From a5f0c395f0676f61e40823d4f88e4bc44101e76a Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:08:18 +0800 Subject: [PATCH 1/9] [+] Books [+] Books --- Books/0-RunAble.md | 9 +++++++++ {ReadmeSrc => Books/src}/Editor-RunSuccessed.png | Bin 2 files changed, 9 insertions(+) create mode 100644 Books/0-RunAble.md rename {ReadmeSrc => Books/src}/Editor-RunSuccessed.png (100%) diff --git a/Books/0-RunAble.md b/Books/0-RunAble.md new file mode 100644 index 00000000..8a084ebc --- /dev/null +++ b/Books/0-RunAble.md @@ -0,0 +1,9 @@ +# TEngine + +### 日志记录编辑器下运行 +![image](src/Editor-RunSuccessed.png) + +### TODO - 安卓环境运行 + + +### TODO - IOS环境运行 \ No newline at end of file diff --git a/ReadmeSrc/Editor-RunSuccessed.png b/Books/src/Editor-RunSuccessed.png similarity index 100% rename from ReadmeSrc/Editor-RunSuccessed.png rename to Books/src/Editor-RunSuccessed.png From ac25925406e616f913ff5d1cbdff722f007ec6bf Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:12:57 +0800 Subject: [PATCH 2/9] [+] Extension [+] Extension --- .../Extension/OdinInspectorExtension.cs | 134 ++++++++++++++++++ .../Extension/OdinInspectorExtension.cs.meta | 11 ++ .../Runtime/Extension/TransformExtension.cs | 34 +++++ .../Extension/TransformExtension.cs.meta | 11 ++ 4 files changed, 190 insertions(+) create mode 100644 Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs create mode 100644 Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs.meta create mode 100644 Assets/TEngine/Runtime/Extension/TransformExtension.cs create mode 100644 Assets/TEngine/Runtime/Extension/TransformExtension.cs.meta diff --git a/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs b/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs new file mode 100644 index 00000000..91e258cc --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs @@ -0,0 +1,134 @@ +using System; +using System.Diagnostics; +using UnityEngine; + +#if !ODIN_INSPECTOR +namespace Sirenix.OdinInspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [Conditional("UNITY_EDITOR")] + public class ButtonAttribute : Attribute + { + public ButtonAttribute() + { + } + + public ButtonAttribute(string name) + { + } + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] + [Conditional("UNITY_EDITOR")] + public sealed class ReadOnlyAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] + [Conditional("UNITY_EDITOR")] + public class ShowInInspectorAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)] + [Conditional("UNITY_EDITOR")] + public sealed class HideIfAttribute : Attribute + { + public string MemberName; + public object Value; + public bool Animate; + + public HideIfAttribute(string memberName, bool animate = true) + { + this.MemberName = memberName; + this.Animate = animate; + } + } + + [DontApplyToListElements] + [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)] + [Conditional("UNITY_EDITOR")] + public sealed class OnValueChangedAttribute : Attribute + { + public string MethodName; + + public bool IncludeChildren; + + public OnValueChangedAttribute(string methodName, bool includeChildren = false) + { + this.MethodName = methodName; + this.IncludeChildren = includeChildren; + } + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] + [Conditional("UNITY_EDITOR")] + public class TableListAttribute : Attribute + { + public int DefaultMinColumnWidth = 40; + public bool DrawScrollView = true; + + public int MinScrollViewHeight = 350; + + public int CellPadding = 2; + + public int NumberOfItemsPerPage; + + public bool IsReadOnly; + + public bool ShowIndexLabels; + + public int MaxScrollViewHeight; + + public bool AlwaysExpanded; + + public bool HideToolbar; + + [SerializeField] [HideInInspector] private bool showPagingHasValue; + } + + [AttributeUsage(AttributeTargets.Class)] + public sealed class DontApplyToListElementsAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] + [DontApplyToListElements] + [Conditional("UNITY_EDITOR")] + public class PropertySpaceAttribute : Attribute + { + public float SpaceBefore; + public float SpaceAfter; + + public PropertySpaceAttribute() + { + this.SpaceBefore = 8f; + this.SpaceAfter = 0.0f; + } + + public PropertySpaceAttribute(float spaceBefore) + { + this.SpaceBefore = spaceBefore; + this.SpaceAfter = 0.0f; + } + + public PropertySpaceAttribute(float spaceBefore, float spaceAfter) + { + this.SpaceBefore = spaceBefore; + this.SpaceAfter = spaceAfter; + } + } + + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] + [Conditional("UNITY_EDITOR")] + public class LabelTextAttribute : Attribute + { + public string Text; + + public LabelTextAttribute(string text) + { + this.Text = text; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs.meta b/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs.meta new file mode 100644 index 00000000..44752873 --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/OdinInspectorExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b7dfd2b954f77047a61bf4c505f8cc1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Extension/TransformExtension.cs b/Assets/TEngine/Runtime/Extension/TransformExtension.cs new file mode 100644 index 00000000..9ee68723 --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/TransformExtension.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace TEngine +{ + public static partial class TransformExtension + { + public static float YDeg(this Transform tran) + { + return tran.eulerAngles.y; + } + + public static void RemoveAllChildren(this Transform tran) + { + var count = tran.childCount; + for (int i = 0; i < count; i++) + { + GameObject.DestroyImmediate(tran.GetChild(0).gameObject); + } + } + + public static List GetAllChildren(this Transform tran) + { + var count = tran.childCount; + List allTrans = new List(); + for (int i = 0; i < count; i++) + { + allTrans.Add(tran.GetChild(i)); + } + + return allTrans; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Extension/TransformExtension.cs.meta b/Assets/TEngine/Runtime/Extension/TransformExtension.cs.meta new file mode 100644 index 00000000..72c0d7fb --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/TransformExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59821d6add0226e40a841e85a2cba8ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 8f972f93408cf877fe31eb61eb00344ca15b629a Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:14:17 +0800 Subject: [PATCH 3/9] Update Extension --- Assets/TEngine/Runtime/{Utility => Extension}/BinaryExtension.cs | 0 .../Runtime/{Utility => Extension}/BinaryExtension.cs.meta | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Assets/TEngine/Runtime/{Utility => Extension}/BinaryExtension.cs (100%) rename Assets/TEngine/Runtime/{Utility => Extension}/BinaryExtension.cs.meta (100%) diff --git a/Assets/TEngine/Runtime/Utility/BinaryExtension.cs b/Assets/TEngine/Runtime/Extension/BinaryExtension.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/BinaryExtension.cs rename to Assets/TEngine/Runtime/Extension/BinaryExtension.cs diff --git a/Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta b/Assets/TEngine/Runtime/Extension/BinaryExtension.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta rename to Assets/TEngine/Runtime/Extension/BinaryExtension.cs.meta From 688b76b745cdcdde10b2eb0d7f4eb4f3343cc1da Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:16:40 +0800 Subject: [PATCH 4/9] [+] Extension [+] Extension --- Assets/TEngine/Runtime/{Utility => Extension}/StringExtension.cs | 0 .../Runtime/{Utility => Extension}/StringExtension.cs.meta | 0 Assets/TEngine/Runtime/{Utility => Extension}/UnityExtension.cs | 0 .../TEngine/Runtime/{Utility => Extension}/UnityExtension.cs.meta | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Assets/TEngine/Runtime/{Utility => Extension}/StringExtension.cs (100%) rename Assets/TEngine/Runtime/{Utility => Extension}/StringExtension.cs.meta (100%) rename Assets/TEngine/Runtime/{Utility => Extension}/UnityExtension.cs (100%) rename Assets/TEngine/Runtime/{Utility => Extension}/UnityExtension.cs.meta (100%) diff --git a/Assets/TEngine/Runtime/Utility/StringExtension.cs b/Assets/TEngine/Runtime/Extension/StringExtension.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/StringExtension.cs rename to Assets/TEngine/Runtime/Extension/StringExtension.cs diff --git a/Assets/TEngine/Runtime/Utility/StringExtension.cs.meta b/Assets/TEngine/Runtime/Extension/StringExtension.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/StringExtension.cs.meta rename to Assets/TEngine/Runtime/Extension/StringExtension.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/UnityExtension.cs b/Assets/TEngine/Runtime/Extension/UnityExtension.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/UnityExtension.cs rename to Assets/TEngine/Runtime/Extension/UnityExtension.cs diff --git a/Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta b/Assets/TEngine/Runtime/Extension/UnityExtension.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta rename to Assets/TEngine/Runtime/Extension/UnityExtension.cs.meta From e0b42d3dbe1dae40366459eb49b3213d4faa2bf5 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:16:55 +0800 Subject: [PATCH 5/9] [+] Utility.Bit [+] Utility.Bit --- .../GameFramework/Utility/Utility.Bit.cs | 61 +++++++++++++++++++ .../GameFramework/Utility/Utility.Bit.cs.meta | 3 + 2 files changed, 64 insertions(+) create mode 100644 Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs create mode 100644 Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs new file mode 100644 index 00000000..9f3d795b --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs @@ -0,0 +1,61 @@ +namespace TEngine +{ + public static partial class Utility + { + /// + /// 位运算相关的实用函数。 + /// + public static class Bit + { + public static bool HasBit(long val, int idx) + { + return (val & 1L << idx) != 0L; + } + + public static void SetBit(ref long val, int idx, bool isSet) + { + if (isSet) + { + val |= (1L << idx); + } + else + { + val &= ~(1L << idx); + } + } + + public static bool HasBit(int val, int idx) + { + return (val & 1 << idx) != 0; + } + + + public static void SetBit(ref int val, int idx, bool isSet) + { + if (isSet) + { + val |= (1 << idx); + } + else + { + val &= ~(1 << idx); + } + } + + public static bool HasBit(byte val, byte idx) + { + return (val & 1 << idx) != 0; + } + + public static void SetBit(ref byte val, byte idx) + { + val |= (byte)(1 << idx); + } + + public static byte ToByte(byte idx) + { + return (byte)(1 << idx); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta new file mode 100644 index 00000000..8a0d12a1 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 95d9fac2a8ff467e864aab4cd2650dfc +timeCreated: 1682352897 \ No newline at end of file From 08c2ff4dccda7d855aed4c02ebc69fda6aea5554 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:23:42 +0800 Subject: [PATCH 6/9] [+] BattleCore [+] BattleCore --- .../BattleCore/BattleCore.Runtime.asmdef | 3 ++- .../HotFix/BattleCore/ECSExtension.meta | 3 +++ .../ECSExtension/EntityExtension.cs | 6 +++++ .../ECSExtension/EntityExtension.cs.meta | 11 ++++++++ .../ECSExtension/MathematicsExtension.cs | 27 +++++++++++++++++++ .../ECSExtension/MathematicsExtension.cs.meta | 3 +++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Assets/GameScripts/HotFix/BattleCore/ECSExtension.meta create mode 100644 Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs create mode 100644 Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs.meta create mode 100644 Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs create mode 100644 Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs.meta diff --git a/Assets/GameScripts/HotFix/BattleCore/BattleCore.Runtime.asmdef b/Assets/GameScripts/HotFix/BattleCore/BattleCore.Runtime.asmdef index b50305bd..bbd7f47c 100644 --- a/Assets/GameScripts/HotFix/BattleCore/BattleCore.Runtime.asmdef +++ b/Assets/GameScripts/HotFix/BattleCore/BattleCore.Runtime.asmdef @@ -2,7 +2,8 @@ "name": "BattleCore.Runtime", "rootNamespace": "BattleCore.Runtime", "references": [ - "GUID:aa06d4cc755c979489c256c1bcca1dfb" + "GUID:aa06d4cc755c979489c256c1bcca1dfb", + "GUID:d8b63aba1907145bea998dd612889d6b" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/GameScripts/HotFix/BattleCore/ECSExtension.meta b/Assets/GameScripts/HotFix/BattleCore/ECSExtension.meta new file mode 100644 index 00000000..bc0e1a56 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/ECSExtension.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 890abd3a957e406ab422fc468ba6c169 +timeCreated: 1682353243 \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs new file mode 100644 index 00000000..582c0d86 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs @@ -0,0 +1,6 @@ +namespace BattleCore.Runtime +{ + public static class EntityExtension + { + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs.meta b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs.meta new file mode 100644 index 00000000..7f82c3e7 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/EntityExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4ef2dfa5ceac99458eb1745131a9c83 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs new file mode 100644 index 00000000..2d9ce577 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs @@ -0,0 +1,27 @@ +using UnityEngine; +using Unity.Mathematics; + +namespace BattleCore.Runtime +{ + public static class MathematicsExt + { + public static int2 ToInt2(this Vector2Int vec) => new int2(vec.x, vec.y); + public static int3 ToInt3(this Vector3Int vec) => new int3(vec.x, vec.y, vec.z); + public static float2 ToFloat2(this Vector2 vec) => new float2(vec.x, vec.y); + public static float3 ToFloat3(this Vector3 vec) => new float3(vec.x, vec.y, vec.z); + + public static bool IsEquals(this int2 a, int2 b) => math.all(a == b); + public static bool IsEquals(this int3 a, int3 b) => math.all(a == b); + + + public static Vector2Int ToVec2(this int2 vec) => new Vector2Int(vec.x, vec.y); + public static Vector3Int ToVec3(this int2 vec) => new Vector3Int(vec.x, vec.y, 0); + public static Vector3Int ToVec3(this int3 vec) => new Vector3Int(vec.x, vec.y, vec.z); + public static Vector2 ToVec2(this float2 vec) => new Vector2(vec.x, vec.y); + public static Vector3 ToVec3(this float3 vec) => new Vector3(vec.x, vec.y, vec.z); + public static int ManhattanDist(this int2 vec) => vec.x + vec.y; + public static int ManhattanDist(this int3 vec) => vec.x + vec.y + vec.z; + public static float ManhattanDist(this float2 vec) => vec.x + vec.y; + public static float ManhattanDist(this float3 vec) => vec.x + vec.y + vec.z; + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs.meta b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs.meta new file mode 100644 index 00000000..727a2123 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/ECSExtension/MathematicsExtension.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2b0e288b918a41698571ec3d36059851 +timeCreated: 1682353251 \ No newline at end of file From a285a635b9458e14a2977d2b9b9379ca5f50052e Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:32:21 +0800 Subject: [PATCH 7/9] [+] EditorExtUtil [+] EditorExtUtil --- .../Runtime/Extension/EditorExtUtil.cs | 188 ++++++++++++++++++ .../Runtime/Extension/EditorExtUtil.cs.meta | 11 + 2 files changed, 199 insertions(+) create mode 100644 Assets/TEngine/Runtime/Extension/EditorExtUtil.cs create mode 100644 Assets/TEngine/Runtime/Extension/EditorExtUtil.cs.meta diff --git a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs new file mode 100644 index 00000000..4d5f5999 --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs @@ -0,0 +1,188 @@ +#if UNITY_EDITOR +using UnityEditor; +#endif +using System.Collections.Generic; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace TEngine +{ + public static class EditorExtUtil + { + public static void SavePrefabAsset(GameObject asset) + { +#if UNITY_EDITOR + PrefabUtility.SavePrefabAsset(asset); +#else +#endif + } + + public static void CreateAsset(Object asset, string path) + { +#if UNITY_EDITOR + AssetDatabase.CreateAsset(asset, path); +#else +#endif + } + + public static string AssetPathToGUID(string path) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.AssetPathToGUID(path); +#else + return ""; +#endif + } + + public static UnityEngine.Object GetPrefabParent(UnityEngine.Object obj) + { +#if UNITY_EDITOR + return UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(obj); +#else + return null; +#endif + } + + public static string GetAssetPath(GameObject obj) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.GetAssetPath(obj); +#else + return ""; +#endif + } + + public static string GetAssetPath(ScriptableObject obj) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.GetAssetPath(obj); +#else + return ""; +#endif + } + + public static string[] GetAssetBundleDependencies(string assetBundleName, bool recursive) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.GetAssetBundleDependencies(assetBundleName, recursive); +#else + return null; +#endif + } + + public static string GUIDToAssetPath(string guid) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.GUIDToAssetPath(guid); +#else + return null; +#endif + } + + public static T LoadAssetAtPath(string assetPath) where T : Object + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath); +#else + return null; +#endif + } + + public static string[] GetAssetPathsFromAssetBundle(string assetBundleName) + { +#if UNITY_EDITOR + return UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); +#else + return null; +#endif + } + + public static void ToggleScriptingDefineSymbols(string def, bool isOn) + { +#if UNITY_EDITOR + ToggleScriptingDefineSymbols(def, isOn, (int)BuildTargetGroup.Standalone); + ToggleScriptingDefineSymbols(def, isOn, (int)BuildTargetGroup.Android); +#endif + } + + static void ToggleScriptingDefineSymbols(string def, bool isOn, int type) + { +#if UNITY_EDITOR + var targetGroup = (BuildTargetGroup)type; + string ori = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); + List defineSymbols = new List(ori.Split(';')); + if (isOn) + { + if (!defineSymbols.Contains(def)) + { + defineSymbols.Add(def); + } + } + else + { + defineSymbols.Remove(def); + } + + PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", defineSymbols.ToArray())); +#endif + } + + + public static void SetDirty(ScriptableObject obj) + { +#if UNITY_EDITOR + UnityEditor.EditorUtility.SetDirty(obj); +#endif + } + + public static void ImportAsset(string path) + { +#if UNITY_EDITOR + UnityEditor.AssetDatabase.ImportAsset(path); +#endif + } + + public static void SaveTblConfig(ScriptableObject confg) + { +#if UNITY_EDITOR + EditorUtility.SetDirty(confg); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + var path = AssetDatabase.GetAssetPath(confg); + AssetDatabase.ImportAsset(path); + AssetDatabase.ImportAsset(path.Replace(".asset", ".csv")); + EditorWindow.focusedWindow?.ShowNotification(new GUIContent("Done")); +#endif + } + + + public static GameObject Instantiate( + GameObject original, + Vector3 position, + Quaternion rotation, + Transform parent) + { + if (original == null) return null; +#if UNITY_EDITOR + if (Application.isPlaying) + { + return Object.Instantiate(original, position, rotation, parent); + } + + var go = PrefabUtility.InstantiatePrefab(original, parent) as GameObject; + go.transform.position = position; + go.transform.rotation = rotation; + return go; +#else + return Object.Instantiate( original, position, rotation, parent); +#endif + } + + public static void StopGame() + { +#if UNITY_EDITOR + UnityEditor.EditorApplication.isPlaying = false; +#endif + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs.meta b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs.meta new file mode 100644 index 00000000..78253574 --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 99efa5e84d614e74e960fcedb001ee0a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 3f67b27e455392a15c7a8cf2d88a668c64481c72 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:33:32 +0800 Subject: [PATCH 8/9] [+] EditorExtUtil --- Assets/TEngine/Runtime/Extension/EditorExtUtil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs index 4d5f5999..f8bfe151 100644 --- a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs +++ b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs @@ -142,13 +142,13 @@ namespace TEngine #endif } - public static void SaveTblConfig(ScriptableObject confg) + public static void SaveTblConfig(ScriptableObject config) { #if UNITY_EDITOR - EditorUtility.SetDirty(confg); + EditorUtility.SetDirty(config); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); - var path = AssetDatabase.GetAssetPath(confg); + var path = AssetDatabase.GetAssetPath(config); AssetDatabase.ImportAsset(path); AssetDatabase.ImportAsset(path.Replace(".asset", ".csv")); EditorWindow.focusedWindow?.ShowNotification(new GUIContent("Done")); From ab532c73d7111d7383f1f38920f24ba093a32bbd Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 25 Apr 2023 00:42:32 +0800 Subject: [PATCH 9/9] Update EditorExtUtil.cs --- .../Runtime/Extension/EditorExtUtil.cs | 102 ++++++++++++++++-- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs index f8bfe151..4e500568 100644 --- a/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs +++ b/Assets/TEngine/Runtime/Extension/EditorExtUtil.cs @@ -7,8 +7,15 @@ using Object = UnityEngine.Object; namespace TEngine { + /// + /// 编辑器运行时工具。 + /// public static class EditorExtUtil { + /// + /// 游戏物体保存为预制体。 + /// + /// 游戏物体。 public static void SavePrefabAsset(GameObject asset) { #if UNITY_EDITOR @@ -17,6 +24,11 @@ namespace TEngine #endif } + /// + /// 创建资源。 + /// + /// 游戏物体。 + /// 资源路径。 public static void CreateAsset(Object asset, string path) { #if UNITY_EDITOR @@ -25,24 +37,39 @@ namespace TEngine #endif } + /// + /// 文件路径转化成guid。 + /// + /// 文件路径 + /// guid。 public static string AssetPathToGUID(string path) { #if UNITY_EDITOR return UnityEditor.AssetDatabase.AssetPathToGUID(path); #else - return ""; + return ""; #endif } + /// + /// 获取资源来源预制体。 + /// + /// 资源实例。 + /// 来源预制体。 public static UnityEngine.Object GetPrefabParent(UnityEngine.Object obj) { #if UNITY_EDITOR return UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(obj); #else - return null; + return null; #endif } + /// + /// 获取资源路径。 + /// + /// 资源。 + /// 路径。 public static string GetAssetPath(GameObject obj) { #if UNITY_EDITOR @@ -52,6 +79,11 @@ namespace TEngine #endif } + /// + /// 获取资源路径。 + /// + /// 资源。 + /// 路径。 public static string GetAssetPath(ScriptableObject obj) { #if UNITY_EDITOR @@ -61,6 +93,12 @@ namespace TEngine #endif } + /// + /// 获取AB包中的资源依赖。 + /// + /// The name of the AssetBundle for which dependencies are required. + /// If false, returns only AssetBundles which are direct dependencies of the input; if true, includes all indirect dependencies of the input. + /// returns the list of AssetBundles that it depends on. public static string[] GetAssetBundleDependencies(string assetBundleName, bool recursive) { #if UNITY_EDITOR @@ -70,6 +108,11 @@ namespace TEngine #endif } + /// + /// guid转化成文件路径。 + /// + /// guid。 + /// 文件路径。 public static string GUIDToAssetPath(string guid) { #if UNITY_EDITOR @@ -79,33 +122,55 @@ namespace TEngine #endif } + /// + /// 编辑器下加载资源。 + /// + /// 资源地址。 + /// 资源类型。 + /// 资源实例。 public static T LoadAssetAtPath(string assetPath) where T : Object { #if UNITY_EDITOR return UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath); #else - return null; + return null; #endif } + /// + /// 获取资源包名称里的资源列表。 + /// + /// 资源包名称。 public static string[] GetAssetPathsFromAssetBundle(string assetBundleName) { #if UNITY_EDITOR return UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); #else - return null; + return null; #endif } + /// + /// 开关宏定义。 + /// + /// 宏定义。 + /// 是否开启。 public static void ToggleScriptingDefineSymbols(string def, bool isOn) { #if UNITY_EDITOR ToggleScriptingDefineSymbols(def, isOn, (int)BuildTargetGroup.Standalone); ToggleScriptingDefineSymbols(def, isOn, (int)BuildTargetGroup.Android); + ToggleScriptingDefineSymbols(def, isOn, (int)BuildTargetGroup.iOS); #endif } - static void ToggleScriptingDefineSymbols(string def, bool isOn, int type) + /// + /// 开关宏定义。 + /// + /// 宏定义。 + /// 是否开启。 + /// BuildTargetGroup打包平台类型。 + public static void ToggleScriptingDefineSymbols(string def, bool isOn, int type) { #if UNITY_EDITOR var targetGroup = (BuildTargetGroup)type; @@ -128,13 +193,21 @@ namespace TEngine } - public static void SetDirty(ScriptableObject obj) + /// + /// 设置脏标记。 + /// + /// ScriptableObject。 + public static void SetDirty(this ScriptableObject obj) { #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(obj); #endif } + /// + /// 导入资源。 + /// + /// 资源定位地址。 public static void ImportAsset(string path) { #if UNITY_EDITOR @@ -142,7 +215,11 @@ namespace TEngine #endif } - public static void SaveTblConfig(ScriptableObject config) + /// + /// 把ScriptableObject保存为CSV表格。 + /// + /// ScriptableObject。 + public static void SaveTblConfig(this ScriptableObject config) { #if UNITY_EDITOR EditorUtility.SetDirty(config); @@ -156,6 +233,14 @@ namespace TEngine } + /// + /// 实例化游戏物体操作。 + /// + /// 来源游戏物体。 + /// 实例化的位置。 + /// 实例化的四元数。 + /// 实例化的父节点。 + /// 实例化游戏物体。 public static GameObject Instantiate( GameObject original, Vector3 position, @@ -178,6 +263,9 @@ namespace TEngine #endif } + /// + /// 停止运行游戏。 + /// public static void StopGame() { #if UNITY_EDITOR