From 6c91f1ed6810a57da08a24dd1359f288c443dd75 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 19:00:29 +0800 Subject: *misc --- WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs | 55 ++++++++++++++ .../Assets/Scripts/Data/CSVReader.cs.meta | 11 +++ .../Assets/Scripts/Data/DataManager.cs | 19 ++++- WorldlineKeepers/Assets/Scripts/Managers/Main.cs | 36 +++++++++ .../Assets/Scripts/Managers/Main.cs.meta | 11 +++ WorldlineKeepers/Assets/Scripts/Particles.meta | 8 ++ .../Assets/Scripts/Particles/ParticleEffect.cs | 17 +++++ .../Scripts/Particles/ParticleEffect.cs.meta | 11 +++ WorldlineKeepers/Assets/Scripts/Rendering.meta | 8 ++ .../Assets/Scripts/Rendering/SpriteAnimation.cs | 16 ++++ .../Scripts/Rendering/SpriteAnimation.cs.meta | 11 +++ .../Scripts/Rendering/SpriteAnimationController.cs | 34 +++++++++ .../Rendering/SpriteAnimationController.cs.meta | 11 +++ WorldlineKeepers/Assets/Scripts/StaticDefine.cs | 15 ++++ .../Assets/Scripts/StaticDefine.cs.meta | 11 +++ .../Assets/Scripts/Stats/CharacterStatsMetadata.cs | 2 +- WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs | 86 ++++++++++++---------- WorldlineKeepers/Assets/Scripts/Tests/TestJson.cs | 1 + .../Scripts/Unit/Characters/CharacterController.cs | 32 ++++++++ .../Unit/Characters/CharacterController.cs.meta | 11 +++ .../Scripts/Unit/Characters/PlayerController.cs | 18 +++++ .../Unit/Characters/PlayerController.cs.meta | 11 +++ .../Assets/Scripts/Unit/Characters/Ronin.meta | 8 ++ .../Unit/Characters/Ronin/RoninBehaviour.cs | 20 +++++ .../Unit/Characters/Ronin/RoninBehaviour.cs.meta | 11 +++ 25 files changed, 433 insertions(+), 41 deletions(-) create mode 100644 WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Managers/Main.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Managers/Main.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Particles.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Rendering.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/StaticDefine.cs create mode 100644 WorldlineKeepers/Assets/Scripts/StaticDefine.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin.meta create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs create mode 100644 WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs.meta (limited to 'WorldlineKeepers/Assets/Scripts') diff --git a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs new file mode 100644 index 0000000..312eba8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs @@ -0,0 +1,55 @@ +using JetBrains.Annotations; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net.Mime; +using System.Reflection; +using UnityEngine; +using yutokun; +using static UnityEngine.Rendering.DebugUI; + +namespace WK.Data +{ + + public class CSVReader + { + private static Dictionary m_KeyMapping = new Dictionary(); + private static List> m_Rows = new List>(); + + public static List Read(string content) where T : new() + { + m_KeyMapping.Clear(); + m_Rows.Clear(); + + m_Rows = CSVParser.LoadFromString(content); + // һkey + List keys = m_Rows[0]; + for (int i = 0; i < keys.Count; ++i) + { + m_KeyMapping.Add(keys[i], i); + } + List result = new List(); + Type type = typeof(T); + for (int i = 1; i < m_Rows.Count; ++i) + { + if (m_Rows[i][0][0] == '#') // ע + continue; + List row = m_Rows[i]; + T obj = new T(); + foreach(var key in m_KeyMapping) + { + int index = key.Value; + var fieldInfo = type.GetField(key.Key); + if(fieldInfo != null) + { + fieldInfo.SetValue(obj, Convert.ChangeType(row[index], fieldInfo.FieldType)); + } + } + result.Add(obj); + } + return result; + } + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta new file mode 100644 index 0000000..52670ce --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f6b35022c04390a46beb2b27711a7950 +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 e56c80b..a3d1257 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs @@ -9,8 +9,8 @@ namespace WK.Data public class DataManager : Singleton { - private Dictionary m_CharacterStatsMetadata; - private Dictionary m_BuffMetadata; + private Dictionary m_CharacterStatsMetadata = new Dictionary(); + private Dictionary m_BuffMetadata = new Dictionary(); public CharacterStatsMetadata GetCharacterStats(string uid) { @@ -32,6 +32,21 @@ namespace WK.Data return null; } + public void Load() + { + LoadDefaultStats(); + } + + private void LoadDefaultStats() + { + TextAsset text = ResourceManager.Instance.LoadAsset(StaticDefine.StatsFilePath); + List stats = CSVReader.Read(text.text); + for(int i = 0; i < stats.Count; ++i) + { + m_CharacterStatsMetadata.Add(stats[i].uid, stats[i]); + } + } + } } \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Managers/Main.cs b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs new file mode 100644 index 0000000..976779d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using WK.Data; + +namespace WK +{ + + public class Main : SingletonMB
+ { + protected override void Awake() + { + base.Awake(); + DontDestroyOnLoad(this.gameObject); + } + + private void Start() + { + DataManager.Instance.Load(); + + Debug.Log(DataManager.Instance.GetCharacterStats("health")); + } + + private void Update() + { + + } + + private void FixedUpdate() + { + + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Managers/Main.cs.meta b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs.meta new file mode 100644 index 0000000..f8cfcd8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/Main.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e1448edde341f4f44b6959c045b6600b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Particles.meta b/WorldlineKeepers/Assets/Scripts/Particles.meta new file mode 100644 index 0000000..8cc2ebb --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Particles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af5fa8c4dfb03144b82e12b7640aac6b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs b/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs new file mode 100644 index 0000000..514c0b0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + public class Particle + { + + } + + public class ParticleEffect + { + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs.meta b/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs.meta new file mode 100644 index 0000000..6f48db8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Particles/ParticleEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c224205c69a732e4d86047718d17b716 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Rendering.meta b/WorldlineKeepers/Assets/Scripts/Rendering.meta new file mode 100644 index 0000000..311f706 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Rendering.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 71e7fb8d495c42741af95417c97c5477 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs new file mode 100644 index 0000000..f2b7e98 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Rendering +{ + + public class SpriteAnimation + { + public List sprites; + + public float duration; + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs.meta b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs.meta new file mode 100644 index 0000000..6350064 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e85d2c6a8c8a6f41aad37c9bf63851a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs new file mode 100644 index 0000000..315cf91 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Rendering +{ + + public class SpriteAnimationController : MonoBehaviour + { + #region 序列化 + [SerializeField] private SpriteAnimation m_SpriteAnimation; + [SerializeField] private bool m_AutoPlay; + #endregion + + #region 公共字段 + + #endregion + + #region 私有字段 + + #endregion + + private void Awake() + { + // 私有字段赋值 + + // 公共字段赋值 + + // 初始化 + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs.meta b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs.meta new file mode 100644 index 0000000..910958f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Rendering/SpriteAnimationController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 167a1a5c7e017484d92699dc23a2b5c0 +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 new file mode 100644 index 0000000..53219b5 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + public class StaticDefine + { + public static string StatsFilePath = "metadata/default_stats.csv"; + public static string BuffFilePath = "metadata/default_buffs.csv"; + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/StaticDefine.cs.meta b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs.meta new file mode 100644 index 0000000..c7693e2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/StaticDefine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5cbd85a50d3874748ae49b6aa5ed74e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs index 3b0b13b..c240ca1 100644 --- a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs @@ -14,7 +14,7 @@ namespace WK.Data public string name_key; - public int type; + public string type; // public string extra_data; diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs index 068d235..b24a8c7 100644 --- a/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs @@ -4,54 +4,64 @@ using System.Collections.Generic; using System.Resources; using System.Text; using UnityEngine; +using WK.Data; +using WK; using yutokun; -public class TestCSV : MonoBehaviour +namespace WK { - #region 序列化 - - #endregion - - #region 公共字段 - - #endregion - - #region 私有字段 - - #endregion - - private void OnEnable() - { - // 私有字段赋值 - - // 公共字段赋值 - - // 初始化 - - TextAsset text = WK.ResourceManager.Instance.LoadAsset("metadata/default_stats.csv"); - - var sheet = CSVParser.LoadFromString(text.text); - - var styled = new StringBuilder(); - foreach (var row in sheet) + + public class TestCSV : MonoBehaviour + { + #region 序列化 + + #endregion + + #region 公共字段 + + #endregion + + #region 私有字段 + + #endregion + + private void OnEnable() { - styled.Append("| "); + // 私有字段赋值 + + // 公共字段赋值 - if (row[0][0] == '#') - continue; + // 初始化 - foreach (var cell in row) + TextAsset text = ResourceManager.Instance.LoadAsset("metadata/default_stats.csv"); + + var sheet = CSVParser.LoadFromString(text.text); + + var styled = new StringBuilder(); + foreach (var row in sheet) { - styled.Append(cell); - styled.Append(" | "); + styled.Append("| "); + + if (row[0][0] == '#') + continue; + + foreach (var cell in row) + { + styled.Append(cell); + styled.Append(" | "); + } + + styled.AppendLine(); } - styled.AppendLine(); - } + Debug.Log(styled.ToString()); // Unity + Console.WriteLine(styled.ToString()); // C# - Debug.Log(styled.ToString()); // Unity - Console.WriteLine(styled.ToString()); // C# + List stats = CSVReader.Read(text.text); + Debug.Log(stats.Count); + + } } -} +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestJson.cs b/WorldlineKeepers/Assets/Scripts/Tests/TestJson.cs index 89d6219..dbfa8dc 100644 --- a/WorldlineKeepers/Assets/Scripts/Tests/TestJson.cs +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestJson.cs @@ -62,6 +62,7 @@ public class TestJson : MonoBehaviour SaveDatas sd = JsonMapper.ToObject(Datas); Debug.Log(Datas); + } private void Reset() diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs new file mode 100644 index 0000000..7674523 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.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/CharacterController.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.cs.meta new file mode 100644 index 0000000..330a2d3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterController.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/PlayerController.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs new file mode 100644 index 0000000..66bf6df --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +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; } } + + } + +} \ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs.meta new file mode 100644 index 0000000..6d0088e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 66c187a180d1c0848aa1a1743aec6cdc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin.meta new file mode 100644 index 0000000..05dfd58 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1dc22d7994acb134f9036b17b2831130 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs new file mode 100644 index 0000000..4a348eb --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs @@ -0,0 +1,20 @@ +using Mono.Cecil.Cil; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using WK; + +public class RoninBehaviour : CharacterBehaviour +{ + + public override void OnCreate() + { + base.OnCreate(); + + if (info.stats["max_health"] != null) + { + int health = info.stats["max_health"].value.i; + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs.meta new file mode 100644 index 0000000..8edce5b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Ronin/RoninBehaviour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7064bd9c8014c684db967665061cb779 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0