├── RimeFramework
├── Core
│ ├── Pools
│ │ ├── IRimePool
│ │ │ └── IPool.cs
│ │ └── Pools.cs
│ ├── Observers
│ │ ├── ObsValue.cs
│ │ └── Observers.cs
│ ├── Navigations
│ │ ├── Panels
│ │ │ ├── Panel.cs
│ │ │ └── PanelGroup.cs
│ │ └── Navigations.cs
│ ├── Cycles
│ │ ├── IRimeCycle
│ │ │ └── ICycles.cs
│ │ └── Cycles.cs
│ ├── RimeManager.cs
│ ├── Consoles
│ │ └── Consoles.cs
│ ├── States
│ │ ├── State
│ │ │ └── State.cs
│ │ └── States.cs
│ ├── Animators
│ │ └── Animators.cs
│ ├── Scenes
│ │ └── Scenes.cs
│ ├── Audios
│ │ └── Audios.cs
│ └── Controls
│ │ └── Controls.cs
├── Utility
│ ├── ObjectUtility.cs
│ ├── NumberUtility.cs
│ ├── StringUtility.cs
│ ├── ColorUtility.cs
│ └── VectorUtility.cs
├── Tool
│ └── Singleton.cs
└── #Generate
│ └── Input
│ ├── InputSettings.inputactions
│ └── InputSettings.cs
├── LICENSE
└── README.md
/RimeFramework/Core/Pools/IRimePool/IPool.cs:
--------------------------------------------------------------------------------
1 | namespace RimeFramework.Core
2 | {
3 | ///
4 | /// Resource接口
5 | ///
6 | /// Author: AstoraGray
7 | interface IPool
8 | {
9 |
10 | }
11 | }
--------------------------------------------------------------------------------
/RimeFramework/Utility/ObjectUtility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RimeFramework.Utility
4 | {
5 | public static class ObjectUtility
6 | {
7 | public static string GetKey(this Object obj)
8 | {
9 | return $"{obj.GetType().Name}-{obj.GetHashCode()}";
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/RimeFramework/Utility/NumberUtility.cs:
--------------------------------------------------------------------------------
1 | namespace RimeFramework.Utility
2 | {
3 | public static class NumberUtility
4 | {
5 | public static int GetSign(this float y)
6 | {
7 | if (y > 0)
8 | {
9 | return 1;
10 | }
11 | if (y < 0)
12 | {
13 | return -1;
14 | }
15 | return 0;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/RimeFramework/Utility/StringUtility.cs:
--------------------------------------------------------------------------------
1 | namespace RimeFramework.Utility
2 | {
3 | public static class StringUtility
4 | {
5 | public static string Extract(this string str,string strExt)
6 | {
7 | int index = str.IndexOf(strExt);
8 |
9 | if (index >= 0)
10 | {
11 | return str.Substring(index + strExt.Length);
12 | }
13 | else
14 | {
15 | return "未找到指定标记";
16 | }
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/RimeFramework/Utility/ColorUtility.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace RimeFramework.Utility
4 | {
5 | public static class ColorUtility
6 | {
7 | public static string ToHex(this Color color)
8 | {
9 |
10 | int r = Mathf.RoundToInt(color.r * 255);
11 | int g = Mathf.RoundToInt(color.g * 255);
12 | int b = Mathf.RoundToInt(color.b * 255);
13 | int a = Mathf.RoundToInt(color.a * 255);
14 |
15 | return $"#{r:X2}{g:X2}{b:X2}{a:X2}";
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Observers/ObsValue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RimeFramework.Core
4 | {
5 | ///
6 | /// 监控值
7 | ///
8 | /// 值类型
9 | /// Author: AstoraGray
10 | public struct ObsValue where T : struct
11 | {
12 | public T Value
13 | {
14 | set
15 | {
16 | bool isChanged = !_value.Equals(value);
17 | _value = value;
18 | if (isChanged)
19 | {
20 | OnValueChanged?.Invoke(value);
21 | }
22 | }
23 | get => _value;
24 | }
25 |
26 | public event Action OnValueChanged;
27 |
28 | private T _value;
29 | }
30 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Navigations/Panels/Panel.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace RimeFramework.Core
4 | {
5 | ///
6 | /// 面板
7 | ///
8 | /// Note: 面板属于IPool也就是池对象,配合Pools使用
9 | /// Author: AstoraGray
10 | public abstract class Panel : MonoBehaviour,IPool
11 | {
12 | public abstract string Group { get; } // 所属导航组
13 | ///
14 | /// 显示面板
15 | ///
16 | public virtual void Show()
17 | {
18 | gameObject.transform.SetAsLastSibling();
19 | gameObject.SetActive(true);
20 | }
21 | ///
22 | /// 隐藏面板
23 | ///
24 | public virtual void Hide()
25 | {
26 | gameObject.SetActive(false);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/RimeFramework/Utility/VectorUtility.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace RimeFramework.Utility
4 | {
5 | public static class VectorUtility
6 | {
7 | public static Vector2 SetX(this Vector2 v,float x)
8 | {
9 | return new Vector2(x,v.y);
10 | }
11 |
12 | public static Vector2 SetY(this Vector2 v,float y)
13 | {
14 | return new Vector2(v.x,y);
15 | }
16 |
17 | public static Vector3 SetX(this Vector3 v,float x)
18 | {
19 | return new Vector3(x,v.y,v.z);
20 | }
21 |
22 | public static Vector3 SetY(this Vector3 v,float y)
23 | {
24 | return new Vector3(v.x,y,v.z);
25 | }
26 |
27 | public static Vector3 SetZ(this Vector3 v,float z)
28 | {
29 | return new Vector3(v.x,v.y,z);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 AstoraGray
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/RimeFramework/Tool/Singleton.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace RimeFramework.Tool
4 | {
5 | ///
6 | /// 单例类
7 | ///
8 | /// 类型
9 | /// Author: AstoraGray
10 | public abstract class Singleton : MonoBehaviour where T : Singleton
11 | {
12 | private static T _instance;
13 |
14 | protected virtual void Awake()
15 | {
16 | if (_instance != null && this != null)
17 | {
18 | Destroy(this);
19 | return;
20 | }
21 |
22 | _instance = this as T;
23 | DontDestroyOnLoad(_instance);
24 | }
25 |
26 | public static T Instance
27 | {
28 | get
29 | {
30 | if (_instance == null)
31 | {
32 | _instance = FindObjectOfType();
33 | if (_instance == null)
34 | {
35 | _instance = new GameObject(typeof(T).Name).AddComponent();
36 | }
37 | }
38 | return _instance;
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Cycles/IRimeCycle/ICycles.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace RimeFramework.Core
4 | {
5 | ///
6 | /// 绑定接口
7 | ///
8 | /// Author: AstoraGray
9 | public interface IBind
10 | {
11 |
12 | }
13 | ///
14 | /// Unity · Awake
15 | ///
16 | public interface IAwake : IBind
17 | {
18 | public void Awake();
19 | }
20 | ///
21 | /// Unity · OnEnable
22 | ///
23 | public interface IOnEnable : IBind
24 | {
25 | public void OnEnable(GameObject obj);
26 | }
27 | ///
28 | /// Unity · Start
29 | ///
30 | public interface IStart : IBind
31 | {
32 | public void Start();
33 | }
34 | ///
35 | /// Unity · Update
36 | ///
37 | public interface IUpdate : IBind
38 | {
39 | public void Update();
40 | }
41 | ///
42 | /// Unity · FixedUpdate
43 | ///
44 | public interface IFixedUpdate : IBind
45 | {
46 | public void FixedUpdate();
47 | }
48 | ///
49 | /// Unity · LateUpdate
50 | ///
51 | public interface ILateUpdate : IBind
52 | {
53 | public void LateUpdate();
54 | }
55 | ///
56 | /// Unity · OnDisable
57 | ///
58 | public interface IOnDisable : IBind
59 | {
60 | public void OnDisable();
61 | }
62 | ///
63 | /// Unity · OnDestroy
64 | ///
65 | public interface IOnDestroy : IBind
66 | {
67 | public void OnDestroy();
68 | }
69 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/RimeManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using RimeFramework.Tool;
3 |
4 | namespace RimeFramework.Core
5 | {
6 | ///
7 | /// 最上层,游戏管理器
8 | ///
9 | /// Author: AstoraGray
10 | public class RimeManager : Singleton
11 | {
12 | public bool consoles = true;
13 | public bool controls = true;
14 | public bool states = true;
15 | public bool cycles = true;
16 | public bool pools = true;
17 | public bool navigations = true;
18 | public bool scenes = true;
19 | public bool animators = true;
20 | public bool audios = true;
21 | public bool observers = true;
22 |
23 | protected override void Awake()
24 | {
25 | base.Awake();
26 | Init();
27 | }
28 |
29 | private void Init()
30 | {
31 | Consoles.Print(nameof(RimeManager),$"{Environment.UserName}, 欢迎回来!");
32 | if(consoles) Consoles.Instance.transform.SetParent(transform);
33 | if(controls) Controls.Instance.transform.SetParent(transform);
34 | if(states) States.Instance.transform.SetParent(transform);
35 | if(cycles) Cycles.Instance.transform.SetParent(transform);
36 | if(pools) Pools.Instance.transform.SetParent(transform);
37 | if(navigations) Navigations.Instance.transform.SetParent(transform);
38 | if(scenes) Scenes.Instance.transform.SetParent(transform);
39 | if(animators) Animators.Instance.transform.SetParent(transform);
40 | if(audios) Audios.Instance.transform.SetParent(transform);
41 | if(observers) Observers.Instance.transform.SetParent(transform);
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Consoles/Consoles.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using RimeFramework.Tool;
5 | using RimeFramework.Utility;
6 | using UnityEngine;
7 | using Object = System.Object;
8 |
9 | namespace RimeFramework.Core
10 | {
11 | ///
12 | /// 霜 · 控制台 💻
13 | ///
14 | /// Note: 类打印传Type,实例传Object,目前可以配置特定的颜色
15 | /// 打印类
16 | /// 打印实例
17 | /// Author: AstoraGray
18 | public class Consoles : Singleton
19 | {
20 | private static readonly Dictionary _dicMapping = new()
21 | {
22 | { nameof(RimeManager), Color.cyan },
23 | { nameof(States), Color.cyan },
24 | { nameof(Controls), Color.cyan },
25 | { nameof(Cycles), Color.cyan },
26 | { nameof(Pools), Color.cyan },
27 | { nameof(Navigations),Color.cyan},
28 | { nameof(Scenes), Color.cyan },
29 | { nameof(Animators),Color.cyan},
30 | { nameof(Observers),Color.cyan}
31 | };
32 |
33 | public static void Print(string name,string content)
34 | {
35 | if (_dicMapping.ContainsKey(name))
36 | {
37 | name = $"{name}";
38 | }
39 | Debug.Log($"{name}: {content}");
40 | }
41 |
42 | public static void Print(Object obj, string content)
43 | {
44 | string objName;
45 | MonoBehaviour own = obj as MonoBehaviour;
46 | if (own != null)
47 | {
48 | objName = own.name;
49 | }
50 | else
51 | {
52 | objName = obj.GetType().Name;
53 | }
54 | Debug.Log($"{objName}: {content}");
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/States/State/State.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace RimeFramework.Core
5 | {
6 | ///
7 | /// 霜 · 状态类
8 | /// WakeUp(): 请将初始化状态要做的事写入这个方法
9 | /// On(): 将进入状态,或者说激活状态要做的事写入这个方法
10 | /// Off(): 将离开状态,或者说取消激活状态要做的事写入这个方法
11 | /// 生命周期:WakeUp->On->Update->Off
12 | /// 建议使用直接访问的方式监听连续输入,eg: InputDir
13 | /// 建议使用Action来监听离散输入,eg: Jump
14 | ///
15 | public abstract class State : MonoBehaviour
16 | {
17 | public MonoBehaviour own;
18 |
19 | ///
20 | /// 首次唤醒,代替Awake
21 | ///
22 | public virtual void WakeUp(){}
23 |
24 | ///
25 | /// 进入此状态,代替OnEnable
26 | ///
27 | public virtual void On(){}
28 |
29 | ///
30 | /// 离开此状态,代替OnDisAble
31 | ///
32 | public virtual void Off(){}
33 |
34 | ///
35 | /// 进入状态
36 | ///
37 | /// 是否离开本状态
38 | /// 是否激活目标状态
39 | /// 状态类型
40 | ///
41 | protected virtual T Enter(bool exit = true,bool enabled = true) where T : State
42 | {
43 | if (exit)
44 | {
45 | Exit();
46 | }
47 | return States.Register(own, enabled);
48 | }
49 | ///
50 | /// 离开状态
51 | ///
52 | protected virtual void Exit()
53 | {
54 | enabled = false;
55 | }
56 | ///
57 | /// 隐藏Awake
58 | ///
59 | private void Awake(){}
60 |
61 | ///
62 | /// 隐藏Start
63 | ///
64 | private void Start(){}
65 |
66 | ///
67 | /// 隐藏OnEnable
68 | ///
69 | private void OnEnable() { }
70 |
71 | ///
72 | /// 取消激活
73 | ///
74 | private void OnDisable()
75 | {
76 | Off();
77 | }
78 | ///
79 | /// 销毁时取消注册
80 | ///
81 | protected virtual void OnDestroy()
82 | {
83 | States.UnRegister(this);
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Navigations/Panels/PanelGroup.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace RimeFramework.Core
5 | {
6 | ///
7 | /// 导航组
8 | ///
9 | public class PanelGroup
10 | {
11 | public string Name { get; private set; } // 导航组名
12 |
13 | private readonly List _panels = new (); // 面板列表
14 | ///
15 | /// 初始化导航组
16 | ///
17 | /// 组名
18 | public PanelGroup(string name) => Name = name;
19 | ///
20 | /// 打开当前面板
21 | ///
22 | ///
23 | public Panel Open()
24 | {
25 | return Open(_panels.LastOrDefault());
26 | }
27 | ///
28 | /// 打开面板
29 | ///
30 | /// 面板实例
31 | ///
32 | public Panel Open(Panel panel)
33 | {
34 | if (panel == _panels.LastOrDefault())
35 | {
36 | panel?.Show();
37 | return panel;
38 | }
39 | _panels.LastOrDefault()?.Hide();
40 |
41 | _panels.Remove(panel);
42 | _panels.Add(panel);
43 |
44 | panel.Show();
45 |
46 | return panel;
47 | }
48 | ///
49 | /// 返回上一级
50 | ///
51 | ///
52 | public bool Back()
53 | {
54 | Panel panel = _panels.LastOrDefault();
55 | panel?.Hide();
56 | _panels.Remove(panel);
57 | if (_panels.Count == 0)
58 | {
59 | return false;
60 | }
61 | _panels.LastOrDefault()?.Show();
62 | return true;
63 | }
64 | ///
65 | /// 关闭当前面板
66 | ///
67 | public void Close()
68 | {
69 | _panels.LastOrDefault()?.Hide();
70 | }
71 | ///
72 | /// 清理面板列表(不是销毁)
73 | ///
74 | public void Clear()
75 | {
76 | _panels.Clear();
77 | }
78 | ///
79 | /// 打印面板Debug信息
80 | ///
81 | ///
82 | public string DebugPanels()
83 | {
84 | string log = "";
85 | for (var i = 0; i < _panels.Count; i++)
86 | {
87 | log += _panels[i].GetType().Name;
88 | if (i < _panels.Count - 1)
89 | {
90 | log += "-->";
91 | }
92 | }
93 |
94 | return log;
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/States/States.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using RimeFramework.Tool;
4 | using UnityEngine;
5 |
6 | namespace RimeFramework.Core
7 | {
8 | ///
9 | /// 霜 · 状态机 🗡️
10 | /// Note: 为什么使用静态方法,但又是单例?
11 | /// 这样可以在融入Unity生命周期的同时,保持一些配置不受生命周期的影响,比如后续可以给States设置一些Awake()初始化方法
12 | /// 注册状态
13 | ///
14 | /// Author: AstoraGray
15 | public class States : Singleton
16 | {
17 | private static Dictionary> _dicStates = new (); // 字典
18 |
19 | private const string STATES_NAME = "States"; // 状态节点名字
20 |
21 | public Dictionary this[MonoBehaviour monoBehaviour]
22 | {
23 | get
24 | {
25 | if (_dicStates.TryGetValue(monoBehaviour, out var states))
26 | {
27 | return states;
28 | }
29 | Consoles.Print(nameof(States),"状态不存在");
30 | return null; // 或者抛出异常,根据需求
31 | }
32 | }
33 |
34 | ///
35 | /// 注册状态行为
36 | ///
37 | /// 持有者
38 | /// 激活状态
39 | /// 类型
40 | ///
41 | public static T Register(MonoBehaviour own,bool enabled = true) where T : State
42 | {
43 | Transform actions = null;
44 | // 查找是否存在key
45 | if (!_dicStates.ContainsKey(own))
46 | {
47 | // 查找是否已有节点
48 | if (!own.transform.Find(STATES_NAME))
49 | {
50 | actions = new GameObject(STATES_NAME).transform;
51 | actions.SetParent(own.transform);
52 | }
53 | _dicStates.Add(own,new Dictionary());
54 | }
55 | State newState = null;
56 | bool isWake = false;
57 | if (!_dicStates[own].ContainsKey(typeof(T)))
58 | {
59 | actions ??= own.transform.Find(STATES_NAME);
60 | newState = actions.GetComponent() ?? actions.gameObject.AddComponent();
61 | _dicStates[own].Add(typeof(T),newState);
62 | isWake = true;
63 | }
64 | newState ??= _dicStates[own][typeof(T)];
65 | newState.enabled = enabled;
66 | newState.own = own;
67 | if (isWake)
68 | {
69 | newState.WakeUp();
70 | }
71 | newState.On();
72 | return newState as T;
73 | }
74 |
75 | ///
76 | /// 注销状态行为
77 | ///
78 | /// 状态行为
79 | public static void UnRegister(State state)
80 | {
81 | if (state == null)
82 | {
83 | Consoles.Print(nameof(States),"注销目标不存在");
84 | return;
85 | }
86 | _dicStates[state.own].Remove(state.GetType());
87 | if (_dicStates[state.own].Count <= 0)
88 | {
89 | _dicStates.Remove(state.own);
90 | }
91 | Destroy(state);
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/RimeFramework/Core/Observers/Observers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using RimeFramework.Tool;
4 |
5 | namespace RimeFramework.Core
6 | {
7 | ///
8 | /// 霜 · 观察者 📷
9 | ///
10 | /// Note: 支持有参无参事件的管理
11 | /// Author: AstoraGray
12 | public class Observers : Singleton
13 | {
14 | private static readonly Dictionary> _dicEventObserversParams = new(); // 事件观察者
15 |
16 | private static readonly Dictionary _dicEventObservers = new(); // 事件观察者(无参)
17 |
18 | ///
19 | /// 注册事件
20 | ///
21 | /// 事件名
22 | /// 事件
23 | public static void Register(string name,Action