From 6fb204d494b897907d655b5752196983a82ceba2 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sat, 13 May 2023 15:20:20 +0800 Subject: *misc --- WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs | 2 +- .../Assets/Scripts/Buffs/BuffBehaviour.cs | 32 +++ .../Assets/Scripts/Buffs/BuffBehaviour.cs.meta | 11 + .../Assets/Scripts/Buffs/BuffEfectorBase.cs | 32 --- .../Assets/Scripts/Buffs/BuffEfectorBase.cs.meta | 11 - .../Assets/Scripts/Common/Statemachine.cs | 254 +++++++++++++++++++++ .../Assets/Scripts/Common/Statemachine.cs.meta | 11 + .../Assets/Scripts/Data/DataManager.cs | 13 ++ WorldlineKeepers/Assets/Scripts/EntityBase.cs | 2 +- WorldlineKeepers/Assets/Scripts/Items/Inventory.cs | 15 ++ .../Assets/Scripts/Items/Inventory.cs.meta | 11 + WorldlineKeepers/Assets/Scripts/Items/Item.cs | 21 ++ WorldlineKeepers/Assets/Scripts/Items/Item.cs.meta | 11 + .../Assets/Scripts/Items/ItemBehaviour.cs | 27 +++ .../Assets/Scripts/Items/ItemBehaviour.cs.meta | 11 + .../Assets/Scripts/Items/ItemDaggerBehaviour.cs | 15 ++ .../Scripts/Items/ItemDaggerBehaviour.cs.meta | 11 + .../Assets/Scripts/Items/ItemHellbellBehaviour.cs | 15 ++ .../Scripts/Items/ItemHellbellBehaviour.cs.meta | 11 + .../Assets/Scripts/Items/ItemMetadata.cs | 23 ++ .../Assets/Scripts/Items/ItemMetadata.cs.meta | 11 + WorldlineKeepers/Assets/Scripts/StaticDefine.cs | 2 + .../Assets/Scripts/Stats/CharacterStatsBase.cs | 28 ++- .../Assets/Scripts/Stats/CharacterStatsMetadata.cs | 2 + WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs | 40 ++++ .../Assets/Scripts/Tests/TestEvent.cs.meta | 11 + WorldlineKeepers/Assets/Scripts/Tools.meta | 8 + .../Assets/Scripts/Tools/GlobalEventManager.cs | 97 ++++++++ .../Scripts/Tools/GlobalEventManager.cs.meta | 11 + .../Assets/Scripts/Tools/NotificationCenter.cs | 167 ++++++++++++++ .../Scripts/Tools/NotificationCenter.cs.meta | 11 + .../Scripts/Unit/Characters/CharacterBehaviour.cs | 32 +++ .../Unit/Characters/CharacterBehaviour.cs.meta | 11 + .../Scripts/Unit/Characters/CharacterController.cs | 32 --- .../Unit/Characters/CharacterController.cs.meta | 11 - .../Scripts/Unit/Characters/CharacterMetadata.cs | 23 ++ .../Unit/Characters/CharacterMetadata.cs.meta | 11 + .../Scripts/Unit/Characters/PlayerController.cs | 6 + .../Unit/Characters/Ronin/RoninBehaviour.cs | 3 +- .../Assets/Scripts/Unit/Enemies/SpiritScript.cs | 4 +- .../Assets/Scripts/Unit/UnitManager.cs | 15 ++ .../Assets/Scripts/Unit/UnitManager.cs.meta | 11 + 42 files changed, 985 insertions(+), 101 deletions(-) create mode 100644 WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs.meta delete mode 100644 WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs delete mode 100644 WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/Inventory.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/Inventory.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/Item.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/Item.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs.meta delete mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs delete mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs.meta (limited to 'WorldlineKeepers/Assets/Scripts') diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs index 8f65991..1c6ae5a 100644 --- a/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs +++ b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs @@ -13,7 +13,7 @@ public abstract class Buff public BuffMetadata metadata; // buffЧ - public BuffEfectorBase effector; + public BuffBehaviour effector; public string uid { diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs new file mode 100644 index 0000000..0a0559f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BuffBehaviour +{ + private CharacterBase m_Character; + + /// + /// buff生成时候 + /// + public virtual void OnCreate() + { + + } + + /// + /// 更新 + /// + public virtual void OnUpdate() + { + + } + + /// + /// 角色死亡 + /// + public virtual void OnCharacterDeath() + { + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs.meta new file mode 100644 index 0000000..a433744 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5dabb53754f969c4194ad10b2b9fc154 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs deleted file mode 100644 index b90beb8..0000000 --- a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class BuffEfectorBase -{ - private CharacterBase m_Character; - - /// - /// buff生成时候 - /// - public virtual void OnCreate() - { - - } - - /// - /// 更新 - /// - public virtual void OnUpdate() - { - - } - - /// - /// 角色死亡 - /// - public virtual void OnCharacterDeath() - { - } - -} diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta deleted file mode 100644 index a433744..0000000 --- a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5dabb53754f969c4194ad10b2b9fc154 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs b/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs new file mode 100644 index 0000000..ffa33a2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/Statemachine.cs @@ -0,0 +1,254 @@ +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; + } + + /// + /// 첽лij״̬ + /// + /// + 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 new file mode 100644 index 0000000..e2b8d49 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/Statemachine.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/Data/DataManager.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs index a3d1257..3bb9ef2 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs @@ -1,3 +1,4 @@ +using LitJson; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; @@ -11,6 +12,7 @@ namespace WK.Data private Dictionary m_CharacterStatsMetadata = new Dictionary(); private Dictionary m_BuffMetadata = new Dictionary(); + private Dictionary m_CharacterMetadata = new Dictionary(); public CharacterStatsMetadata GetCharacterStats(string uid) { @@ -35,6 +37,7 @@ namespace WK.Data public void Load() { LoadDefaultStats(); + LoadDefaultCharacters(); } private void LoadDefaultStats() @@ -47,6 +50,16 @@ namespace WK.Data } } + private void LoadDefaultCharacters() + { + TextAsset text = ResourceManager.Instance.LoadAsset(StaticDefine.RoninPath); + CharacterMetadata metadata = JsonMapper.ToObject(text.text); + if(metadata != null) + { + m_CharacterMetadata.Add(metadata.uid, metadata); + } + } + } } \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/EntityBase.cs b/WorldlineKeepers/Assets/Scripts/EntityBase.cs index 3470d3c..f894d20 100644 --- a/WorldlineKeepers/Assets/Scripts/EntityBase.cs +++ b/WorldlineKeepers/Assets/Scripts/EntityBase.cs @@ -6,7 +6,7 @@ public class EntityBase : MonoBehaviour { public SpriteRenderer m_Shadow; - private SpriteRenderer m_SpriteRenderer; + protected SpriteRenderer m_SpriteRenderer; protected virtual void Awake() { diff --git a/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs b/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs new file mode 100644 index 0000000..f620a93 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Items +{ + + public class Inventory + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs.meta new file mode 100644 index 0000000..a6a021f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Inventory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0fd1d1f499057e44097943c0eb053781 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/Item.cs b/WorldlineKeepers/Assets/Scripts/Items/Item.cs new file mode 100644 index 0000000..bcffc5b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Item.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using WK.Data; +using WK.Items; + +namespace Wk.Items +{ + + public class Item + { + private ItemMetadata m_Metadata; + public ItemMetadata metadata { get { return m_Metadata; } } + + private ItemBehaviour m_Behaviour; + public ItemBehaviour behaviour { get { return m_Behaviour; } } + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/Item.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/Item.cs.meta new file mode 100644 index 0000000..828b300 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Item.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7ae8ebc7348cf647a6cf90a67bd1711 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs new file mode 100644 index 0000000..520946a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Items +{ + + public class ItemBehaviour + { + + public virtual void OnEquiped() + { + + } + + public virtual void OnUnEquiped() + { + + } + + public virtual void OnStack() + { + + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs.meta new file mode 100644 index 0000000..1acab27 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ecedcd123438614db9ea58933287d13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs new file mode 100644 index 0000000..1e0dfe6 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Items +{ + + public class ItemDaggerBehaviour : ItemBehaviour + { + + + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs.meta new file mode 100644 index 0000000..409141f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemDaggerBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 759db356bc563824882ce1b4ee8fd879 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs new file mode 100644 index 0000000..1008eed --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Items +{ + + public class ItemHellbellBehaviour : ItemBehaviour + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs.meta new file mode 100644 index 0000000..341e7c0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemHellbellBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1156ea03b49c6264692b0552676e606c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs b/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs new file mode 100644 index 0000000..e77f494 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Data +{ + + public class ItemMetadata + { + + public string uid; + + public string name_key; + + public string desc_key; + + public string icon_path; + + public string extra_data; + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs.meta new file mode 100644 index 0000000..07ede60 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemMetadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f5b94a115aa35a4c84083a3743c2639 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/StaticDefine.cs b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs index 53219b5..3f62e8c 100644 --- a/WorldlineKeepers/Assets/Scripts/StaticDefine.cs +++ b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs @@ -10,6 +10,8 @@ namespace WK public static string StatsFilePath = "metadata/default_stats.csv"; public static string BuffFilePath = "metadata/default_buffs.csv"; + public static string RoninPath = "characters/ronin/ronin.json"; + } } \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs index b4869cb..8dbb161 100644 --- a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs @@ -7,24 +7,24 @@ using WK.Data; namespace WK { - [System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)] + [StructLayout(LayoutKind.Explicit)] public struct CharacterStatsValue { - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public int i; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public float f; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public bool boolean; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public char c; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public Vector2 v2; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public Vector3 v3; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public Vector4 v4; - [System.Runtime.InteropServices.FieldOffset(0)] + [FieldOffset(0)] public Color color; } @@ -44,7 +44,15 @@ namespace WK /// ǰֵ /// public CharacterStatsValue value; - + + public ref int intValue => ref value.i; + public ref bool boolValue => ref value.boolean; + public ref float floatValue => ref value.f; + public ref char chartValue => ref value.c; + public ref Vector2 Vector2Value => ref value.v2; + public ref Vector3 Vector3Value => ref value.v3; + public ref Vector4 Vector4Value => ref value.v4; + public string uid { get diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs index c240ca1..dbb0942 100644 --- a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs @@ -16,6 +16,8 @@ namespace WK.Data public string type; + public string behaviour; + // public string extra_data; } diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs b/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs new file mode 100644 index 0000000..c6e9bba --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using WK; + +public class TestEvent : MonoBehaviour +{ + #region 序列化 + + #endregion + + #region 公共字段 + + #endregion + + #region 私有字段 + + #endregion + + private void Awake() + { + // 私有字段赋值 + + // 公共字段赋值 + + // 初始化 + } + + private void OnEnable() + { + GlobalEventManager.Instance.Register("Health.BurnKill", OnEventCheck); + GlobalEventManager.Instance.Notify("Health.BurnKill"); + } + + private void OnEventCheck(params object[] p) + { + Debug.Log("msg"); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs.meta b/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs.meta new file mode 100644 index 0000000..965ecdd --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0825a89e4815bc94eb58cd23aa6f4814 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools.meta b/WorldlineKeepers/Assets/Scripts/Tools.meta new file mode 100644 index 0000000..bc5c8b7 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0f4ad5525cbe4b942bba307305127136 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs b/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs new file mode 100644 index 0000000..47f3990 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs @@ -0,0 +1,97 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; + +namespace WK +{ + /// + /// ȫ¼ + /// + public class GlobalEventManager : Singleton + { + + // callback + public delegate void EventCallback(params object[] objs); + public Dictionary> AllEvents = new Dictionary>(); + + public void Register(string eventName, EventCallback callback, bool addFirst = false) + { + if (callback == null) + { + Debug.LogError("Ϊ"); + return; + } + LinkedList list; + if (!AllEvents.TryGetValue(eventName, out list)) + { + list = new LinkedList(); // ôӳ + AllEvents.Add(eventName, list); + } + if (!list.Contains(callback)) + { + if (addFirst && list.Count > 0) + { + list.AddFirst(callback); + } + else + { + list.AddLast(callback); + } + } + else + { + Debug.LogError("ظӼ, eventName=" + eventName); + } + } + + public void UnRegister(string eventName, EventCallback callback) + { + if (callback == null) + { + Debug.LogError("Ϊ"); + return; + } + LinkedList list; + if (!AllEvents.TryGetValue(eventName, out list)) + { + return; + } + list.Remove(callback); + if (list.Count == 0) + { + AllEvents.Remove(eventName); + // listǴӳõģ + } + } + + public void UnRegisterEvent(string eventName) + { + if (AllEvents.ContainsKey(eventName)) + { + AllEvents.Remove(eventName); + } + } + + public void UnRegisterAll(string eventName) + { + AllEvents.Remove(eventName); + } + + public void Notify(string eventName, params object[] objs) + { + LinkedList list; + if (AllEvents.TryGetValue(eventName, out list) && list != null && list.Count > 0) + { + foreach (EventCallback callback in list) + { + if (callback != null) + { + callback.Invoke(objs); + } + } + } + } + + } +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs.meta new file mode 100644 index 0000000..0c2c8ec --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/GlobalEventManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a9f38c8080be5e41ad5220346ba8c7f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs b/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs new file mode 100644 index 0000000..b3f299a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class NotificationCenter + { + private Dictionary>>> _table = new Dictionary>>>(); + + private HashSet>> _invoking = new HashSet>>(); + + public static readonly NotificationCenter instance = new NotificationCenter(); + + private NotificationCenter() + { + } + + public void AddObserver(Action handler, string notificationName) + { + AddObserver(handler, notificationName, null); + } + + public void AddObserver(Action handler, string notificationName, object sender) + { + if (handler == null) + { + Debug.LogError("Can't add a null event handler for notification, " + notificationName); + return; + } + if (string.IsNullOrEmpty(notificationName)) + { + Debug.LogError("Can't observe an unnamed notification"); + return; + } + if (!_table.ContainsKey(notificationName)) + { + _table.Add(notificationName, new Dictionary>>()); + } + Dictionary>> dictionary = _table[notificationName]; + object key = ((sender != null) ? sender : this); + if (!dictionary.ContainsKey(key)) + { + dictionary.Add(key, new List>()); + } + List> list = dictionary[key]; + if (_invoking.Contains(list)) + { + list = (dictionary[key] = new List>(list)); + } + list.Add(handler); + } + + public void RemoveObserver(Action handler, string notificationName) + { + RemoveObserver(handler, notificationName, null); + } + + public void RemoveObserver(Action handler, string notificationName, object sender) + { + if (handler == null) + { + Debug.LogError("Can't remove a null event handler for notification, " + notificationName); + } + else if (string.IsNullOrEmpty(notificationName)) + { + Debug.LogError("A notification name is required to stop observation"); + } + else + { + if (!_table.ContainsKey(notificationName)) + { + return; + } + Dictionary>> dictionary = _table[notificationName]; + object key = ((sender != null) ? sender : this); + if (!dictionary.ContainsKey(key)) + { + return; + } + List> list = dictionary[key]; + int num = list.IndexOf(handler); + if (num != -1) + { + if (_invoking.Contains(list)) + { + list = (dictionary[key] = new List>(list)); + } + list.RemoveAt(num); + } + } + } + + public void Clean() + { + string[] array = new string[_table.Keys.Count]; + _table.Keys.CopyTo(array, 0); + for (int num = array.Length - 1; num >= 0; num--) + { + string key = array[num]; + Dictionary>> dictionary = _table[key]; + object[] array2 = new object[dictionary.Keys.Count]; + dictionary.Keys.CopyTo(array2, 0); + for (int num2 = array2.Length - 1; num2 >= 0; num2--) + { + object key2 = array2[num2]; + if (dictionary[key2].Count == 0) + { + dictionary.Remove(key2); + } + } + if (dictionary.Count == 0) + { + _table.Remove(key); + } + } + } + + public void PostNotification(string notificationName) + { + PostNotification(notificationName, null); + } + + public void PostNotification(string notificationName, object sender) + { + PostNotification(notificationName, sender, null); + } + + public void PostNotification(string notificationName, object sender, object e) + { + if (string.IsNullOrEmpty(notificationName)) + { + Debug.LogError("A notification name is required"); + } + else + { + if (!_table.ContainsKey(notificationName)) + { + return; + } + Dictionary>> dictionary = _table[notificationName]; + if (sender != null && dictionary.ContainsKey(sender)) + { + List> list = dictionary[sender]; + _invoking.Add(list); + for (int i = 0; i < list.Count; i++) + { + list[i](sender, e); + } + _invoking.Remove(list); + } + if (dictionary.ContainsKey(this)) + { + List> list2 = dictionary[this]; + _invoking.Add(list2); + for (int j = 0; j < list2.Count; j++) + { + list2[j](sender, e); + } + _invoking.Remove(list2); + } + } + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs.meta new file mode 100644 index 0000000..13d54ee --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/NotificationCenter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f222398a57afbf446b471ccf17bb9575 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs new file mode 100644 index 0000000..7674523 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + /// + /// ɫ淨Ϊǽɫ淨ġҪ̳ʵ + /// + public abstract class CharacterBehaviour + { + private PlayerController m_Controller; + public PlayerController controller { get { return m_Controller; } } + + public CharacterInfo info { get { return m_Controller.info; } } + + public virtual void OnCreate() + { + } + + public virtual void OnGlobalUpdate() + { + } + + public virtual void OnStageUpdate() + { + } + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs.meta new file mode 100644 index 0000000..330a2d3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 65afd074deb4dbc468bd8d8940712002 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs deleted file mode 100644 index 7674523..0000000 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace WK -{ - - /// - /// ɫ淨Ϊǽɫ淨ġҪ̳ʵ - /// - public abstract class CharacterBehaviour - { - private PlayerController m_Controller; - public PlayerController controller { get { return m_Controller; } } - - public CharacterInfo info { get { return m_Controller.info; } } - - public virtual void OnCreate() - { - } - - public virtual void OnGlobalUpdate() - { - } - - public virtual void OnStageUpdate() - { - } - - } - -} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta deleted file mode 100644 index 330a2d3..0000000 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 65afd074deb4dbc468bd8d8940712002 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs new file mode 100644 index 0000000..81b80c0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Data +{ + + public class CharacterMetadata + { + + public string uid; + + public string name_key; + + public Dictionary stats; + + public string behaviour; + + public string extra_data; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs.meta new file mode 100644 index 0000000..f39e3ec --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ecafd17226029e748994c5814d59cc03 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs index 66bf6df..2f19fb3 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs @@ -7,9 +7,15 @@ namespace WK public class PlayerController { + /// + /// ɫеǰֵ + /// private CharacterInfo m_CharacterInfo; public CharacterInfo info { get { return m_CharacterInfo; } } + /// + /// ɫΪ߼ + /// private CharacterBehaviour m_CharacterBehaviour; public CharacterBehaviour behaviour { get { return m_CharacterBehaviour; } } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs index 4a348eb..1964323 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs @@ -13,7 +13,8 @@ public class RoninBehaviour : CharacterBehaviour if (info.stats["max_health"] != null) { - int health = info.stats["max_health"].value.i; + int health = info.stats["max_health"].intValue; + } } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs index 7ebae9c..dbcab58 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs @@ -17,7 +17,7 @@ public class SpiritScript : UnitBase private static List collisions = new List(); - private SpriteRenderer m_SpriteRenderer; + //private SpriteRenderer m_SpriteRenderer; private int m_CollisionCheckerCount = 0; @@ -32,7 +32,7 @@ public class SpiritScript : UnitBase speed = 2; TestSpirits.spirits.Add(this); } - + protected override void Update() { base.Update(); diff --git a/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs b/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs new file mode 100644 index 0000000..9ec97f3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class UnitManager + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs.meta new file mode 100644 index 0000000..a1d3faf --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/UnitManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c5e1e3ffbd73844aa887ef5d5a829f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0