summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Data
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-05-31 09:21:51 +0800
committerchai <215380520@qq.com>2023-05-31 09:21:51 +0800
commitdbf4ea119100f571b3710568dfdc2e09dcec2a61 (patch)
tree50d3721718aeff5944b5baa8d392a1d8cfa1bad1 /WorldlineKeepers/Assets/Scripts/Data
parent2fcb4625389b1594bbefdbaf2e038b2cfffa8ead (diff)
*misc
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Data')
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs137
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/DataManager.cs99
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs24
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs.meta (renamed from WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta)2
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs4
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata.meta8
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs (renamed from WorldlineKeepers/Assets/Scripts/Data/FileKey.cs)2
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs.meta (renamed from WorldlineKeepers/Assets/Scripts/Data/FileKey.cs.meta)0
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs (renamed from WorldlineKeepers/Assets/Scripts/Data/Filelist.cs)11
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs.meta (renamed from WorldlineKeepers/Assets/Scripts/Data/Filelist.cs.meta)0
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs17
-rw-r--r--WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs.meta11
12 files changed, 117 insertions, 198 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs b/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs
deleted file mode 100644
index 207656b..0000000
--- a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-using JetBrains.Annotations;
-using LitJson;
-using Newtonsoft.Json.Serialization;
-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<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();
-
- m_Rows = CSVParser.LoadFromString(content);
- // 第一行是key
- List<string> keys = m_Rows[0];
- for (int i = 0; i < keys.Count; ++i)
- {
- m_KeyMapping.Add(keys[i], i);
- }
- int count = 0;
- Type type = typeof(T);
- for (int i = 1; i < m_Rows.Count; ++i)
- {
- if (m_Rows[i][0][0] == '#') // 注释
- continue;
- List<string> 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)
- {
- 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));
- }
- }
- }
- target.Add(obj);
- count++;
- }
- 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;
- }
-
- }
-
-} \ No newline at end of file
diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs
index 2667736..9ec2734 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs
+++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs
@@ -7,63 +7,54 @@ using UnityEngine;
namespace WK.Data
{
- /// <summary>
- /// 所有配置数据
- /// </summary>
public partial class DataManager : Singleton<DataManager>
{
- private Dictionary<string/*uid*/, CharacterStatsMetadata> m_CharacterStatsMetadata = new Dictionary<string, CharacterStatsMetadata>();
- private Dictionary<string/*uid*/, BuffMetadata> m_BuffMetadata = new Dictionary<string, BuffMetadata>();
- private Dictionary<string/*uid*/, CharacterMetadata> m_CharacterMetadata = new Dictionary<string, CharacterMetadata>();
-
- private Dictionary<EFileKey, MetadataFile> m_Filelist = new Dictionary<EFileKey, MetadataFile>();
-
- public CharacterStatsMetadata GetCharacterStats(string uid)
- {
- CharacterStatsMetadata metadata;
- if(m_CharacterStatsMetadata.TryGetValue(uid, out metadata))
- {
- return metadata;
- }
- return null;
- }
-
- public BuffMetadata GetBuffMetadata(string uid)
- {
- BuffMetadata metadata;
- if(m_BuffMetadata.TryGetValue(uid, out metadata))
- {
- return metadata;
- }
- return null;
- }
-
- public void Load()
- {
- LoadDefaultStats();
- LoadDefaultCharacters();
- }
-
- private void LoadDefaultStats()
- {
- TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.StatsFilePath);
- List<CharacterStatsMetadata> stats = CSVReader.Read<CharacterStatsMetadata>(text.text);
- for(int i = 0; i < stats.Count; ++i)
- {
- m_CharacterStatsMetadata.Add(stats[i].uid, stats[i]);
- }
- }
-
- private void LoadDefaultCharacters()
- {
- TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.RoninPath);
- CharacterMetadata metadata = JsonMapper.ToObject<CharacterMetadata>(text.text);
- if(metadata != null)
- {
- m_CharacterMetadata.Add(metadata.uid, metadata);
- }
- }
+ //public CharacterStatsMetadata GetCharacterStats(string uid)
+ //{
+ // CharacterStatsMetadata metadata;
+ // if(m_CharacterStatsMetadata.TryGetValue(uid, out metadata))
+ // {
+ // return metadata;
+ // }
+ // return null;
+ //}
+
+ //public BuffMetadata GetBuffMetadata(string uid)
+ //{
+ // BuffMetadata metadata;
+ // if(m_BuffMetadata.TryGetValue(uid, out metadata))
+ // {
+ // return metadata;
+ // }
+ // return null;
+ //}
+
+ //public void Load()
+ //{
+ // LoadDefaultStats();
+ // LoadDefaultCharacters();
+ //}
+
+ //private void LoadDefaultStats()
+ //{
+ // TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.StatsFilePath);
+ // List<CharacterStatsMetadata> stats = CSVReader.Read<CharacterStatsMetadata>(text.text);
+ // for(int i = 0; i < stats.Count; ++i)
+ // {
+ // m_CharacterStatsMetadata.Add(stats[i].uid, stats[i]);
+ // }
+ //}
+
+ //private void LoadDefaultCharacters()
+ //{
+ // TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.RoninPath);
+ // CharacterMetadata metadata = JsonMapper.ToObject<CharacterMetadata>(text.text);
+ // if(metadata != null)
+ // {
+ // m_CharacterMetadata.Add(metadata.uid, metadata);
+ // }
+ //}
}
diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs
new file mode 100644
index 0000000..d16c785
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace WK.Data
+{
+
+ /// <summary>
+ /// 所有配置数据
+ /// </summary>
+ public partial class DataManager : Singleton<DataManager>
+ {
+ // 文件列表
+ private Dictionary<string/*EFileKey*/, MetadataFileDescriptor> m_Filelist = new Dictionary<string, MetadataFileDescriptor>();
+
+ private Dictionary<string/*uid*/, CharacterStatsMetadata> m_CharacterStatsMetadata = new Dictionary<string, CharacterStatsMetadata>();
+ private Dictionary<string/*uid*/, BuffMetadata> m_BuffMetadata = new Dictionary<string, BuffMetadata>();
+ private Dictionary<string/*uid*/, CharacterMetadata> m_CharacterMetadata = new Dictionary<string, CharacterMetadata>();
+
+
+
+ }
+
+}
diff --git a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs.meta
index 52670ce..cea1f4f 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/CSVReader.cs.meta
+++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: f6b35022c04390a46beb2b27711a7950
+guid: 707bcf2d592188048b205923766b94a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs
index 811f5b4..aab90a9 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs
+++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs
@@ -33,8 +33,8 @@ namespace WK.Data
{
TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.FileList);
string content = text.text;
- List<MetadataFile> files = CSVReader.Read<MetadataFile>(content);
- CSVReader.ReadDictionary<EFileKey, MetadataFile>(m_Filelist, content, "key");
+ List<MetadataFileDescriptor> files = CSVReader.Read<MetadataFileDescriptor>(content);
+ CSVReader.ReadDictionary<string, MetadataFileDescriptor>(m_Filelist, content, "key");
Debug.Log(m_Filelist.Count);
}
diff --git a/WorldlineKeepers/Assets/Scripts/Data/Metadata.meta b/WorldlineKeepers/Assets/Scripts/Data/Metadata.meta
new file mode 100644
index 0000000..adfaa0d
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c9192579c4677b3438c941d65a0a1a61
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/WorldlineKeepers/Assets/Scripts/Data/FileKey.cs b/WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs
index 1ab15b2..621203e 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/FileKey.cs
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs
@@ -6,7 +6,7 @@ namespace WK.Data
{
/// <summary>
- /// 文件enum
+ /// 默认文件enum,编号无所谓,名字不可更改。方便找文件
/// </summary>
public enum EFileKey
{
diff --git a/WorldlineKeepers/Assets/Scripts/Data/FileKey.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs.meta
index 1564c3d..1564c3d 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/FileKey.cs.meta
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/FileKey.cs.meta
diff --git a/WorldlineKeepers/Assets/Scripts/Data/Filelist.cs b/WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs
index dc96df9..b91619b 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/Filelist.cs
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs
@@ -5,6 +5,9 @@ using UnityEngine;
namespace WK.Data
{
+ /// <summary>
+ /// 文件类型
+ /// </summary>
public enum FileType
{
CSV = 0,
@@ -12,6 +15,9 @@ namespace WK.Data
Txt = 2,
}
+ /// <summary>
+ /// 文件路径
+ /// </summary>
public enum FileRoot
{
Bundle = 0,
@@ -20,11 +26,10 @@ namespace WK.Data
}
/// <summary>
- /// 文件列表
+ /// 元文件描述符
/// </summary>
- public class MetadataFile
+ public class MetadataFileDescriptor
{
-
public string key;
public FileType type;
public FileRoot root;
diff --git a/WorldlineKeepers/Assets/Scripts/Data/Filelist.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs.meta
index 9bb6057..9bb6057 100644
--- a/WorldlineKeepers/Assets/Scripts/Data/Filelist.cs.meta
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/Filelist.cs.meta
diff --git a/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs b/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs
new file mode 100644
index 0000000..ed7b1cb
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs
@@ -0,0 +1,17 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace WK.Data
+{
+ /// <summary>
+ /// 关卡元数据
+ /// </summary>
+ public class StageMetadata
+ {
+
+
+
+ }
+
+}
diff --git a/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs.meta
new file mode 100644
index 0000000..7ff42d8
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Data/Metadata/StageMetadata.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7e2e7c43d0f01fe4799d8284e9982627
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: