diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts')
20 files changed, 262 insertions, 20 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs index 312eba8..207656b 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs @@ -1,4 +1,6 @@ using JetBrains.Annotations; +using LitJson; +using Newtonsoft.Json.Serialization; using System; using System.Collections; using System.Collections.Generic; @@ -16,8 +18,27 @@ namespace WK.Data private static Dictionary<string/*key*/, int/*index*/> m_KeyMapping = new Dictionary<string, int>(); private static List<List<string>> m_Rows = new List<List<string>>(); + /// <summary> + /// 解析csv表格,并返回列表 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="content"></param> + /// <returns></returns> public static List<T> Read<T>(string content) where T : new() { + List<T> result = new List<T>(); + Read<T>(result, content); + return result; + } + + /// <summary> + /// 解析csv表格,并返回数量 + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="content"></param> + /// <returns></returns> + public static int Read<T>(List<T> target, string content) where T : new() + { m_KeyMapping.Clear(); m_Rows.Clear(); @@ -28,7 +49,7 @@ namespace WK.Data { m_KeyMapping.Add(keys[i], i); } - List<T> result = new List<T>(); + int count = 0; Type type = typeof(T); for (int i = 1; i < m_Rows.Count; ++i) { @@ -36,18 +57,79 @@ namespace WK.Data continue; List<string> row = m_Rows[i]; T obj = new T(); - foreach(var key in m_KeyMapping) + foreach (var key in m_KeyMapping) { int index = key.Value; var fieldInfo = type.GetField(key.Key); - if(fieldInfo != null) + if (fieldInfo != null) { - fieldInfo.SetValue(obj, Convert.ChangeType(row[index], fieldInfo.FieldType)); + Type fieldType = fieldInfo.FieldType; + if (fieldType.IsEnum) // 如果是枚举,先转成int + { + int value = int.Parse(row[index]); + fieldInfo.SetValue(obj, value); + } + else + { + fieldInfo.SetValue(obj, Convert.ChangeType(row[index], fieldInfo.FieldType)); + } } } - result.Add(obj); + target.Add(obj); + count++; } - return result; + return count; + } + + /// <summary> + /// 解析csv表格,并按key存储到字典里,返回数量 + /// </summary> + /// <typeparam name="TKey"></typeparam> + /// <typeparam name="TValue"></typeparam> + /// <param name="target"></param> + /// <param name="content"></param> + /// <param name="keyName"></param> + /// <returns></returns> + public static int ReadDictionary<TKey, TValue>(Dictionary<TKey, TValue> target, string content, string keyName) where TValue : new() + { + List<TValue> data = CSVReader.Read<TValue>(content); + if (data == null || data.Count == 0) + return 0; + Type type_key = typeof(TKey); + Type type_value = typeof(TValue); + FieldInfo field = type_value.GetField(keyName); + Type type_field = field.FieldType; + int count = 0; + for (int i = 0; i < data.Count; ++i) + { + TValue d = data[i]; + + TKey key = default(TKey); + if (type_key.IsEnum) + { + if(type_field == typeof(string)) + { + key = (TKey)Enum.Parse(type_key, field.GetValue(d).ToString()); + } + else if(type_field == typeof(int)) + { + key = (TKey)field.GetValue(d); + } + } + else + { + key = (TKey)field.GetValue(d); + } + if (key == null) + { + LogHelper.LogError("CSVReader.ReadDictionary(): key is null"); + continue; + } + + target.Add(key, d); + count++; + } + return count; } } diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs index 1c148ee..2667736 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs @@ -17,7 +17,7 @@ namespace WK.Data private Dictionary<string/*uid*/, BuffMetadata> m_BuffMetadata = new Dictionary<string, BuffMetadata>(); private Dictionary<string/*uid*/, CharacterMetadata> m_CharacterMetadata = new Dictionary<string, CharacterMetadata>(); - private Dictionary<int, MetadataFile> m_Filelist = new Dictionary<int, MetadataFile>(); + private Dictionary<EFileKey, MetadataFile> m_Filelist = new Dictionary<EFileKey, MetadataFile>(); public CharacterStatsMetadata GetCharacterStats(string uid) { diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs index 40b00a7..75de5f3 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs @@ -26,8 +26,6 @@ namespace WK.Data yield return Timing.WaitForSeconds(StaticDefine.IntervalLoadFile); } - #region 加载 - /// <summary> /// fielist /// </summary> @@ -36,15 +34,18 @@ namespace WK.Data TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.FileList); string content = text.text; List<MetadataFile> files = CSVReader.Read<MetadataFile>(content); - for (int i = 0; i < files.Count; ++i) - { - MetadataFile file = files[i]; - int key = (int)Enum.Parse(typeof(EFileKey), file.key); - m_Filelist.Add(key, file); - } + //for (int i = 0; i < files.Count; ++i) + //{ + // MetadataFile file = files[i]; + // int key = (int)Enum.Parse(typeof(EFileKey), file.key); + // m_Filelist.Add(key, file); + //} + + CSVReader.ReadDictionary<EFileKey, MetadataFile>(m_Filelist, content, "key"); + + Debug.Log(m_Filelist.Count); } - #endregion } }
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs index df84e0d..a644b69 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs @@ -60,6 +60,10 @@ public class FastBoxCollider : MonoBehaviour, IQuadTreeObject { PhysicsManager.Instance.AddHurtboxes(this); } + else if (m_Type == ColliderType.StaticCollider) + { + PhysicsManager.Instance.AddStaticCollider(this); + } } public void OnDestroy() @@ -72,6 +76,10 @@ public class FastBoxCollider : MonoBehaviour, IQuadTreeObject { PhysicsManager.Instance.RemoveHurtbox(this); } + else if (m_Type == ColliderType.StaticCollider) + { + PhysicsManager.Instance.RemoveStaticCollider(this); + } } private void OnDrawGizmos() diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs index dde49f9..5f04a9f 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs @@ -60,6 +60,10 @@ public class FastCircleCollider : MonoBehaviour, IQuadTreeObject { PhysicsManager.Instance.AddHurtboxes(this); } + else if(m_Type == ColliderType.StaticCollider) + { + PhysicsManager.Instance.AddStaticCollider(this); + } } public void OnDestroy() @@ -72,6 +76,10 @@ public class FastCircleCollider : MonoBehaviour, IQuadTreeObject { PhysicsManager.Instance.RemoveHurtbox(this); } + else if(m_Type == ColliderType.StaticCollider) + { + PhysicsManager.Instance.RemoveStaticCollider(this); + } } private void OnDrawGizmos() diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs index b726d6b..182ea16 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs @@ -8,11 +8,11 @@ public enum ColliderType { Collider, Hurtbox, + StaticCollider, } public partial class PhysicsManager : Singleton<PhysicsManager> { - // 四叉树筛选结果 public List<IQuadTreeObject> sharedRetriveResults => m_SharedRetriveResults; private List<IQuadTreeObject> m_SharedRetriveResults = new List<IQuadTreeObject>(); @@ -28,6 +28,8 @@ public partial class PhysicsManager : Singleton<PhysicsManager> return RetriveColliders; else if (type == ColliderType.Hurtbox) return RetriveHurtboxes; + else if (type == ColliderType.StaticCollider) + return RetriveStaticColliders; else return null; } diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_StaticTree.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_StaticTree.cs index c759e32..b89da29 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_StaticTree.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_StaticTree.cs @@ -1,10 +1,48 @@ +using mh; using System.Collections; using System.Collections.Generic; using UnityEngine; +/// <summary> +/// 不经常改变位置和大小的collider认为是静态collider,不会每帧重建 +/// </summary> public partial class PhysicsManager : Singleton<PhysicsManager> { + private PhysicsQuadtree m_StaticCollisionQuadtree; + public Vector4 staticCollisionQuadtreeRange + { + set + { + m_StaticCollisionQuadtree.quadtreeRange = value; + } + } + + public void AddStaticCollider(IQuadTreeObject collider) + { + m_StaticCollisionQuadtree.AddObject(collider); + } + + public void RemoveStaticCollider(IQuadTreeObject collider) + { + m_StaticCollisionQuadtree.RemoveObject(collider); + } + + public bool RetriveStaticColliders(ref List<IQuadTreeObject> returnObjs, IQuadTreeObject obj) + { + return m_StaticCollisionQuadtree.Retrive(ref returnObjs, obj); + } + + public bool RetriveStaticColliders(ref List<IQuadTreeObject> returnObjs, Vector4 bound) + { + return m_StaticCollisionQuadtree.Retrive(ref returnObjs, bound); + } + + public bool RetriveStaticColliders(Vector4 bound) + { + m_SharedRetriveResults.Clear(); + return m_StaticCollisionQuadtree.Retrive(ref m_SharedRetriveResults, bound); + } } diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs index 5cd374e..9fa8c2f 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs @@ -40,6 +40,9 @@ class PhysicsQuadtree m_Objects.Remove(obj); } + /// <summary> + /// 閲嶅缓鍥涘弶鏍 + /// </summary> public void UpdateQuadtree() { m_Quadtree.Clear(false); diff --git a/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs index 3f313ae..8e46d3d 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs @@ -12,7 +12,6 @@ public class TestSpirits : MonoBehaviour private const int kMaxCount = 500; - // Start is called before the first frame update void Start() { int count = kMaxCount - spirits.Count; diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs index 19b3535..183310e 100644 --- a/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageBase.cs @@ -24,6 +24,12 @@ namespace WK public override void OnUpdate(float deltaTime) { } + + protected void GotoStage(EGameStage target) + { + owner.AsyncLoadStage(target); + } + } } diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs index a28e56d..d19a06d 100644 --- a/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStageManager.cs @@ -33,7 +33,7 @@ namespace WK stages[(int)EGameStage.Battle] = m_Statemachine.RegisterState(new GameStage_Battle()); stages[(int)EGameStage.Dojo] = m_Statemachine.RegisterState(new GameStage_Dojo()); - m_Statemachine.Start(stages[(int)EGameStage.Dojo]); + m_Statemachine.Start(stages[(int)EGameStage.Launch]); } public void OnStart() @@ -42,6 +42,7 @@ namespace WK public void OnUpdate() { + m_Statemachine.Update(Time.deltaTime); } public void OnFixedUpdate() diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs index 08cec82..2956dca 100644 --- a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Launch.cs @@ -1,6 +1,10 @@ +using MovementEffects; using System.Collections; using System.Collections.Generic; +using System.Data; +using Unity.VisualScripting; using UnityEngine; +using WK.Data; namespace WK { @@ -8,8 +12,12 @@ namespace WK public class GameStage_Launch : GameStageBase { + CoroutineHandle m_CoLoadData; + public override IEnumerator<float> OnStart() { + m_CoLoadData = DataManager.Instance.AsyncLoadAll(); + yield break; } @@ -20,6 +28,10 @@ namespace WK public override void OnUpdate(float deltaTime) { + if (!m_CoLoadData.IsRunning) + { + //GotoStage(EGameStage.Dojo); + } } } diff --git a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs index 8a1d5eb..54ec304 100644 --- a/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs +++ b/WorldlineKeepers/Assets/Scripts/Stages/GameStage_Main.cs @@ -5,6 +5,9 @@ using UnityEngine; namespace WK { + /// <summary> + /// 主界面 + /// </summary> public class GameStage_Main : GameStageBase { diff --git a/WorldlineKeepers/Assets/Scripts/StaticDefine.cs b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs index 05755ec..947882e 100644 --- a/WorldlineKeepers/Assets/Scripts/StaticDefine.cs +++ b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs @@ -17,6 +17,7 @@ namespace WK public static string RoninPath = "characters/ronin/ronin.json"; + // 场景 public static string Scene_Dojo = "Scenes/3_Dojo"; public static string Scene_Stage = "Scenes/4_Stage"; diff --git a/WorldlineKeepers/Assets/Scripts/UI/PanelBase.cs b/WorldlineKeepers/Assets/Scripts/UI/PanelBase.cs index f0b25f7..c2391ca 100644 --- a/WorldlineKeepers/Assets/Scripts/UI/PanelBase.cs +++ b/WorldlineKeepers/Assets/Scripts/UI/PanelBase.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -namespace WK +namespace WK.UI { /// <summary> @@ -11,6 +11,24 @@ namespace WK public class PanelBase : MonoBehaviour { + protected void Awake() + { + OnAwake(); + } + + protected void Start() + { + OnStart(); + } + + protected virtual void OnAwake() + { + } + + protected virtual void OnStart() + { + } + } } diff --git a/WorldlineKeepers/Assets/Scripts/UI/Panels.meta b/WorldlineKeepers/Assets/Scripts/UI/Panels.meta new file mode 100644 index 0000000..1b40c62 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Panels.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bf1825c84278f794785dba326debd24e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries.meta b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries.meta new file mode 100644 index 0000000..902d189 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f29ad0540e5669c4dabe77941585683a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs new file mode 100644 index 0000000..24522aa --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace WK.UI +{ + + public class PanelEntries : PanelBase + { + public Button m_BtnDojo; + + protected override void OnAwake() + { + base.OnAwake(); + + m_BtnDojo.onClick.AddListener(OnClickDojo); + } + + private void OnClickDojo() + { + GameStageManager.Instance.AsyncLoadStage(EGameStage.Dojo); + } + + + } + +};
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs.meta b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs.meta new file mode 100644 index 0000000..532b19f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e8482d947d64cf14ca37ceb33dbeaa62 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/AsyncUtils.cs b/WorldlineKeepers/Assets/Scripts/Utils/AsyncUtils.cs index 14bbc86..a6f97ea 100644 --- a/WorldlineKeepers/Assets/Scripts/Utils/AsyncUtils.cs +++ b/WorldlineKeepers/Assets/Scripts/Utils/AsyncUtils.cs @@ -7,6 +7,11 @@ namespace WK { public static class AsyncUtils { + /// <summary> + /// 异步处理任务 + /// </summary> + /// <param name="asyncAct"></param> + /// <returns></returns> public static CoroutineHandle AsyncAction(IEnumerator<float> asyncAct) { var handle = Timing.Instance.RunCoroutineOnInstance(asyncAct); |