diff --git a/Assets/Plugins/Sirenix/Odin Inspector/Config/Resources/Sirenix/GlobalSerializationConfig.asset b/Assets/Plugins/Sirenix/Odin Inspector/Config/Resources/Sirenix/GlobalSerializationConfig.asset index 0e48b68..185befc 100644 --- a/Assets/Plugins/Sirenix/Odin Inspector/Config/Resources/Sirenix/GlobalSerializationConfig.asset +++ b/Assets/Plugins/Sirenix/Odin Inspector/Config/Resources/Sirenix/GlobalSerializationConfig.asset @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 1549551891, guid: 74721b9f0af448f5ae2e91102a1a5edd, type: 3} m_Name: GlobalSerializationConfig m_EditorClassIdentifier: - HideSerializationCautionaryMessage: 0 + HideSerializationCautionaryMessage: 1 HidePrefabCautionaryMessage: 0 HideOdinSerializeAttributeWarningMessages: 0 HideNonSerializedShowInInspectorWarningMessages: 0 diff --git a/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs b/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs new file mode 100644 index 0000000..ff7c6cb --- /dev/null +++ b/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs @@ -0,0 +1,20 @@ +using System.Reflection; + +namespace Tools.Editor +{ + public static class UnityEditorUtil + { + static MethodInfo clearMethod; + + public static void ClearConsole() + { + if (clearMethod == null) + { + Assembly assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor)); + System.Type logEntries = assembly.GetType("UnityEditor.LogEntries"); + clearMethod = logEntries.GetMethod("Clear"); + } + clearMethod.Invoke(new object(), null); + } + } +} \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs.meta b/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs.meta new file mode 100644 index 0000000..b33b363 --- /dev/null +++ b/Assets/Unity-Tools/Core/Editor/UnityEditorUtil.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b4f042c2bcf24f2494edc41df37ff88f +timeCreated: 1737803701 \ No newline at end of file diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs new file mode 100644 index 0000000..a51d963 --- /dev/null +++ b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Tools.ExcelResolver.Editor +{ + internal class TDict : TType + { + internal override Type RealType => typeof(Dictionary<,>).MakeGenericType(KeyType?.RealType ?? typeof(object), ValueType?.RealType ?? typeof(object)); + internal override string FieldWriteFormat => $"Dictionary<{KeyType?.RealType.Name ?? "object"}, {ValueType?.RealType.Name ?? "object"}>"; + internal override object DefaultValue => Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(KeyType?.RealType ?? typeof(object), ValueType?.RealType ?? typeof(object))); + + // 键和值的类型 + internal TType KeyType { get; set; } + internal TType ValueType { get; set; } + + internal override bool String2TType(string typeText) + { + var split = typeText.Split(',', StringSplitOptions.RemoveEmptyEntries); + if (split.Length != 3 || !string.Equals(split[0], "dict", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + // 解析键和值的类型 + KeyType = ExcelResolverUtil.GetTTypeByString(split[1]); + ValueType = ExcelResolverUtil.GetTTypeByString(split[2]); + + return KeyType != null && ValueType != null; + } + + internal override object TryParseFrom(string cellText) + { + if (KeyType == null || ValueType == null) + { + return null; // 如果未指定键和值类型,无法解析 + } + + var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(KeyType.RealType, ValueType.RealType)); + var entries = cellText.Split('|'); // 假定每个键值对用 "|" 分隔 + + foreach (var entry in entries) + { + var keyValue = entry.Split(':'); // 假定键和值用 ":" 分隔 + if (keyValue.Length != 2) + { + return null; // 任意键值对格式不正确时,返回 null + } + + var key = KeyType.TryParseFrom(keyValue[0]); + var value = ValueType.TryParseFrom(keyValue[1]); + + if (key != null && value != null) + { + dict.Add(key, value); + } + else + { + return null; // 键或值解析失败时,返回 null + } + } + + return dict; + } + } +} diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs.meta b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs.meta new file mode 100644 index 0000000..81bb979 --- /dev/null +++ b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Types/TDict.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ee795236344b4595bafcdb6222b93798 +timeCreated: 1737802386 \ No newline at end of file diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs index fca0594..1a5048d 100644 --- a/Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs +++ b/Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs @@ -64,7 +64,11 @@ namespace Tools.ExcelResolver.Editor return result; } - throw new Exception($"单元格转换失败 className: '{className}' FullAddress: {cell.FullAddress} Text: '{cell.Text}'"); + throw new Exception($"单元格转换失败 " + + $"className: '{className}' " + + $"FullAddress: {cell.FullAddress} " + + $"Type: '{type.FieldWriteFormat}' " + + $"Text: '{cell.Text}' "); } /// diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs index b01df57..3d867e1 100644 --- a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs +++ b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteDataCode.cs @@ -3,7 +3,9 @@ using System.CodeDom.Compiler; using System.IO; using Microsoft.CSharp; -/* 使用CodeCompileUnit需要将Edit->Project Settings->Player->Other Settings->Api Compatibility Level改为.NET 4.x(或.NET Framework) */ +/* 使用CodeCompileUnit需要将Edit->Project Settings->Player->Other Settings->Api Compatibility Level改为.NET 4.x(或.NET Framework) + 更正:如果使用了程序集才需要如上设置,否则不需要 + */ namespace Tools.ExcelResolver.Editor @@ -30,6 +32,7 @@ namespace Tools.ExcelResolver.Editor "System.Collections", "System.Collections.Generic", "UnityEngine", + "Sirenix.OdinInspector", }; foreach (var import in classImports) { @@ -50,8 +53,8 @@ namespace Tools.ExcelResolver.Editor // }, BaseTypes = { - new CodeTypeReference("ScriptableObject"), - new CodeTypeReference("IExcelData") + new CodeTypeReference("SerializedScriptableObject"), + new CodeTypeReference("IExcelSOData") } }; codeNamespace.Types.Add(classType); diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteUtilCode.cs b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteUtilCode.cs index a0484be..400bf77 100644 --- a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteUtilCode.cs +++ b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteUtilCode.cs @@ -48,7 +48,7 @@ namespace Tools.ExcelResolver.Editor BaseTypes = { new CodeTypeReference("SerializedScriptableObject"), - new CodeTypeReference("IExcelSO"), + new CodeTypeReference("IExcelSOUtil"), } }; codeNamespace.Types.Add(classType); diff --git a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.cs b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.cs index dc9823d..aaee4e7 100644 --- a/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.cs +++ b/Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.cs @@ -12,6 +12,10 @@ namespace Tools.ExcelResolver.Editor { [SerializeField] private ExcelResolverEditorConfig excelResolverConfig; + [FoldoutGroup("Hide Setting"), LabelText("导表前是否清空Console")] + [SerializeField] private bool isClearConsole = true; + + [MenuItem("\u272dExcelResolver\u272d/ExcelResolverEditorWindow")] private static void OpenWindow() { @@ -59,7 +63,14 @@ namespace Tools.ExcelResolver.Editor [Button("导表", ButtonSizes.Gigantic)] - private void StartExportExcel() => ReadExcel(); + private void StartExportExcel() + { + if (isClearConsole) + { + UnityEditorUtil.ClearConsole(); + } + ReadExcel(); + } // [ButtonGroup("Generate")] // private void GenerateSO() => WriteSOData(); diff --git a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelData.cs b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOData.cs similarity index 61% rename from Assets/Unity-Tools/ExcelResolver/Interface/IExcelData.cs rename to Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOData.cs index 710d3e6..4b01010 100644 --- a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelData.cs +++ b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOData.cs @@ -1,6 +1,6 @@ namespace Tools.ExcelResolver { - public interface IExcelData + public interface IExcelSOData { } diff --git a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelData.cs.meta b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOData.cs.meta similarity index 100% rename from Assets/Unity-Tools/ExcelResolver/Interface/IExcelData.cs.meta rename to Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOData.cs.meta diff --git a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSO.cs b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOUtil.cs similarity index 61% rename from Assets/Unity-Tools/ExcelResolver/Interface/IExcelSO.cs rename to Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOUtil.cs index 06a154d..2da6b0e 100644 --- a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSO.cs +++ b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOUtil.cs @@ -1,6 +1,6 @@ namespace Tools.ExcelResolver { - public interface IExcelSO + public interface IExcelSOUtil { } diff --git a/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSO.cs.meta b/Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOUtil.cs.meta similarity index 100% rename from Assets/Unity-Tools/ExcelResolver/Interface/IExcelSO.cs.meta rename to Assets/Unity-Tools/ExcelResolver/Interface/IExcelSOUtil.cs.meta diff --git a/Assets/_Project/ExcelResolver/Excel/hero.xlsx b/Assets/_Project/ExcelResolver/Excel/hero.xlsx index 6c281b5..f92c961 100644 Binary files a/Assets/_Project/ExcelResolver/Excel/hero.xlsx and b/Assets/_Project/ExcelResolver/Excel/hero.xlsx differ diff --git a/Assets/_Project/ScriptableObject/Excel/Hero_1.asset b/Assets/_Project/ScriptableObject/Excel/Hero_1.asset index 8f7199f..ec603a5 100644 --- a/Assets/_Project/ScriptableObject/Excel/Hero_1.asset +++ b/Assets/_Project/ScriptableObject/Excel/Hero_1.asset @@ -12,6 +12,59 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e8aa3c1560079b84cafbabe4bc0d2c8d, type: 3} m_Name: Hero_1 m_EditorClassIdentifier: + serializationData: + SerializedFormat: 2 + SerializedBytes: + ReferencedUnityObjects: [] + SerializedBytesString: + Prefab: {fileID: 0} + PrefabModificationsReferencedUnityObjects: [] + PrefabModifications: [] + SerializationNodes: + - Name: attribute + Entry: 7 + Data: 0|System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.Int32, + mscorlib]], mscorlib + - Name: comparer + Entry: 7 + Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.Int32, + mscorlib]], mscorlib + - Name: + Entry: 8 + Data: + - Name: + Entry: 12 + Data: 2 + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 3 + Data: 1 + - Name: $v + Entry: 3 + Data: 500 + - Name: + Entry: 8 + Data: + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 3 + Data: 2 + - Name: $v + Entry: 3 + Data: 300 + - Name: + Entry: 8 + Data: + - Name: + Entry: 13 + Data: + - Name: + Entry: 8 + Data: id: 1 name: "\u9053\u58EB" icon: hero_1 @@ -22,7 +75,7 @@ MonoBehaviour: pos: {x: 0, y: 1, z: 4} ches: {x: 0, y: 1} attack_target: - - 0.5 - - -2.6 - - 3 - - 4.5 + - {x: 1, y: 2} + - {x: 1, y: 2} + - {x: 1, y: 2} + - {x: 1, y: 2} diff --git a/Assets/_Project/ScriptableObject/Excel/Hero_2.asset b/Assets/_Project/ScriptableObject/Excel/Hero_2.asset index 99e9164..cfa159d 100644 --- a/Assets/_Project/ScriptableObject/Excel/Hero_2.asset +++ b/Assets/_Project/ScriptableObject/Excel/Hero_2.asset @@ -12,6 +12,35 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e8aa3c1560079b84cafbabe4bc0d2c8d, type: 3} m_Name: Hero_2 m_EditorClassIdentifier: + serializationData: + SerializedFormat: 2 + SerializedBytes: + ReferencedUnityObjects: [] + SerializedBytesString: + Prefab: {fileID: 0} + PrefabModificationsReferencedUnityObjects: [] + PrefabModifications: [] + SerializationNodes: + - Name: attribute + Entry: 7 + Data: 0|System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.Int32, + mscorlib]], mscorlib + - Name: comparer + Entry: 7 + Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.Int32, + mscorlib]], mscorlib + - Name: + Entry: 8 + Data: + - Name: + Entry: 12 + Data: 0 + - Name: + Entry: 13 + Data: + - Name: + Entry: 8 + Data: id: 2 name: icon: hero_2 diff --git a/Assets/_Project/ScriptableObject/Excel/Hero_3.asset b/Assets/_Project/ScriptableObject/Excel/Hero_3.asset index b74aae5..c5aa403 100644 --- a/Assets/_Project/ScriptableObject/Excel/Hero_3.asset +++ b/Assets/_Project/ScriptableObject/Excel/Hero_3.asset @@ -12,6 +12,47 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e8aa3c1560079b84cafbabe4bc0d2c8d, type: 3} m_Name: Hero_3 m_EditorClassIdentifier: + serializationData: + SerializedFormat: 2 + SerializedBytes: + ReferencedUnityObjects: [] + SerializedBytesString: + Prefab: {fileID: 0} + PrefabModificationsReferencedUnityObjects: [] + PrefabModifications: [] + SerializationNodes: + - Name: attribute + Entry: 7 + Data: 0|System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.Int32, + mscorlib]], mscorlib + - Name: comparer + Entry: 7 + Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.Int32, + mscorlib]], mscorlib + - Name: + Entry: 8 + Data: + - Name: + Entry: 12 + Data: 1 + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 3 + Data: 2 + - Name: $v + Entry: 3 + Data: 200 + - Name: + Entry: 8 + Data: + - Name: + Entry: 13 + Data: + - Name: + Entry: 8 + Data: id: 2 name: "\u5973\u5DEB" icon: hero_3 @@ -22,4 +63,4 @@ MonoBehaviour: pos: {x: 3, y: 2, z: 4} ches: {x: 5, y: 12} attack_target: - - 2.5 + - {x: 1, y: 2} diff --git a/Assets/_Project/Scripts/Generator/Excel/Hero.cs b/Assets/_Project/Scripts/Generator/Excel/Hero.cs index 55fead2..cd66223 100644 --- a/Assets/_Project/Scripts/Generator/Excel/Hero.cs +++ b/Assets/_Project/Scripts/Generator/Excel/Hero.cs @@ -14,9 +14,10 @@ namespace Tools.ExcelResolver using System.Collections; using System.Collections.Generic; using UnityEngine; + using Sirenix.OdinInspector; - public class Hero : ScriptableObject, IExcelData + public class Hero : SerializedScriptableObject, IExcelSOData { /// @@ -67,6 +68,11 @@ namespace Tools.ExcelResolver /// /// 攻击优先级 /// - public List attack_target; + public List attack_target; + + /// + /// + /// + public Dictionary attribute; } } diff --git a/Assets/_Project/Scripts/Generator/Excel/HeroUtil.cs b/Assets/_Project/Scripts/Generator/Excel/HeroUtil.cs index 052db47..c4f85c7 100644 --- a/Assets/_Project/Scripts/Generator/Excel/HeroUtil.cs +++ b/Assets/_Project/Scripts/Generator/Excel/HeroUtil.cs @@ -17,7 +17,7 @@ namespace Tools.ExcelResolver using Sirenix.OdinInspector; - public class HeroUtil : SerializedScriptableObject, IExcelSO + public class HeroUtil : SerializedScriptableObject, IExcelSOUtil { public Dictionary Data;