From 27df4282109a26a21aa042793c3136fbb5b81a98 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Tue, 16 May 2023 08:50:55 +0800 Subject: *misc --- WorldlineKeepers/Assets/Scripts/Application.meta | 8 + .../Assets/Scripts/Application/ApplicationMain.cs | 62 +++++ .../Scripts/Application/ApplicationMain.cs.meta | 11 + .../Assets/Scripts/Application/ISubsystem.cs | 23 ++ .../Assets/Scripts/Application/ISubsystem.cs.meta | 11 + .../Assets/Scripts/Battle/SceneManager.cs | 27 ++- .../Assets/Scripts/Common/Statemachine.cs | 254 --------------------- .../Assets/Scripts/Common/Statemachine.cs.meta | 11 - WorldlineKeepers/Assets/Scripts/Managers/Main.cs | 20 +- WorldlineKeepers/Assets/Scripts/Stages.meta | 8 + .../Assets/Scripts/Stages/GameStageBase.cs | 28 +++ .../Assets/Scripts/Stages/GameStageBase.cs.meta | 11 + .../Assets/Scripts/Stages/GameStageManager.cs | 59 +++++ .../Assets/Scripts/Stages/GameStageManager.cs.meta | 11 + .../Assets/Scripts/Stages/GameStage_Battle.cs | 15 ++ .../Assets/Scripts/Stages/GameStage_Battle.cs.meta | 11 + .../Assets/Scripts/Stages/GameStage_Dojo.cs | 15 ++ .../Assets/Scripts/Stages/GameStage_Dojo.cs.meta | 11 + .../Assets/Scripts/Stages/GameStage_Launch.cs | 15 ++ .../Assets/Scripts/Stages/GameStage_Launch.cs.meta | 11 + .../Assets/Scripts/Stages/GameStage_Main.cs | 15 ++ .../Assets/Scripts/Stages/GameStage_Main.cs.meta | 11 + .../Assets/Scripts/Stages/GameStages.cs | 19 ++ .../Assets/Scripts/Stages/GameStages.cs.meta | 11 + .../Assets/Scripts/Tools/Statemachine.meta | 8 + .../Tools/Statemachine/AsyncStatemachine.cs | 254 +++++++++++++++++++++ .../Tools/Statemachine/AsyncStatemachine.cs.meta | 11 + .../Scripts/Tools/Statemachine/Statemachine.cs | 249 ++++++++++++++++++++ .../Tools/Statemachine/Statemachine.cs.meta | 11 + .../Assets/Scripts/Tools/UniqueStringMap.cs | 51 +++++ .../Assets/Scripts/Tools/UniqueStringMap.cs.meta | 11 + .../Assets/Scripts/Utils/StringUtils.cs | 30 +++ .../Assets/Scripts/Utils/StringUtils.cs.meta | 11 + 33 files changed, 1041 insertions(+), 273 deletions(-) create mode 100644 WorldlineKeepers/Assets/Scripts/Application.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs.meta delete mode 100644 WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs delete mode 100644 WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Statemachine.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs.meta (limited to 'WorldlineKeepers/Assets/Scripts') diff --git a/WorldlineKeepers/Assets/Scripts/Application.meta b/WorldlineKeepers/Assets/Scripts/Application.meta new file mode 100644 index 0000000..3d93c15 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Application.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 880675e8c90730d4c94482d83cfd6df0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs b/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs new file mode 100644 index 0000000..a4698f4 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + /// + /// 主循环,所有子系统的更新理论上都走这里的循环 + /// + public class ApplicationMain : Singleton + { + public delegate void ApplicationCallback(); + + #region 事件 + public event ApplicationCallback onAwakeHandler; + public event ApplicationCallback onStartHandler; + public event ApplicationCallback onUpdateHandler; + public event ApplicationCallback onFixedUpdateHandler; + public event ApplicationCallback onApplicationQuitHandler; + public event ApplicationCallback onDestroyHandler; + public event ApplicationCallback onApplicationPauseHandler; + #endregion + + public void OnAwake() + { + onAwakeHandler?.Invoke(); + } + + public void OnStart() + { + onStartHandler?.Invoke(); + } + + public void OnUpdate() + { + onUpdateHandler?.Invoke(); + } + + public void OnFixedUpdate() + { + onFixedUpdateHandler?.Invoke(); + } + + public void OnDestroy() + { + onDestroyHandler?.Invoke(); + } + + public void OnApplicationQuit() + { + onApplicationQuitHandler?.Invoke(); + } + + public void OnApplicationPause() + { + onApplicationPauseHandler?.Invoke(); + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs.meta b/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs.meta new file mode 100644 index 0000000..f201dbf --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 95fdd2b99bd27a94eb3783f14ea43c22 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs b/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs new file mode 100644 index 0000000..5bbc60d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs @@ -0,0 +1,23 @@ +using Mono.CompilerServices.SymbolWriter; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace WK +{ + + public interface ISubsystem + { + + void OnAwake(); + void OnStart(); + void OnUpdate(); + void OnFixedUpdate(); + void OnDestroy(); + void OnApplicationQuit(); + void OnApplicationPause(); + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs.meta b/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs.meta new file mode 100644 index 0000000..acad5f8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 471d0112ba2db594686ad821387d11e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs index 9ed2fc9..ff7ac65 100644 --- a/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs @@ -2,10 +2,29 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class SceneManager : Singleton +namespace WK { - // 鍦烘櫙鍐呮墍鏈夊璞$敤杩欎釜缁撴瀯缁存姢 - private GridMap m_GridMap; + /// + /// 鍛藉悕鍜孶nityEngine.SceneManagement.SceneManager鍖哄垎 + /// + public class GameSceneManager : Singleton + { + private AsyncOperation m_AsyncOpt = null; + public AsyncOperation AsyncOpt + { + get + { + return m_AsyncOpt; + } + } -} \ No newline at end of file + public void LoadScene(string sceneName, UnityEngine.SceneManagement.LoadSceneMode loadMode) + { + m_AsyncOpt = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, loadMode); + } + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs b/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs deleted file mode 100644 index ffa33a2..0000000 --- a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using MEC; - -namespace WK -{ - - /// - /// 公共状态机 - /// - public class StateMachine - { - - public delegate void LoadStateComplete(); - - public abstract class State - { - public StateMachine owner; - public int stateID; - public abstract IEnumerator OnStart(); - public abstract IEnumerator OnEnd(); - public abstract void OnUpdate(float deltaTime); - } - - public const int NULL_STATE_ID = -1; - public const float COROUINT_DELTIME = 0.01f; - - private Dictionary allState = new Dictionary(); - private int curStateID = NULL_STATE_ID; - private int stateIDDistributor = 0; - // 在状态切换完成前为false,不能进行update - private bool isUpdateActive = false; - - /// - /// 添加状态,并返回在状态机中的ID - /// - /// - /// - public int RegisterState(State newState) - { - if (newState == null) - return NULL_STATE_ID; - if (stateIDDistributor + 1 >= int.MaxValue) - { - Debug.LogError("状态机添加状态失败,此状态机中添加的状态过多"); - return NULL_STATE_ID; - } - ++stateIDDistributor; - if (!allState.ContainsKey(stateIDDistributor)) - { - newState.owner = this; - newState.stateID = stateIDDistributor; - allState.Add(stateIDDistributor, newState); - return stateIDDistributor; - } - Debug.LogError("状态机添加状态失败,状态已经存在"); - return NULL_STATE_ID; - } - - public bool RemoveState(State state) - { - if (state != null) - { - return RemoveState(state.stateID); - } - Debug.LogError("状态机删除状态失败,状态为空"); - return false; - } - - public bool RemoveState(int stateID) - { - if (allState.ContainsKey(stateID)) - { - allState.Remove(stateID); - return true; - } - Debug.LogError("状态机删除状态失败,该状态不存在,stateID = " + stateID); - return false; - } - - /// - /// 开始运行状态机 - /// - /// - /// - public bool Start(int stateID) - { - if (!HasBegin()) - { - ForceGotoState(stateID); - return true; - } - return false; - } - - /// - /// 结束状态机 - /// - /// - public bool Stop() - { - if (HasBegin()) - { - ForceGotoState(NULL_STATE_ID); - return true; - } - return false; - } - - /// - /// 更新状态机 - /// - /// - public void Update(float deltaTime) - { - if (HasBegin()) - { - UpdateState(curStateID, deltaTime); - } - } - - public bool GotoState(int stateID, bool skipStartFunc = false, bool bForce = false, LoadStateComplete callback = null) - { - if (HasBegin()) - return ForceGotoState(stateID, skipStartFunc, bForce, callback); - return false; - } - - public bool ForceGotoState(int nextStateID, bool skipStartFunc = false, bool bForce = false, LoadStateComplete callback = null) - { - if (curStateID != nextStateID || bForce) - { - Timing.Instance.RunCoroutineOnInstance(AyncForceGotoState(nextStateID, skipStartFunc, callback)); - return true; - } - if (callback != null) - callback(); - return false; - } - - /// - /// 异步的切换到某个状态 - /// - /// - private IEnumerator AyncForceGotoState(int nextStateID, bool skipStartFunc = false, LoadStateComplete callback = null) - { - isUpdateActive = false; - CoroutineHandle handle = Timing.RunCoroutine(EndState(curStateID)); - while (handle.IsValid) - { - yield return Timing.WaitForSeconds(COROUINT_DELTIME); - } - curStateID = nextStateID; - if (!skipStartFunc) - { - CoroutineHandle handle2 = Timing.RunCoroutine(StartState(curStateID)); - while (handle2.IsValid) - { - yield return Timing.WaitForSeconds(COROUINT_DELTIME); - } - } - if (callback != null) - callback(); - isUpdateActive = true; - } - - public int GetCurStateID() - { - return curStateID; - } - - public bool HasBegin() - { - if (curStateID != NULL_STATE_ID && allState.ContainsKey(curStateID)) - return true; - return false; - } - - public bool IsInState(int stateID) - { - if (HasBegin()) - { - return curStateID == stateID; - } - return false; - } - - public State GetState(int stateID) - { - if (allState.ContainsKey(stateID)) - { - return allState[stateID]; - } - return null; - } - - public void Clean() - { - allState.Clear(); - curStateID = NULL_STATE_ID; - stateIDDistributor = 0; - } - - public void ResetCurState() - { - curStateID = NULL_STATE_ID; - } - - private IEnumerator StartState(int stateID) - { - if (HasBegin()) - { - State state = GetState(stateID); - if (state != null) - { - CoroutineHandle handle = Timing.RunCoroutine(state.OnStart()); - while (handle.IsValid) - { - yield return Timing.WaitForSeconds(COROUINT_DELTIME); - } - } - } - } - - private IEnumerator EndState(int stateID) - { - if (HasBegin()) - { - State state = GetState(stateID); - if (state != null) - { - CoroutineHandle handle = Timing.RunCoroutine(state.OnEnd()); - while (handle.IsValid) - { - yield return Timing.WaitForSeconds(COROUINT_DELTIME); - } - } - } - } - - private void UpdateState(int stateID, float deltaTime) - { - if (HasBegin()) - { - State state = GetState(stateID); - if (state != null) - state.OnUpdate(deltaTime); - } - } - - } - -} diff --git a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta b/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta deleted file mode 100644 index e2b8d49..0000000 --- a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c43b283f086a24140b0e6e6e0e9efbef -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Managers/Main.cs b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs index 976779d..2d50dda 100644 --- a/WorldlineKeepers/Assets/Scripts/Managers/Main.cs +++ b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs @@ -1,34 +1,46 @@ using System.Collections; using System.Collections.Generic; +using Unity.VisualScripting; using UnityEngine; using WK.Data; namespace WK { + /// + /// 托管ApplicationMain的Monobehaviour对象 + /// 这么作的目的是为了减少monobehaviour的调用,子系统同一走application main + /// public class Main : SingletonMB
{ protected override void Awake() { base.Awake(); - DontDestroyOnLoad(this.gameObject); + DontDestroyOnLoad(this.gameObject);// + + ApplicationMain.Instance.OnAwake(); } private void Start() { DataManager.Instance.Load(); - Debug.Log(DataManager.Instance.GetCharacterStats("health")); + ApplicationMain.Instance.OnStart(); } private void Update() { - + ApplicationMain.Instance.OnUpdate(); } private void FixedUpdate() { - + ApplicationMain.Instance.OnFixedUpdate(); + } + + private void OnDestroy() + { + ApplicationMain.Instance.OnDestroy(); } } diff --git a/WorldlineKeepers/Assets/Scripts/Stages.meta b/WorldlineKeepers/Assets/Scripts/Stages.meta new file mode 100644 index 0000000..c9ff25f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dc0534a6527c55d4cb2b2e876775be80 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs new file mode 100644 index 0000000..73ded6e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs @@ -0,0 +1,28 @@ +using Microsoft.Unity.VisualStudio.Editor; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace WK +{ + + public class GameStageBase : AsyncStatemachine.State + { + + public override IEnumerator OnStart() + { + yield break; + } + + public override IEnumerator OnEnd() + { + yield break; + } + + public override void OnUpdate(float deltaTime) + { + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs.meta new file mode 100644 index 0000000..15a5c56 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 432eadb305e58da4897534478987c4da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs new file mode 100644 index 0000000..a92a3d8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs @@ -0,0 +1,59 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; +using WK.Tools; + +namespace WK +{ + + public sealed class GameStageManager : Singleton, ISubsystem + { + /// + /// GameStage的状态机 + /// + private AsyncStatemachine m_Statemachine; + private int[] stages = new int[(int)EGameStage.Num]; + private EGameStage prevStage = EGameStage.Launch; + private EGameStage curStage = EGameStage.Launch; + + public void OnAwake() + { + SetupGameStages(); + + } + + private void SetupGameStages() + { + m_Statemachine = new AsyncStatemachine(); + + + } + + public void OnStart() + { + } + + public void OnUpdate() + { + } + + public void OnFixedUpdate() + { + } + + public void OnDestroy() + { + } + + public void OnApplicationPause() + { + } + + public void OnApplicationQuit() + { + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs.meta new file mode 100644 index 0000000..0ce1cb9 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4b7f17be1928ff849ba0d7d28ca8e87d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs new file mode 100644 index 0000000..3701299 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class GameStage_Battle : GameStageBase + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs.meta new file mode 100644 index 0000000..9104992 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad0f7465a835f2942ab4a37df3a827b4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs new file mode 100644 index 0000000..fbb92a4 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class GameStage_Dojo : GameStageBase + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs.meta new file mode 100644 index 0000000..d4e25cf --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 30c90d11e59fd3f42b4568e275bb3fbe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs new file mode 100644 index 0000000..e283008 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class GameStage_Launch : GameStageBase + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs.meta new file mode 100644 index 0000000..aa30aaa --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 140927b1845ec1846814b71c4e114ad8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs new file mode 100644 index 0000000..01488d9 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class GameStage_Lobby + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs.meta new file mode 100644 index 0000000..5add0f2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 102ce3dadc4654b44838f17cf9415384 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs new file mode 100644 index 0000000..28ba28f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public enum EGameStage + { + Launch = 0, // splash screen + //Login = 1, // + Main = 2, // 主界面 + Battle = 3, // 战斗场景 + Dojo = 4, // 训练道场 + + Num + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs.meta b/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs.meta new file mode 100644 index 0000000..ea2c442 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a4b80a072bd95b643a7c2295281f3174 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Statemachine.meta b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine.meta new file mode 100644 index 0000000..77a2746 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0a7c937b01d531843b68e7ecf1ac0ca9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs new file mode 100644 index 0000000..605f737 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs @@ -0,0 +1,254 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using MEC; + +namespace WK +{ + + /// + /// 公共状态机 + /// + public class AsyncStatemachine + { + + public delegate void LoadStateComplete(); + + public abstract class State + { + public AsyncStatemachine owner; + public int stateID; // stateID可以是string.GetHashCode() 以提供扩展性 + public abstract IEnumerator OnStart(); + public abstract IEnumerator OnEnd(); + public abstract void OnUpdate(float deltaTime); + } + + public const int NULL_STATE_ID = -1; + public const float COROUINT_DELTIME = 0.01f; + + private Dictionary allState = new Dictionary(); + private int curStateID = NULL_STATE_ID; + private int stateIDDistributor = 0; + // 在状态切换完成前为false,不能进行update + private bool isUpdateActive = false; + + /// + /// 添加状态,并返回在状态机中的ID + /// + /// + /// + public int RegisterState(State newState) + { + if (newState == null) + return NULL_STATE_ID; + if (stateIDDistributor + 1 >= int.MaxValue) + { + Debug.LogError("状态机添加状态失败,此状态机中添加的状态过多"); + return NULL_STATE_ID; + } + ++stateIDDistributor; + if (!allState.ContainsKey(stateIDDistributor)) + { + newState.owner = this; + newState.stateID = stateIDDistributor; + allState.Add(stateIDDistributor, newState); + return stateIDDistributor; + } + Debug.LogError("状态机添加状态失败,状态已经存在"); + return NULL_STATE_ID; + } + + public bool RemoveState(State state) + { + if (state != null) + { + return RemoveState(state.stateID); + } + Debug.LogError("状态机删除状态失败,状态为空"); + return false; + } + + public bool RemoveState(int stateID) + { + if (allState.ContainsKey(stateID)) + { + allState.Remove(stateID); + return true; + } + Debug.LogError("状态机删除状态失败,该状态不存在,stateID = " + stateID); + return false; + } + + /// + /// 开始运行状态机 + /// + /// + /// + public bool Start(int stateID) + { + if (!HasBegin()) + { + ForceGotoState(stateID); + return true; + } + return false; + } + + /// + /// 结束状态机 + /// + /// + public bool Stop() + { + if (HasBegin()) + { + ForceGotoState(NULL_STATE_ID); + return true; + } + return false; + } + + /// + /// 更新状态机 + /// + /// + public void Update(float deltaTime) + { + if (HasBegin()) + { + UpdateState(curStateID, deltaTime); + } + } + + public bool GotoState(int stateID, bool skipStartFunc = false, bool bForce = false, LoadStateComplete callback = null) + { + if (HasBegin()) + return ForceGotoState(stateID, skipStartFunc, bForce, callback); + return false; + } + + public bool ForceGotoState(int nextStateID, bool skipStartFunc = false, bool bForce = false, LoadStateComplete callback = null) + { + if (curStateID != nextStateID || bForce) + { + Timing.Instance.RunCoroutineOnInstance(AyncForceGotoState(nextStateID, skipStartFunc, callback)); + return true; + } + if (callback != null) + callback(); + return false; + } + + /// + /// 异步的切换到某个状态 + /// + /// + private IEnumerator AyncForceGotoState(int nextStateID, bool skipStartFunc = false, LoadStateComplete callback = null) + { + isUpdateActive = false; + CoroutineHandle handle = Timing.RunCoroutine(EndState(curStateID)); + while (handle.IsValid) + { + yield return Timing.WaitForSeconds(COROUINT_DELTIME); + } + curStateID = nextStateID; + if (!skipStartFunc) + { + CoroutineHandle handle2 = Timing.RunCoroutine(StartState(curStateID)); + while (handle2.IsValid) + { + yield return Timing.WaitForSeconds(COROUINT_DELTIME); + } + } + if (callback != null) + callback(); + isUpdateActive = true; + } + + public int GetCurStateID() + { + return curStateID; + } + + public bool HasBegin() + { + if (curStateID != NULL_STATE_ID && allState.ContainsKey(curStateID)) + return true; + return false; + } + + public bool IsInState(int stateID) + { + if (HasBegin()) + { + return curStateID == stateID; + } + return false; + } + + public State GetState(int stateID) + { + if (allState.ContainsKey(stateID)) + { + return allState[stateID]; + } + return null; + } + + public void Clean() + { + allState.Clear(); + curStateID = NULL_STATE_ID; + stateIDDistributor = 0; + } + + public void ResetCurState() + { + curStateID = NULL_STATE_ID; + } + + private IEnumerator StartState(int stateID) + { + if (HasBegin()) + { + State state = GetState(stateID); + if (state != null) + { + CoroutineHandle handle = Timing.RunCoroutine(state.OnStart()); + while (handle.IsValid) + { + yield return Timing.WaitForSeconds(COROUINT_DELTIME); + } + } + } + } + + private IEnumerator EndState(int stateID) + { + if (HasBegin()) + { + State state = GetState(stateID); + if (state != null) + { + CoroutineHandle handle = Timing.RunCoroutine(state.OnEnd()); + while (handle.IsValid) + { + yield return Timing.WaitForSeconds(COROUINT_DELTIME); + } + } + } + } + + private void UpdateState(int stateID, float deltaTime) + { + if (HasBegin()) + { + State state = GetState(stateID); + if (state != null) + state.OnUpdate(deltaTime); + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta new file mode 100644 index 0000000..e2b8d49 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c43b283f086a24140b0e6e6e0e9efbef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs new file mode 100644 index 0000000..56dd28b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs @@ -0,0 +1,249 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using Newtonsoft.Json.Utilities; + +namespace WK +{ + + public class BaseStateMachine + { + public delegate void StateEvent(); + public delegate bool StateFinishChecker(); + public class State + { + public BaseStateMachine owner; + public int stateId; + + public virtual void BeginState() + { + //reserve function + } + public virtual void EndState() + { + //reserve function + } + //时间单位是毫秒 + public virtual bool UpdateState(int deltaTimeMS) + { + return true; + } + } + + private Dictionary stateDic = new Dictionary(); + private int currentStateId = -1; + private int stateIdDistributor = 0; + + private int recordLastStateId = -1; + + public int RegisterState(State newState) + { + if (newState != null) + { + if (stateIdDistributor + 1 > int.MaxValue) + { + Debug.LogError("状态机添加状态失败:一个状态机中添加了过多的状态!"); + return -1; + } + + stateIdDistributor++; + if (!stateDic.ContainsKey(stateIdDistributor)) + { + stateDic.Add(stateIdDistributor, newState); + newState.owner = this; + newState.stateId = stateIdDistributor; + return stateIdDistributor; + } + } + Debug.LogError("状态机添加状态失败:无效的新状态或新状态已存在!"); + return -1; + } + + public bool RemoveState(State toBeRemoveState) + { + if (toBeRemoveState != null) + return RemoveState(toBeRemoveState.stateId); + Debug.LogError("状态机删除状态失败:无效的状态!"); + return false; + } + + public bool RemoveState(int stateId) + { + if (stateDic.ContainsKey(stateId)) + { + stateDic.Remove(stateId); + return true; + } + Debug.LogError("状态机删除状态失败:该状态不存在!"); + return false; + } + + public bool Begin(int beginStateId) + { + if (!HasBegin()) + { + ForceGoToState(beginStateId, false); + return true; + } + + return false; + } + + public bool Stop() + { + if (HasBegin()) + { + ForceGoToState(-1); + return true; + } + + return false; + } + + public bool GoToState(int newStateId, bool skipBeginFunc = false, bool forceLoad = false) + { + if (HasBegin()) + { + return ForceGoToState(newStateId, skipBeginFunc, forceLoad); + } + return false; + } + + private bool ForceGoToState(int newStateId) + { + return ForceGoToState(newStateId, false); + } + private bool ForceGoToState(int newStateId, bool skipBeginFunc, bool bForce = false) + { + if (currentStateId != newStateId || bForce) + { + OnStateEnd(currentStateId); + currentStateId = newStateId; + if (!skipBeginFunc) OnStateBegin(currentStateId); + return true; + } + else + { + return false; + } + } + + /// + /// + /// + /// 剔除的state + public void RecordCurrentState(int filterState) + { + if (currentStateId != filterState) + { + recordLastStateId = currentStateId; + } + } + + public void ClearRecordState() + { + recordLastStateId = -1; + } + + public void RevertToRecordState(int fallbackState, bool skipBeginFunc, bool bForce = false) + { + if (recordLastStateId >= 0 && stateDic.ContainsKey(recordLastStateId)) + { + GoToState(recordLastStateId, skipBeginFunc, bForce); + } + else if (fallbackState >= 0 && stateDic.ContainsKey(fallbackState)) + { + GoToState(fallbackState, skipBeginFunc, bForce); + } + } + + + //时间单位是毫秒 + public void OnUpdate(int mSecDeltaTime) + { + if (HasBegin()) + { + UpdateState(currentStateId, mSecDeltaTime); + } + } + + public bool HasBegin() + { + if (currentStateId != -1 && stateDic.ContainsKey(currentStateId)) + return true; + else + return false; + } + + public bool IsInState(int stateId) + { + if (HasBegin()) + { + return currentStateId == stateId; + } + return false; + } + + + public int GetCurrentStateId() + { + return currentStateId; + } + + public State GetState(int stateId) + { + if (stateDic.ContainsKey(stateId)) + { + return stateDic[stateId]; + } + return null; + } + + public void Clean() + { + stateDic.Clear(); + currentStateId = -1; + stateIdDistributor = 0; + recordLastStateId = -1; + } + + /// + /// 重置当前状态(置为-1) + /// + public void ResetCurrentState() + { + currentStateId = -1; + } + + private void OnStateBegin(int stateId) + { + if (HasBegin()) + { + State state = GetState(stateId); + if (state != null) + state.BeginState(); + } + } + + private void OnStateEnd(int stateId) + { + if (HasBegin()) + { + State state = GetState(stateId); + if (state != null) + state.EndState(); + } + } + //时间单位是毫秒 + private void UpdateState(int stateId, int mSecDeltaTime) + { + if (HasBegin()) + { + State state = GetState(stateId); + if (state != null) + state.UpdateState(mSecDeltaTime); + } + } + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs.meta new file mode 100644 index 0000000..1f9dc33 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 740b9ccdbc7196546acfadecbcbd71f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs new file mode 100644 index 0000000..7e54840 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Tools +{ + + public class UniqueStringMap + { + private int m_Index = 1; + + private Dictionary m_StringMap = new Dictionary(); + + public int RegisterString(string str) + { + if(m_StringMap.ContainsKey(str)) + return m_StringMap[str]; + + int index = m_Index++; + m_StringMap.Add(str, index); + + return index; + } + + public int GetStringCode(string str) + { + if (!m_StringMap.ContainsKey(str)) + return 0; + return m_StringMap[str]; + } + + //public int GetOrAddStringCode(string str) + //{ + // if (!m_StringMap.ContainsKey(str)) + // { + // RegisterString(str); + // } + // return m_StringMap[str]; + //} + + public int this[string str] + { + get + { + return GetStringCode(str); + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs.meta new file mode 100644 index 0000000..0e1c43d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f24ea275bd009864e8b1e4c0d64f2316 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs b/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs new file mode 100644 index 0000000..b9ec52e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +namespace WK.Utils +{ + + public class StringUtils + { + + public static byte[] GetHash(string inputString) + { + using (HashAlgorithm algorithm = SHA256.Create()) + return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString)); + } + + public static string GetHashString(string inputString) + { + StringBuilder sb = new StringBuilder(); + foreach (byte b in GetHash(inputString)) + sb.Append(b.ToString("X2")); + + return sb.ToString(); + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs.meta new file mode 100644 index 0000000..555da6c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 917c8c50054333a45b8925c7b33ffdf5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0