summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-05-16 08:50:55 +0800
committerchai <215380520@qq.com>2023-05-16 08:50:55 +0800
commit27df4282109a26a21aa042793c3136fbb5b81a98 (patch)
treefb20d2b3b6270430eaa32de9a0c88aa7ea5d8258 /WorldlineKeepers/Assets/Scripts
parent85629d871b1cbf65e57c8e25b2145c0b77f7e353 (diff)
*misc
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts')
-rw-r--r--WorldlineKeepers/Assets/Scripts/Application.meta8
-rw-r--r--WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs62
-rw-r--r--WorldlineKeepers/Assets/Scripts/Application/ApplicationMain.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs23
-rw-r--r--WorldlineKeepers/Assets/Scripts/Application/ISubsystem.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs27
-rw-r--r--WorldlineKeepers/Assets/Scripts/Managers/Main.cs20
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages.meta8
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs28
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs59
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs15
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Battle.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs15
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Dojo.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs15
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs15
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs19
-rw-r--r--WorldlineKeepers/Assets/Scripts/Stages/GameStages.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/Statemachine.meta8
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs (renamed from WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs)6
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta (renamed from WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta)0
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs249
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/Statemachine/Statemachine.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs51
-rw-r--r--WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs.meta11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs30
-rw-r--r--WorldlineKeepers/Assets/Scripts/Utils/StringUtils.cs.meta11
31 files changed, 779 insertions, 11 deletions
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
+{
+
+ /// <summary>
+ /// 主循环,所有子系统的更新理论上都走这里的循环
+ /// </summary>
+ public class ApplicationMain : Singleton<ApplicationMain>
+ {
+ 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<SceneManager>
+namespace WK
{
- // 鍦烘櫙鍐呮墍鏈夊璞$敤杩欎釜缁撴瀯缁存姢
- private GridMap m_GridMap;
+ /// <summary>
+ /// 鍛藉悕鍜孶nityEngine.SceneManagement.SceneManager鍖哄垎
+ /// </summary>
+ public class GameSceneManager : Singleton<GameSceneManager>
+ {
+ 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/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
{
+ /// <summary>
+ /// 托管ApplicationMain的Monobehaviour对象
+ /// 这么作的目的是为了减少monobehaviour的调用,子系统同一走application main
+ /// </summary>
public class Main : SingletonMB<Main>
{
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<float> OnStart()
+ {
+ yield break;
+ }
+
+ public override IEnumerator<float> 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<GameStageManager>, ISubsystem
+ {
+ /// <summary>
+ /// GameStage的状态机
+ /// </summary>
+ 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/Common/Statemachine.cs b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs
index ffa33a2..605f737 100644
--- a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs
+++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs
@@ -9,15 +9,15 @@ namespace WK
/// <summary>
/// 公共状态机
/// </summary>
- public class StateMachine
+ public class AsyncStatemachine
{
public delegate void LoadStateComplete();
public abstract class State
{
- public StateMachine owner;
- public int stateID;
+ public AsyncStatemachine owner;
+ public int stateID; // stateID可以是string.GetHashCode() 以提供扩展性
public abstract IEnumerator<float> OnStart();
public abstract IEnumerator<float> OnEnd();
public abstract void OnUpdate(float deltaTime);
diff --git a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta
index e2b8d49..e2b8d49 100644
--- a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta
+++ b/WorldlineKeepers/Assets/Scripts/Tools/Statemachine/AsyncStatemachine.cs.meta
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<int/*state id*/, State> stateDic = new Dictionary<int/*state id*/, State>();
+ 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;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="filterState">剔除的state</param>
+ 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;
+ }
+
+ /// <summary>
+ /// 重置当前状态(置为-1)
+ /// </summary>
+ 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<string, int/*ID*/> m_StringMap = new Dictionary<string, int>();
+
+ 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: