From 38e177b0fdf130d6a361ab51c80b5b56ee83f28e Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 26 May 2023 19:12:36 +0800 Subject: *misc --- WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs | 94 ++++++++++++++++++++-- .../Assets/Scripts/Data/DataManager.cs | 2 +- .../Assets/Scripts/Data/DataManager_Load.cs | 19 ++--- .../Assets/Scripts/Physics/FastBoxCollider.cs | 8 ++ .../Assets/Scripts/Physics/FastCircleCollider.cs | 8 ++ .../Assets/Scripts/Physics/PhysicsManager.cs | 4 +- .../Scripts/Physics/PhysicsManager_StaticTree.cs | 38 +++++++++ .../Assets/Scripts/Physics/PhysicsQuadtree.cs | 3 + .../Assets/Scripts/Physics/TestSpirits.cs | 1 - .../Assets/Scripts/Stages/GameStageBase.cs | 6 ++ .../Assets/Scripts/Stages/GameStageManager.cs | 3 +- .../Assets/Scripts/Stages/GameStage_Launch.cs | 12 +++ .../Assets/Scripts/Stages/GameStage_Main.cs | 3 + WorldlineKeepers/Assets/Scripts/StaticDefine.cs | 1 + WorldlineKeepers/Assets/Scripts/UI/PanelBase.cs | 20 ++++- WorldlineKeepers/Assets/Scripts/UI/Panels.meta | 8 ++ .../Assets/Scripts/UI/Panels/PanelEntries.meta | 8 ++ .../Scripts/UI/Panels/PanelEntries/PanelEntries.cs | 28 +++++++ .../UI/Panels/PanelEntries/PanelEntries.cs.meta | 11 +++ .../Assets/Scripts/Utils/AsyncUtils.cs | 5 ++ 20 files changed, 262 insertions(+), 20 deletions(-) create mode 100644 WorldlineKeepers/Assets/Scripts/UI/Panels.meta create mode 100644 WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries.meta create mode 100644 WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs create mode 100644 WorldlineKeepers/Assets/Scripts/UI/Panels/PanelEntries/PanelEntries.cs.meta (limited to 'WorldlineKeepers/Assets/Scripts') 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,7 +18,26 @@ namespace WK.Data private static Dictionary m_KeyMapping = new Dictionary(); private static List> m_Rows = new List>(); + /// + /// 解析csv表格,并返回列表 + /// + /// + /// + /// public static List Read(string content) where T : new() + { + List result = new List(); + Read(result, content); + return result; + } + + /// + /// 解析csv表格,并返回数量 + /// + /// + /// + /// + public static int Read(List 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 result = new List(); + 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 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; + } + + /// + /// 解析csv表格,并按key存储到字典里,返回数量 + /// + /// + /// + /// + /// + /// + /// + public static int ReadDictionary(Dictionary target, string content, string keyName) where TValue : new() + { + List data = CSVReader.Read(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 m_BuffMetadata = new Dictionary(); private Dictionary m_CharacterMetadata = new Dictionary(); - private Dictionary m_Filelist = new Dictionary(); + private Dictionary m_Filelist = new Dictionary(); 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 加载 - /// /// fielist /// @@ -36,15 +34,18 @@ namespace WK.Data TextAsset text = ResourceManager.Instance.LoadAsset(StaticDefine.FileList); string content = text.text; List files = CSVReader.Read(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(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 { - // 四叉树筛选结果 public List sharedRetriveResults => m_SharedRetriveResults; private List m_SharedRetriveResults = new List(); @@ -28,6 +28,8 @@ public partial class PhysicsManager : Singleton 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; +/// +/// 不经常改变位置和大小的collider认为是静态collider,不会每帧重建 +/// public partial class PhysicsManager : Singleton { + 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 returnObjs, IQuadTreeObject obj) + { + return m_StaticCollisionQuadtree.Retrive(ref returnObjs, obj); + } + + public bool RetriveStaticColliders(ref List 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); } + /// + /// 閲嶅缓鍥涘弶鏍 + /// 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 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 { + /// + /// 主界面 + /// 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 { /// @@ -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 { + /// + /// 异步处理任务 + /// + /// + /// public static CoroutineHandle AsyncAction(IEnumerator asyncAct) { var handle = Timing.Instance.RunCoroutineOnInstance(asyncAct); -- cgit v1.1-26-g67d0