From 89b1b7ef3b38a0b64dd1c62e8c48a02e2294e696 Mon Sep 17 00:00:00 2001 From: coffee <985942825@qq.com> Date: Sun, 5 Jan 2025 23:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=88=9B=E5=BB=BASO=E5=B9=B6?= =?UTF-8?q?=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ExcelResolver/Excel/hero.xlsx | Bin 10961 -> 10662 bytes Assets/ScriptableObject.meta | 8 +++ Assets/ScriptableObject/Generator.meta | 8 +++ Assets/ScriptableObject/Generator/Excel.meta | 8 +++ .../Generator/Excel/Hero_1.asset | 20 +++++++ .../Generator/Excel/Hero_1.asset.meta | 8 +++ .../Generator/Excel/Hero_2.asset | 20 +++++++ .../Generator/Excel/Hero_2.asset.meta | 8 +++ Assets/Scripts/Generator/Excel/Hero.cs | 52 ++++++++++++++++++ Assets/Scripts/Generator/Excel/Hero.cs.meta | 2 + Assets/Scripts/Generator/Excel/HeroUtil.cs | 25 +++++++++ .../Scripts/Generator/Excel/HeroUtil.cs.meta | 2 + .../ExcelResolverEditorWindow.WriteSOData.cs | 14 ++++- 13 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 Assets/ScriptableObject.meta create mode 100644 Assets/ScriptableObject/Generator.meta create mode 100644 Assets/ScriptableObject/Generator/Excel.meta create mode 100644 Assets/ScriptableObject/Generator/Excel/Hero_1.asset create mode 100644 Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta create mode 100644 Assets/ScriptableObject/Generator/Excel/Hero_2.asset create mode 100644 Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta create mode 100644 Assets/Scripts/Generator/Excel/Hero.cs create mode 100644 Assets/Scripts/Generator/Excel/Hero.cs.meta create mode 100644 Assets/Scripts/Generator/Excel/HeroUtil.cs create mode 100644 Assets/Scripts/Generator/Excel/HeroUtil.cs.meta diff --git a/Assets/Exc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ra{tu&djCu7hjnybbp~*yZuI6pUt*)V?}U!!lQl1m}qZc$4b9XL>#N2!WH39^e23o!NHMn3Li!4TPQ^pLvG2_<}kU7x$9`%geil{WGFa9 z95O_uFNCtb)H44Xv$X$(*Oj5%rQ(YmrAS4OmEM zyJaiy0uV`Ty9lk=2`1F21gt|v(^!^cJCr=>z|A?RUp0J>6WMpYK2D#7Bhig*g3O-LEneB`M%ly(x; zw#m9BVbc`7RErZT)HoNJd`cQkGa|HjD`r?LcnE=DSxs%YOSo8yMPn|zOKs6uWVx`O z*UyaqWB#kR%x;>5wwO9`@@h0a+EZ!%=AamysC4paciMlg(toqVao!*2`$wu!493&l zW0mIpAI0Hu@#4ECd>P~?T6;eHSPVz`*LV5;NK2e+zfKQ|)1j)FW(eB*Ga3Gr)_G;| zVQ*0~#UfJsZg38Q+qb#_#P@)+Sbpg9J9`^Ft9E1FRU^~qZ}ZRJR2o6X9yuyqN0wuu z4GlY%v(Z>b)jMTNUYhJ!b%Yu<%R!C0JWA58OuJT1o^?ylpS^s)XhXN843%x@T5ic+ zEC1YUw$Yz{TmJw2-%v{f1d~fB8na{+!w>?5B$Fv6KLXw%lWHY00s+&0#PHAG$$+^8CYxc4*~!HJ_P^(6aWAK00000 z0RSKX001x(lYA#Y0)Q8jz9%^W;FI_#HUb9?lQ1Yh0&x|SaVR?hn3Jt2AsjW>7^wyX z0003F000;O0000000031AOHXW!~~NtDHW6dC@%s436n4>L;~;%lQ1b2lZz=81}G)~ G0000+{t^xV diff --git a/Assets/ScriptableObject.meta b/Assets/ScriptableObject.meta new file mode 100644 index 0000000..16b4a99 --- /dev/null +++ b/Assets/ScriptableObject.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8c2556b969d8e2e4881be5e4e996dfcc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObject/Generator.meta b/Assets/ScriptableObject/Generator.meta new file mode 100644 index 0000000..c965f3e --- /dev/null +++ b/Assets/ScriptableObject/Generator.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0640585ce4cc1ab43ad546d3258130dc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObject/Generator/Excel.meta b/Assets/ScriptableObject/Generator/Excel.meta new file mode 100644 index 0000000..f11a703 --- /dev/null +++ b/Assets/ScriptableObject/Generator/Excel.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e67c6d5e54b9de94ab4e5d1865feb935 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_1.asset b/Assets/ScriptableObject/Generator/Excel/Hero_1.asset new file mode 100644 index 0000000..098a652 --- /dev/null +++ b/Assets/ScriptableObject/Generator/Excel/Hero_1.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 31296c0321326704c8614b265011bd90, type: 3} + m_Name: Hero_1 + m_EditorClassIdentifier: + id: 1 + name: "\u9053\u58EB" + icon: hero_1 + hp: 100 + atk: 20 + speed: 1.2 diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta b/Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta new file mode 100644 index 0000000..61bce23 --- /dev/null +++ b/Assets/ScriptableObject/Generator/Excel/Hero_1.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5d9d9d9b6a4a85b468a248932c5ffc68 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_2.asset b/Assets/ScriptableObject/Generator/Excel/Hero_2.asset new file mode 100644 index 0000000..b2f797e --- /dev/null +++ b/Assets/ScriptableObject/Generator/Excel/Hero_2.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 31296c0321326704c8614b265011bd90, type: 3} + m_Name: Hero_2 + m_EditorClassIdentifier: + id: 2 + name: "\u6218\u58EB" + icon: hero_2 + hp: 150 + atk: 15 + speed: 1 diff --git a/Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta b/Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta new file mode 100644 index 0000000..878b668 --- /dev/null +++ b/Assets/ScriptableObject/Generator/Excel/Hero_2.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 20719aba661cd244f9d4e3b1f45a3e14 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Generator/Excel/Hero.cs b/Assets/Scripts/Generator/Excel/Hero.cs new file mode 100644 index 0000000..68695bf --- /dev/null +++ b/Assets/Scripts/Generator/Excel/Hero.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tools.ExcelResolver +{ + using System; + using System.Collections; + using System.Collections.Generic; + using UnityEngine; + + + public class Hero : ScriptableObject, IExcelData + { + + /// + /// 英雄 + /// + public int id; + + /// + /// 名称 + /// + public string name; + + /// + /// icon + /// + public string icon; + + /// + /// 血量 + /// + public int hp; + + /// + /// 攻击力 + /// + public int atk; + + /// + /// 移速 + /// + public float speed; + } +} diff --git a/Assets/Scripts/Generator/Excel/Hero.cs.meta b/Assets/Scripts/Generator/Excel/Hero.cs.meta new file mode 100644 index 0000000..3705732 --- /dev/null +++ b/Assets/Scripts/Generator/Excel/Hero.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 31296c0321326704c8614b265011bd90 \ No newline at end of file diff --git a/Assets/Scripts/Generator/Excel/HeroUtil.cs b/Assets/Scripts/Generator/Excel/HeroUtil.cs new file mode 100644 index 0000000..052db47 --- /dev/null +++ b/Assets/Scripts/Generator/Excel/HeroUtil.cs @@ -0,0 +1,25 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tools.ExcelResolver +{ + using System; + using System.Collections; + using System.Collections.Generic; + using UnityEngine; + using Sirenix.OdinInspector; + + + public class HeroUtil : SerializedScriptableObject, IExcelSO + { + + public Dictionary Data; + } +} diff --git a/Assets/Scripts/Generator/Excel/HeroUtil.cs.meta b/Assets/Scripts/Generator/Excel/HeroUtil.cs.meta new file mode 100644 index 0000000..4c6cc39 --- /dev/null +++ b/Assets/Scripts/Generator/Excel/HeroUtil.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f75077205d2ee5349b19af6333dc2e66 \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs index d84db69..e2c4252 100644 --- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs +++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorWindow.WriteSOData.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using OfficeOpenXml; +using UnityEditor; using UnityEngine; namespace Tools.ExcelResolver.Editor @@ -12,6 +14,11 @@ namespace Tools.ExcelResolver.Editor private void WriteSOData() { + if (classCodeDataDict == null) + { + ReadExcel(); + } + foreach (var data in classCodeDataDict) { var worksheet = data.Key; @@ -46,14 +53,19 @@ namespace Tools.ExcelResolver.Editor ScriptableObject instance = ScriptableObject.CreateInstance(soType); - for (int col = 2; col < classCodeData.fields.Keys.Max(); col++) + for (int col = 2; col <= classCodeData.fields.Keys.Max(); col++) { var cell = worksheet.Cells[row, col]; if (string.IsNullOrEmpty(cell.Text)) continue; object convertedValue = ExcelResolverUtil.ConvertCellValue(cell, classCodeData.fields[col].type, classCodeData.className); + FieldInfo fieldInfo = soType.GetField(classCodeData.fields[col].varName); + if (fieldInfo == null) throw new Exception($"目标类中不存在字段:{classCodeData.fields[col].varName}"); + fieldInfo.SetValue(instance, convertedValue); } + AssetDatabase.CreateAsset(instance, $"{excelResolverConfig.SOPathRoot}/{classCodeData.className}_{row - 6}.asset"); } + AssetDatabase.SaveAssets(); } } }