From ce8052f8ce008528451bba31b40e27f80557cd17 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 15 May 2024 00:36:56 +0800 Subject: [PATCH 01/10] update template inspector --- src/Debug/Editor/SettingsEditor.cs | 6 +- src/Debug/Editor/SettingsPrefs.cs | 23 ++- .../Editor/EntityTemplateEditor.cs | 139 +++++++++++++----- .../Templates/ComponentTemplateBase.cs | 8 +- src/Icons/AutosetCascadeIcon.png | Bin 0 -> 1990 bytes ...x.png.meta => AutosetCascadeIcon.png.meta} | 30 ++-- src/Icons/AutosetIcon.png | Bin 0 -> 1706 bytes ...n_max@2x.png.meta => AutosetIcon.png.meta} | 34 +++-- .../{d_winbtn_win_close.png => CloseIcon.png} | Bin ..._win_close.png.meta => CloseIcon.png.meta} | 30 ++-- ...{d_P4_DeletedLocal.png => CloseIconOn.png} | Bin ...tedLocal.png.meta => CloseIconOn.png.meta} | 30 ++-- src/Icons/{d__Help.png => HelpIcon.png} | Bin .../{d__Help.png.meta => HelpIcon.png.meta} | 30 ++-- src/Icons/UnlinkIcon.png | Bin 0 -> 647 bytes ..._Unlinked.png.meta => UnlinkIcon.png.meta} | 30 ++-- src/Icons/d_Unlinked.png | Bin 728 -> 0 bytes src/Icons/d_winbtn_win_max@2x.png | Bin 227 -> 0 bytes src/Icons/d_winbtn_win_restore@2x.png | Bin 283 -> 0 bytes src/Internal/Editor/EcsGUI.cs | 1 + src/Internal/EscEditorConsts.cs | 1 + 21 files changed, 255 insertions(+), 107 deletions(-) create mode 100644 src/Icons/AutosetCascadeIcon.png rename src/Icons/{d_winbtn_win_restore@2x.png.meta => AutosetCascadeIcon.png.meta} (83%) create mode 100644 src/Icons/AutosetIcon.png rename src/Icons/{d_winbtn_win_max@2x.png.meta => AutosetIcon.png.meta} (81%) rename src/Icons/{d_winbtn_win_close.png => CloseIcon.png} (100%) rename src/Icons/{d_winbtn_win_close.png.meta => CloseIcon.png.meta} (83%) rename src/Icons/{d_P4_DeletedLocal.png => CloseIconOn.png} (100%) rename src/Icons/{d_P4_DeletedLocal.png.meta => CloseIconOn.png.meta} (83%) rename src/Icons/{d__Help.png => HelpIcon.png} (100%) rename src/Icons/{d__Help.png.meta => HelpIcon.png.meta} (83%) create mode 100644 src/Icons/UnlinkIcon.png rename src/Icons/{d_Unlinked.png.meta => UnlinkIcon.png.meta} (83%) delete mode 100644 src/Icons/d_Unlinked.png delete mode 100644 src/Icons/d_winbtn_win_max@2x.png delete mode 100644 src/Icons/d_winbtn_win_restore@2x.png diff --git a/src/Debug/Editor/SettingsEditor.cs b/src/Debug/Editor/SettingsEditor.cs index 377cfaf..b782fc2 100644 --- a/src/Debug/Editor/SettingsEditor.cs +++ b/src/Debug/Editor/SettingsEditor.cs @@ -1,4 +1,5 @@ #if UNITY_EDITOR +using System; using System.Collections.Generic; using System.Linq; using UnityEditor; @@ -29,7 +30,6 @@ namespace DCFApixels.DragonECS.Unity.Editors nameof(EcsConsts.DISABLE_DEBUG), nameof(EcsConsts.ENABLE_DUMMY_SPAN), nameof(EcsConsts.DISABLE_CATH_EXCEPTIONS), - "DEBUG", }; for (int i = 0; i < _defineSymbols.Count; i++) { @@ -74,11 +74,14 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Label(nameof(SettingsPrefs.IsShowRuntimeComponents), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); + settings.AutoColorMode = (AutoColorMode)EditorGUILayout.EnumPopup(nameof(SettingsPrefs.AutoColorMode), SettingsPrefs.instance.AutoColorMode); + if (EditorGUI.EndChangeCheck()) { SettingsPrefs.instance.IsShowHidden = settings.IsShowHidden; SettingsPrefs.instance.IsShowInterfaces = settings.IsShowInterfaces; SettingsPrefs.instance.IsShowRuntimeComponents = settings.IsShowRuntimeComponents; + SettingsPrefs.instance.AutoColorMode = settings.AutoColorMode; } GUILayout.EndVertical(); @@ -144,6 +147,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public bool IsShowHidden; public bool IsShowInterfaces; public bool IsShowRuntimeComponents; + public AutoColorMode AutoColorMode; } } } diff --git a/src/Debug/Editor/SettingsPrefs.cs b/src/Debug/Editor/SettingsPrefs.cs index 072e06b..22e81b6 100644 --- a/src/Debug/Editor/SettingsPrefs.cs +++ b/src/Debug/Editor/SettingsPrefs.cs @@ -4,8 +4,14 @@ using UnityEngine; namespace DCFApixels.DragonECS.Unity.Editors { - [FilePath(EcsConsts.FRAMEWORK_NAME + "/" + nameof(SettingsPrefs) + ".prefs", FilePathAttribute.Location.ProjectFolder)] - public class SettingsPrefs : ScriptableSingleton + internal enum AutoColorMode + { + Generic = 0, + Name = 1, + Rainbow = 2, + } + [FilePath(EcsConsts.AUTHOR + "/" + EcsConsts.FRAMEWORK_NAME + "/" + nameof(SettingsPrefs) + ".prefs", FilePathAttribute.Location.ProjectFolder)] + internal class SettingsPrefs : ScriptableSingleton { [SerializeField] private bool _isShowInterfaces = false; @@ -52,6 +58,19 @@ namespace DCFApixels.DragonECS.Unity.Editors Save(false); } } + + + [SerializeField] + private AutoColorMode _autoColorMode = AutoColorMode.Name; + public AutoColorMode AutoColorMode + { + get => _autoColorMode; + set + { + _autoColorMode = value; + Save(false); + } + } } } #endif \ No newline at end of file diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index 833b7fc..b30ec75 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -16,6 +16,12 @@ namespace DCFApixels.DragonECS.Unity.Editors private GenericMenu _genericMenu; private bool _isInit = false; + private static AutoColorMode AutoColorMode + { + get { return SettingsPrefs.instance.AutoColorMode; } + set { SettingsPrefs.instance.AutoColorMode = value; } + } + #region Init private void Init() { @@ -42,6 +48,11 @@ namespace DCFApixels.DragonECS.Unity.Editors var componentTemplateDummies = ComponentTemplateTypeCache.Dummies; foreach (var dummy in componentTemplateDummies) { + if (dummy.Type.GetCustomAttribute() == null) + { + Debug.LogWarning($"Type {dummy.Type.Name} does not have the [Serializable] attribute"); + continue; + } ITypeMeta meta = dummy is ITypeMeta metaOverride ? metaOverride : dummy.Type.ToMeta(); string name = meta.Name; string description = meta.Description.Text; @@ -112,7 +123,7 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Label("", GUILayout.Height(0), GUILayout.ExpandWidth(true)); for (int i = 0; i < componentsProp.arraySize; i++) { - DrawComponentData(componentsProp.GetArrayElementAtIndex(i), i); + DrawComponentData(componentsProp.GetArrayElementAtIndex(i), componentsProp.arraySize, i); } GUILayout.EndVertical(); } @@ -132,37 +143,85 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - private void DrawComponentData(SerializedProperty componentRefProp, int index) + private void DrawComponentData(SerializedProperty componentRefProp, int total, int index) { IComponentTemplate template = componentRefProp.managedReferenceValue as IComponentTemplate; if (template == null || componentRefProp.managedReferenceValue == null) { - DrawDamagedComponent(componentRefProp, index); + DrawDamagedComponent_Replaced(componentRefProp, index); + return; + } + + Type componentType; + SerializedProperty componentProperty = componentRefProp; + try + { + ComponentTemplateBase customTemplate = componentProperty.managedReferenceValue as ComponentTemplateBase; + if (customTemplate != null) + { + componentProperty = componentRefProp.FindPropertyRelative("component"); + componentType = customTemplate.GetType().GetField("component", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FieldType; + } + else + { + componentType = componentProperty.managedReferenceValue.GetType(); + } + + if (componentType == null || componentProperty == null) + { + throw new NullReferenceException(); + } + } + catch (Exception e) + { + Debug.LogException(e, serializedObject.targetObject); + DrawDamagedComponent(index, "Damaged component template."); return; } - Type componentType; - SerializedProperty componentProperty = componentRefProp; - ComponentTemplateBase customInitializer = componentProperty.managedReferenceValue as ComponentTemplateBase; - if (customInitializer != null) - { - componentProperty = componentRefProp.FindPropertyRelative("component"); - componentType = customInitializer.GetType().GetField("component", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FieldType; - } - else - { - componentType = componentProperty.managedReferenceValue.GetType(); ; - } + //сюда попадают уже валидные компоненты + ITypeMeta meta = template is ITypeMeta metaOverride ? metaOverride : template.Type.ToMeta(); string name = meta.Name; string description = meta.Description.Text; - Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); - //GUIContent label = new GUIContent(name); bool isEmpty = componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0; + var propsCounter = componentProperty.Copy(); + int lastDepth = propsCounter.depth; + bool next = propsCounter.Next(true) && lastDepth < propsCounter.depth; + int propCount = next ? -1 : 0; + while (next) + { + propCount++; + next = propsCounter.Next(false); + } float padding = EditorGUIUtility.standardVerticalSpacing; + + Color panelColor; + if (meta.IsCustomColor) + { + panelColor = meta.Color.ToUnityColor(); + } + else + { + switch (AutoColorMode) + { + case AutoColorMode.Name: + panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; + break; + case AutoColorMode.Rainbow: + Color hsv = Color.HSVToRGB(1f / (Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE)) * index, 1, 1); + panelColor = hsv.Desaturate(0.48f) / 1.18f; + break; + default: + panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); + break; + } + } + panelColor = panelColor.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + Color alphaPanelColor = panelColor; alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA; @@ -171,24 +230,27 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor)); - - #region Draw Component Block - bool isRemoveComponent = false; removeButtonRect.yMin = removeButtonRect.yMax; removeButtonRect.yMax += RemoveButtonRect.height; removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width; removeButtonRect.center += Vector2.up * padding * 2f; - if (EcsGUI.CloseButton(removeButtonRect)) - { - isRemoveComponent = true; - } + bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect); - if (isEmpty) + if (propCount <= 0) { GUIContent label = UnityEditorUtility.GetLabel(name); - GUILayout.Label(label); + EditorGUILayout.LabelField(name); + Rect emptyPos = GUILayoutUtility.GetLastRect(); + emptyPos.xMin += EditorGUIUtility.labelWidth; + if (isEmpty) + { + using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) + { + GUI.Label(emptyPos, "empty"); + } + } EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), label, componentRefProp); EditorGUI.EndProperty(); } @@ -226,19 +288,28 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorUtility.SetDirty(componentProperty.serializedObject.targetObject); } } - - private void DrawDamagedComponent(SerializedProperty componentRefProp, int index) + private void DrawDamagedComponent_Replaced(SerializedProperty componentRefProp, int index) { + DrawDamagedComponent(index, $"Damaged component template. If the problem occurred after renaming a component or initializer. use MovedFromAttrubute"); + } + private void DrawDamagedComponent(int index, string message) + { + Rect removeButtonRect = GUILayoutUtility.GetLastRect(); + GUILayout.BeginHorizontal(); - EditorGUILayout.HelpBox($"Damaged component. If the problem occurred after renaming a component or initializer. use MovedFromAttrubute", MessageType.Warning); + float padding = EditorGUIUtility.standardVerticalSpacing; - Rect lastrect = GUILayoutUtility.GetLastRect(); - Rect removeButtonRect = RemoveButtonRect; - removeButtonRect.center = new Vector2(lastrect.xMax + removeButtonRect.width, lastrect.yMin + removeButtonRect.height / 2f); + removeButtonRect.yMin = removeButtonRect.yMax; + removeButtonRect.yMax += RemoveButtonRect.height; + removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width; + removeButtonRect.center += Vector2.up * padding * 2f; - GUILayout.Label("", GUILayout.Width(removeButtonRect.width)); - if (GUI.Button(removeButtonRect, "x", _removeButtonStyle)) + bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect); + + EditorGUILayout.HelpBox(message, MessageType.Warning); + + if (isRemoveComponent) { OnRemoveComponentAt(index); } diff --git a/src/EntityTemplate/Templates/ComponentTemplateBase.cs b/src/EntityTemplate/Templates/ComponentTemplateBase.cs index df4f541..e8105d1 100644 --- a/src/EntityTemplate/Templates/ComponentTemplateBase.cs +++ b/src/EntityTemplate/Templates/ComponentTemplateBase.cs @@ -33,7 +33,9 @@ namespace DCFApixels.DragonECS { #region Properties public abstract Type Type { get; } + public virtual bool IsCustomName { get { return false; } } public virtual string Name { get { return string.Empty; } } + public virtual bool IsCustomColor { get { return false; } } public virtual MetaColor Color { get { return new MetaColor(MetaColor.Black); } } public virtual MetaGroup Group { get { return MetaGroup.Empty; } } public virtual MetaDescription Description { get { return MetaDescription.Empty; } } @@ -58,11 +60,13 @@ namespace DCFApixels.DragonECS #region Properties public override Type Type { get { return typeof(T); } } + public override bool IsCustomName { get { return Meta.IsCustomName; } } public override string Name { get { return Meta.Name; } } + public override bool IsCustomColor { get { return Meta.IsCustomColor; } } + public override MetaColor Color { get { return Meta.Color; } } public override MetaGroup Group { get { return Meta.Group; } } public override MetaDescription Description { get { return Meta.Description; } } public override IReadOnlyCollection Tags { get { return Meta.Tags; } } - public override MetaColor Color { get { return Meta.Color; } } #endregion #region Methods @@ -129,7 +133,7 @@ namespace DCFApixels.DragonECS.Unity.Editors Type interfaceType = typeof(IComponentTemplate); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { - var targetTypes = assembly.GetTypes().Where(type => !type.IsGenericType && !(type.IsAbstract || type.IsInterface) && type.GetCustomAttribute() != null); + var targetTypes = assembly.GetTypes().Where(type => !type.IsGenericType && !(type.IsAbstract || type.IsInterface) /*&& type.GetCustomAttribute() != null*/); types.AddRange(targetTypes.Where(type => interfaceType.IsAssignableFrom(type))); diff --git a/src/Icons/AutosetCascadeIcon.png b/src/Icons/AutosetCascadeIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..2ad48f625bbbef4926b1399af39d002c3f2e33d0 GIT binary patch literal 1990 zcmbVNeQeZZ94;FhV=#lxY`9=3T~I`N{kpqe8x9zElMT4Jj2jyoaJ}~JuI}zy+irK8 z1a}CA4H6_65E&wjgmB1Y1on?nmXQ!pLKZMO1Ly>T5`v1d1Y!)ny}O-&e8o$8ecL|o z^E|(g{@PJpwV)usBp*SLg31bS4LqaPk(UeqjkdO%@HAelSY{x|ghJ~WgM8FA89{PR zD*k%2-nW<+)v!&F)Bv!>!Wu*)$n3c>O%R)ai3UKU5^-a{eSQ=}70Hd&Ieer~^MIgI z(WZkXZB>4;tx4o0Z0;O%c8rGvVPFbqEF6j$e9Vm{d3m_DZW9=qgqTfktjrQb>wVRz zN7Vt!*(h8jNeX2-o8Xe{tb>__(j?6gBty^)PP%x9lV?~o{llP~F3Eh2_m#95ymDhf z)6{r^h(@EfC}UIgMuOrvjv#4*rg4bCjn;@M#PEnwI?CV$hNvr=si+auViW>uv+2g5 z)l>{&EkheI(s_azBVvL^P&U$vDG8Ls3{Gp-LrHN-BtQs+LBup5mdaqYplYf{P<;q> z=J7oOFtG0Ir(7??@{wc;>Qf~} zZoLoc@RKCZFua|<2MT*e5=`N-U`ga(&&D#DmGh{ zwf3jFTvA2I@vkaJbBx{YkZ~s`N;o6g?T{@Hz-fo%WLQ?_oD@6C_NuPH7flG=&1$)l zAR{MIQXn9aILFEiE|7K_cgZe*J1IeCoDP{3W!CEEWP|V(iUCX4ntnf)fVa}Ckb)+A zf)_-q*WH+C71@d>bz6BrKAuQ9y+0ZRkn|D7PstdnY(@nglr_TKJ+`@shnY8omPcEE zvQnlz-Dmy3&G>(;r_&+^g-9cSlas)#U4h^U$5k|yT;Kd9L_jvnVGKeA~T;s z1XAm8`p!$x0R$P-UFj|J*RQ?4rFUU=*`)W5u0wYh9UmC@u6p~vGYfByKU{OTwru;* zw)Pp5EA|BoclQ5Mx_H+O$FsBigF}0`_2*8se*g7>tzBCOjxHOzuYdwSi1X|>+VDAk@Qisud% zZR%Y!sjBm<_;Tjgz0XbAZ8ZF_VPse;;ht{JT7qDIl;o|*?TN4UXs15T8YKIcj(oa$ z-tX9|`F(Ns@XWkoVe`19@xo8`B%;`vim~(17rlF~1R9X01pm~OpWawr+}>1r=*pVz z)1Eo2PK=BValK=^#u&T4*x0{i-T9V~f8^YP`o9lfT(n3#b$;#s&8rZ(u%}>R1KOE& z>qN=$w5ImNyVs3@BQfM`?@X%i+O6ru-xeOcnm_6G)VzhYKi;?&d!Z-i_0XUF69%8z z)U#svwVWMY^?&)a?gGXcUf;9hVCS7f&+ku+`=eQM*I)|a-jyvo}%zhU)1 DE@G+g literal 0 HcmV?d00001 diff --git a/src/Icons/d_winbtn_win_restore@2x.png.meta b/src/Icons/AutosetCascadeIcon.png.meta similarity index 83% rename from src/Icons/d_winbtn_win_restore@2x.png.meta rename to src/Icons/AutosetCascadeIcon.png.meta index 343fb69..641eceb 100644 --- a/src/Icons/d_winbtn_win_restore@2x.png.meta +++ b/src/Icons/AutosetCascadeIcon.png.meta @@ -3,10 +3,10 @@ guid: 8f9fb2a8877577940971d81a98aeaaaa TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 13 + serializedVersion: 11 mipmaps: mipMapMode: 0 - enableMipMap: 1 + enableMipMap: 0 sRGBTexture: 1 linearTexture: 0 fadeOut: 0 @@ -20,12 +20,11 @@ TextureImporter: externalNormalMap: 0 heightScale: 0.25 normalMapFilter: 0 - flipGreenChannel: 0 isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 vTOnly: 0 - ignoreMipmapLimit: 0 + ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -52,7 +51,7 @@ TextureImporter: spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 - alphaIsTransparency: 0 + alphaIsTransparency: 1 spriteTessellationDetail: -1 textureType: 0 textureShape: 1 @@ -64,20 +63,17 @@ TextureImporter: textureFormatSet: 0 ignorePngGamma: 0 applyGammaDecoding: 0 - swizzle: 50462976 - cookieLightType: 0 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 - serializedVersion: 3 @@ -90,7 +86,18 @@ TextureImporter: crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: @@ -107,8 +114,9 @@ TextureImporter: weights: [] secondaryTextures: [] nameFileIdTable: {} - mipmapLimitGroupName: + spritePackingTag: pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/src/Icons/AutosetIcon.png b/src/Icons/AutosetIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..b1f790d26fe7a25a3c4d0b1d4495827cc63db443 GIT binary patch literal 1706 zcmbVNZEO=|9KXH7=7zy-aW309Zy5n*dw0EdZO@f$tiyJpquH9hkSyVP_q4sW_u}1^ zc8vpPFoKFR3b-w5rjcljPLiQUO`!7wOfrlblSKo%NL&bm`auI1KNOR7tKn7k>MmiFvbNLq7kH}H7+x37-*;;1bNYc{qfZq4COfo)^G6;9=QXA zcvnIJy@_rgn+UUZ4r|?xw!~>jAOMX)<3dDK>9_++^U`pwzs4~%4bj35tX(&V4tTt1 zhok`1ZX^vXL6E4`Ze(nn*=nJlKuv^+!U+mDQ3k?BTbgOgie?TBnp3y{-Q(PuF$SL; zSV+@k8pmU?m@!5fB_)WHcDo%XOt{HpfCz&+B5F+BAgT>n1}9Kig_kv65>cIz@k>$7 zfk9W-GzfBzR#Y=_f)T^xjEs{;Lf4cAa%>JKN0mt0ILG230t6sxD#VgGtQ?XwNexN= zLY@13hXEK{k0)p2p1ue|&V;IU?t?Ni0l6ny^^M2??*Xb5Ranru54zc)tC8sr1u&YV z_#`Qk&6GFmGHNm#t>~71UgV^hy7jgVz{zO9fx)bq4TQx&Qa;i~n@F0pHNo@|#2VBi zaeQFpE~v#v5Hv;7X3HH=STh`>G4};?EFF*(fq{Z~fe8X!7K0d?3nSejMI;3phTc(W zFFYRFEvgzLvcT=Q*0P1W49o4H&G11waAjW`o}ZtHw&$Z5BIeVr$Qf49QJ)?y+L%%eA)UJ|s6S7EY7G9A$ip3bZyJesZonql?oc3`ZYR={DI z*Zc!VV2w5w0+94S(!B;#rGOS=6wn@o(YkLr;m~_-RA4q$NBL*xSEqUxCjVSbExbj&{?faL z_76{gl6tJI7%AI-4CPC<44H<#6ZfAMQ4vbft;ajxso z$Q$2&IXwDWxajQkss(ZFL5ySH9JP-pKb*XDYPoB8v8(3_*%F(m7#})VSynW0V}9~# zV{*KyU>@0#mvSieiIS5WeyqD3-D`Mndc~AD@zdPqXYh9p){HEbgeC_4R_){DP;LKd zwm#hO%BQCa7l*w0%VVs2qnDh0bW^|kvU%?2lf#WyZ*F(dXlZgYvF_#g)aks>+qPbR m{I~M&!mD5GJeqf__1TAm&TtA8+^W+5ChpE|=gf}1&;0{*#ynU6 literal 0 HcmV?d00001 diff --git a/src/Icons/d_winbtn_win_max@2x.png.meta b/src/Icons/AutosetIcon.png.meta similarity index 81% rename from src/Icons/d_winbtn_win_max@2x.png.meta rename to src/Icons/AutosetIcon.png.meta index 7125548..c253200 100644 --- a/src/Icons/d_winbtn_win_max@2x.png.meta +++ b/src/Icons/AutosetIcon.png.meta @@ -3,10 +3,10 @@ guid: d01e651682f48b548b597714f47e14b9 TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 13 + serializedVersion: 11 mipmaps: mipMapMode: 0 - enableMipMap: 1 + enableMipMap: 0 sRGBTexture: 1 linearTexture: 0 fadeOut: 0 @@ -20,12 +20,11 @@ TextureImporter: externalNormalMap: 0 heightScale: 0.25 normalMapFilter: 0 - flipGreenChannel: 0 isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 vTOnly: 0 - ignoreMipmapLimit: 0 + ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -43,7 +42,7 @@ TextureImporter: nPOTScale: 0 lightmap: 0 compressionQuality: 50 - spriteMode: 2 + spriteMode: 1 spriteExtrude: 1 spriteMeshType: 1 alignment: 0 @@ -52,7 +51,7 @@ TextureImporter: spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 - alphaIsTransparency: 0 + alphaIsTransparency: 1 spriteTessellationDetail: -1 textureType: 0 textureShape: 1 @@ -64,20 +63,17 @@ TextureImporter: textureFormatSet: 0 ignorePngGamma: 0 applyGammaDecoding: 0 - swizzle: 50462976 - cookieLightType: 0 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 - serializedVersion: 3 @@ -90,7 +86,18 @@ TextureImporter: crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: @@ -99,7 +106,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: + spriteID: 5e97eb03825dee720800000000000000 internalID: 0 vertices: [] indices: @@ -107,8 +114,9 @@ TextureImporter: weights: [] secondaryTextures: [] nameFileIdTable: {} - mipmapLimitGroupName: + spritePackingTag: pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/src/Icons/d_winbtn_win_close.png b/src/Icons/CloseIcon.png similarity index 100% rename from src/Icons/d_winbtn_win_close.png rename to src/Icons/CloseIcon.png diff --git a/src/Icons/d_winbtn_win_close.png.meta b/src/Icons/CloseIcon.png.meta similarity index 83% rename from src/Icons/d_winbtn_win_close.png.meta rename to src/Icons/CloseIcon.png.meta index 26a947b..8a67a2d 100644 --- a/src/Icons/d_winbtn_win_close.png.meta +++ b/src/Icons/CloseIcon.png.meta @@ -3,10 +3,10 @@ guid: 8a708e50662813d4a99c107e6431a60b TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 13 + serializedVersion: 11 mipmaps: mipMapMode: 0 - enableMipMap: 1 + enableMipMap: 0 sRGBTexture: 1 linearTexture: 0 fadeOut: 0 @@ -20,12 +20,11 @@ TextureImporter: externalNormalMap: 0 heightScale: 0.25 normalMapFilter: 0 - flipGreenChannel: 0 isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 vTOnly: 0 - ignoreMipmapLimit: 0 + ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -52,7 +51,7 @@ TextureImporter: spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 - alphaIsTransparency: 0 + alphaIsTransparency: 1 spriteTessellationDetail: -1 textureType: 0 textureShape: 1 @@ -64,20 +63,17 @@ TextureImporter: textureFormatSet: 0 ignorePngGamma: 0 applyGammaDecoding: 0 - swizzle: 50462976 - cookieLightType: 0 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 - serializedVersion: 3 @@ -90,7 +86,18 @@ TextureImporter: crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: @@ -107,8 +114,9 @@ TextureImporter: weights: [] secondaryTextures: [] nameFileIdTable: {} - mipmapLimitGroupName: + spritePackingTag: pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/src/Icons/d_P4_DeletedLocal.png b/src/Icons/CloseIconOn.png similarity index 100% rename from src/Icons/d_P4_DeletedLocal.png rename to src/Icons/CloseIconOn.png diff --git a/src/Icons/d_P4_DeletedLocal.png.meta b/src/Icons/CloseIconOn.png.meta similarity index 83% rename from src/Icons/d_P4_DeletedLocal.png.meta rename to src/Icons/CloseIconOn.png.meta index 046fdf1..7904d9f 100644 --- a/src/Icons/d_P4_DeletedLocal.png.meta +++ b/src/Icons/CloseIconOn.png.meta @@ -3,10 +3,10 @@ guid: 6a1d402595b00c24db2ba647fed93a5c TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 13 + serializedVersion: 11 mipmaps: mipMapMode: 0 - enableMipMap: 1 + enableMipMap: 0 sRGBTexture: 1 linearTexture: 0 fadeOut: 0 @@ -20,12 +20,11 @@ TextureImporter: externalNormalMap: 0 heightScale: 0.25 normalMapFilter: 0 - flipGreenChannel: 0 isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 vTOnly: 0 - ignoreMipmapLimit: 0 + ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -52,7 +51,7 @@ TextureImporter: spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 - alphaIsTransparency: 0 + alphaIsTransparency: 1 spriteTessellationDetail: -1 textureType: 0 textureShape: 1 @@ -64,20 +63,17 @@ TextureImporter: textureFormatSet: 0 ignorePngGamma: 0 applyGammaDecoding: 0 - swizzle: 50462976 - cookieLightType: 0 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 - serializedVersion: 3 @@ -90,7 +86,18 @@ TextureImporter: crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: @@ -107,8 +114,9 @@ TextureImporter: weights: [] secondaryTextures: [] nameFileIdTable: {} - mipmapLimitGroupName: + spritePackingTag: pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/src/Icons/d__Help.png b/src/Icons/HelpIcon.png similarity index 100% rename from src/Icons/d__Help.png rename to src/Icons/HelpIcon.png diff --git a/src/Icons/d__Help.png.meta b/src/Icons/HelpIcon.png.meta similarity index 83% rename from src/Icons/d__Help.png.meta rename to src/Icons/HelpIcon.png.meta index 439d0b0..fdee6d6 100644 --- a/src/Icons/d__Help.png.meta +++ b/src/Icons/HelpIcon.png.meta @@ -3,10 +3,10 @@ guid: e135cf23a5d53ce48a75e163b41e39d5 TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 13 + serializedVersion: 11 mipmaps: mipMapMode: 0 - enableMipMap: 1 + enableMipMap: 0 sRGBTexture: 1 linearTexture: 0 fadeOut: 0 @@ -20,12 +20,11 @@ TextureImporter: externalNormalMap: 0 heightScale: 0.25 normalMapFilter: 0 - flipGreenChannel: 0 isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 vTOnly: 0 - ignoreMipmapLimit: 0 + ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -52,7 +51,7 @@ TextureImporter: spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 - alphaIsTransparency: 0 + alphaIsTransparency: 1 spriteTessellationDetail: -1 textureType: 0 textureShape: 1 @@ -64,20 +63,17 @@ TextureImporter: textureFormatSet: 0 ignorePngGamma: 0 applyGammaDecoding: 0 - swizzle: 50462976 - cookieLightType: 0 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 - serializedVersion: 3 @@ -90,7 +86,18 @@ TextureImporter: crunchedCompression: 0 allowsAlphaSplitting: 0 overridden: 0 - ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: @@ -107,8 +114,9 @@ TextureImporter: weights: [] secondaryTextures: [] nameFileIdTable: {} - mipmapLimitGroupName: + spritePackingTag: pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/src/Icons/UnlinkIcon.png b/src/Icons/UnlinkIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..f6f1004fc8d96971889366b48644e75ee5b4730e GIT binary patch literal 647 zcmV;20(kw2P)y!+0* z@7#~~YW;qnVPe}*y^jJI1@J!vu)S!(%nkuceGR0*%o@OZ zU>tY}OiKFV=~x1e;OW??JIrhsun3&+gB*~wlC_CaFyqeGQs)5ftO>kjlZEMfC!K5D zxz{05-~+G^xFhL$aH;_%fW3aoH{_Hi!+&1{L`O*qYn>9nN0MAG zxlJA^S0lerI0*|d2DJQtlfO!&g_+uH8j%8Nk(|sgNO}#N0d@k%7*t}xZSqLDR`Lr` z4cr4RlN8RuvFKu@9oQ zfA)Y!z$@T;&h)9IpMG<$G1whvfm?1n9Sx$e2qn#%S%qsr?A(!qV2+c)Cpv$IJ6hQ@=BDf9LLf}SS4Z6^U z8>L7}cM+r;K?0eQ z17~8lpi-%HVw(U1rBdlf%Xw*2{JSoMS`6q2B+Ez3 z@h^$GdD377Oz`{-=&To=58FU|E}uIwnnRdavzxQ1%1*5&{7mSrHJB3loLDRd{E*zO z&jNjG==#A0a2wP!G3k6T1>$r0+=O(Z)Joi{zMTb!+X|Js}ncQ;y;Y+%edxQ;jKz}30$#j`UnGJRw6zonJ%=Hb_Sm+hCD zi+>bw%6s}!xTApsi1zq3++%%_QqceX+^1`n@ktl7zJ2uMT+o~4Ys0ni`=v=6cl=RO bV5(Q1q&H#it)AIHS2K9J`njxgN@xNAM|EG? diff --git a/src/Icons/d_winbtn_win_restore@2x.png b/src/Icons/d_winbtn_win_restore@2x.png deleted file mode 100644 index dc22a341c8aef5c7ee156b6e94972c56b948e2c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 283 zcmV+$0p$LPP)N$H0r(D3SEKr^)wL`o ziOE;m5Qe{iTIxt3K7iXXySH!JY3 hoG6LwTopKn0$=a}Nr4Sy+6@2z002ovPDHLkV1l9JboKxM diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index c7e7ef4..679e47b 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -39,6 +39,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public struct ContentColorScope : IDisposable { private readonly Color _value; + public ContentColorScope(float r, float g, float b, float a = 1f) : this(new Color(r, g, b, a)) { } public ContentColorScope(Color value) { _value = GUI.contentColor; diff --git a/src/Internal/EscEditorConsts.cs b/src/Internal/EscEditorConsts.cs index 9307e9a..d3a7c88 100644 --- a/src/Internal/EscEditorConsts.cs +++ b/src/Internal/EscEditorConsts.cs @@ -4,5 +4,6 @@ { public const float COMPONENT_DRAWER_ALPHA = 0.26f; public const float COMPONENT_DRAWER_DESATURATE = 0.86f; + public const int AUTO_COLOR_RAINBOW_MIN_RANGE = 7; } } From 7b2f9f5093268cf8d3b8e059a0fe9ad017f3ed7e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 15 May 2024 00:49:28 +0800 Subject: [PATCH 02/10] rename/update setting prefs --- src/Debug/Editor/SettingsEditor.cs | 12 ++++++------ src/Debug/Editor/SettingsPrefs.cs | 12 ++++++------ src/EntityTemplate/Editor/EntityTemplateEditor.cs | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Debug/Editor/SettingsEditor.cs b/src/Debug/Editor/SettingsEditor.cs index b782fc2..e8e0e39 100644 --- a/src/Debug/Editor/SettingsEditor.cs +++ b/src/Debug/Editor/SettingsEditor.cs @@ -61,27 +61,27 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.BeginHorizontal(); settings.IsShowHidden = EditorGUILayout.Toggle(SettingsPrefs.instance.IsShowHidden, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(nameof(SettingsPrefs.IsShowHidden), GUILayout.ExpandWidth(false)); + GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(SettingsPrefs.IsShowHidden)), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); settings.IsShowInterfaces = EditorGUILayout.Toggle(SettingsPrefs.instance.IsShowInterfaces, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(nameof(SettingsPrefs.IsShowInterfaces), GUILayout.ExpandWidth(false)); + GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(SettingsPrefs.IsShowInterfaces)), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); settings.IsShowRuntimeComponents = EditorGUILayout.Toggle(SettingsPrefs.instance.IsShowRuntimeComponents, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(nameof(SettingsPrefs.IsShowRuntimeComponents), GUILayout.ExpandWidth(false)); + GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(SettingsPrefs.IsShowRuntimeComponents)), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); - settings.AutoColorMode = (AutoColorMode)EditorGUILayout.EnumPopup(nameof(SettingsPrefs.AutoColorMode), SettingsPrefs.instance.AutoColorMode); + settings.AutoColorMode = (ComponentColorMode)EditorGUILayout.EnumPopup(UnityEditorUtility.TransformFieldName(nameof(SettingsPrefs.ComponentColorMode)), SettingsPrefs.instance.ComponentColorMode); if (EditorGUI.EndChangeCheck()) { SettingsPrefs.instance.IsShowHidden = settings.IsShowHidden; SettingsPrefs.instance.IsShowInterfaces = settings.IsShowInterfaces; SettingsPrefs.instance.IsShowRuntimeComponents = settings.IsShowRuntimeComponents; - SettingsPrefs.instance.AutoColorMode = settings.AutoColorMode; + SettingsPrefs.instance.ComponentColorMode = settings.AutoColorMode; } GUILayout.EndVertical(); @@ -147,7 +147,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public bool IsShowHidden; public bool IsShowInterfaces; public bool IsShowRuntimeComponents; - public AutoColorMode AutoColorMode; + public ComponentColorMode AutoColorMode; } } } diff --git a/src/Debug/Editor/SettingsPrefs.cs b/src/Debug/Editor/SettingsPrefs.cs index 22e81b6..a193e42 100644 --- a/src/Debug/Editor/SettingsPrefs.cs +++ b/src/Debug/Editor/SettingsPrefs.cs @@ -4,10 +4,10 @@ using UnityEngine; namespace DCFApixels.DragonECS.Unity.Editors { - internal enum AutoColorMode + internal enum ComponentColorMode { Generic = 0, - Name = 1, + Auto = 1, Rainbow = 2, } [FilePath(EcsConsts.AUTHOR + "/" + EcsConsts.FRAMEWORK_NAME + "/" + nameof(SettingsPrefs) + ".prefs", FilePathAttribute.Location.ProjectFolder)] @@ -61,13 +61,13 @@ namespace DCFApixels.DragonECS.Unity.Editors [SerializeField] - private AutoColorMode _autoColorMode = AutoColorMode.Name; - public AutoColorMode AutoColorMode + private ComponentColorMode _componentColorMode = ComponentColorMode.Auto; + public ComponentColorMode ComponentColorMode { - get => _autoColorMode; + get => _componentColorMode; set { - _autoColorMode = value; + _componentColorMode = value; Save(false); } } diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index b30ec75..ac4e4c1 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -16,10 +16,10 @@ namespace DCFApixels.DragonECS.Unity.Editors private GenericMenu _genericMenu; private bool _isInit = false; - private static AutoColorMode AutoColorMode + private static ComponentColorMode AutoColorMode { - get { return SettingsPrefs.instance.AutoColorMode; } - set { SettingsPrefs.instance.AutoColorMode = value; } + get { return SettingsPrefs.instance.ComponentColorMode; } + set { SettingsPrefs.instance.ComponentColorMode = value; } } #region Init @@ -208,10 +208,10 @@ namespace DCFApixels.DragonECS.Unity.Editors { switch (AutoColorMode) { - case AutoColorMode.Name: + case ComponentColorMode.Auto: panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; break; - case AutoColorMode.Rainbow: + case ComponentColorMode.Rainbow: Color hsv = Color.HSVToRGB(1f / (Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE)) * index, 1, 1); panelColor = hsv.Desaturate(0.48f) / 1.18f; break; From 60723a67f6ca96410ef3ad329d75df13ad0a94b8 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 15 May 2024 01:06:19 +0800 Subject: [PATCH 03/10] update runtime component display --- src/Internal/Editor/EcsGUI.cs | 51 +++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 679e47b..0c7a18c 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -51,6 +51,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } } #endregion + private static readonly BindingFlags fieldFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; internal readonly static Color GrayColor = new Color32(100, 100, 100, 255); internal readonly static Color GreenColor = new Color32(75, 255, 0, 255); @@ -61,6 +62,12 @@ namespace DCFApixels.DragonECS.Unity.Editors public static float EntityBarHeight => EditorGUIUtility.singleLineHeight + 3f; + #region Properties + private static ComponentColorMode AutoColorMode + { + get { return SettingsPrefs.instance.ComponentColorMode; } + set { SettingsPrefs.instance.ComponentColorMode = value; } + } private static bool IsShowHidden { get { return SettingsPrefs.instance.IsShowHidden; } @@ -71,7 +78,9 @@ namespace DCFApixels.DragonECS.Unity.Editors get { return SettingsPrefs.instance.IsShowRuntimeComponents; } set { SettingsPrefs.instance.IsShowRuntimeComponents = value; } } + #endregion + #region enums public enum AddClearComponentButton : byte { None = 0, @@ -85,7 +94,9 @@ namespace DCFApixels.DragonECS.Unity.Editors Alive = 1 << 0, Undefined = 1 << 1, } + #endregion + #region HitTest internal static bool HitTest(Rect rect) { return HitTest(rect, Event.current.mousePosition); @@ -103,7 +114,9 @@ namespace DCFApixels.DragonECS.Unity.Editors { return point.x >= rect.xMin - (float)offset && point.x < rect.xMax + (float)offset && point.y >= rect.yMin - (float)offset && point.y < rect.yMax + (float)offset; } + #endregion + #region small elems public static void DrawIcon(Rect position, Texture icon, float iconPadding, string description) { GUI.Label(position, UnityEditorUtility.GetLabel(string.Empty, description)); @@ -164,8 +177,9 @@ namespace DCFApixels.DragonECS.Unity.Editors { return IconButton(position, Icons.Instance.CloseIcon, 0f, "Delete Entity"); } + #endregion - + #region entity bar public static void EntityBarForAlive(Rect position, EntityStatus status, int id, short gen, short world) { EntityBar(position, status != EntityStatus.Alive, status, id, gen, world); @@ -243,6 +257,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } } } + #endregion public static bool AddComponentButtons(Rect position) { @@ -281,6 +296,8 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorGUILayout.IntField("Leaked Entites", leakedEntitesCount, EditorStyles.boldLabel); } } + + #region entity bar public static void EntityBarForAlive(EntityStatus status, int id, short gen, short world) { float width = EditorGUIUtility.currentViewWidth; @@ -305,6 +322,7 @@ namespace DCFApixels.DragonECS.Unity.Editors float height = EntityBarHeight; EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height)); } + #endregion public static bool AddComponentButtons() { @@ -344,24 +362,47 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Box("", UnityEditorUtility.GetStyle(GUI.color, 0.16f), GUILayout.ExpandWidth(true)); IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden); + int i = 0; foreach (var componentTypeID in componentTypeIDs) { var pool = world.GetPoolInstance(componentTypeID); { - DrawRuntimeComponent(entityID, pool); + DrawRuntimeComponent(componentTypeIDs.Length, i++, entityID, pool); } } } GUILayout.EndVertical(); } - private static readonly BindingFlags fieldFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; - private static void DrawRuntimeComponent(int entityID, IEcsPool pool) + private static void DrawRuntimeComponent(int total, int index, int entityID, IEcsPool pool) { var meta = pool.ComponentType.ToMeta(); if (meta.IsHidden == false || IsShowHidden) { object data = pool.GetRaw(entityID); - Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + //Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + + Color panelColor; + if (meta.IsCustomColor) + { + panelColor = meta.Color.ToUnityColor(); + } + else + { + switch (AutoColorMode) + { + case ComponentColorMode.Auto: + panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; + break; + case ComponentColorMode.Rainbow: + Color hsv = Color.HSVToRGB(1f / (Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE)) * index, 1, 1); + panelColor = hsv.Desaturate(0.48f) / 1.18f; + break; + default: + panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); + break; + } + } + panelColor = panelColor.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); float padding = EditorGUIUtility.standardVerticalSpacing; Rect removeButtonRect = GUILayoutUtility.GetLastRect(); From e9ccb3f48e99ef2f2a578ff9d8d12d90dfa5c59c Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 19:03:03 +0800 Subject: [PATCH 04/10] add component template display --- src/Connectors/EcsEntityConnect.cs | 5 +- src/Debug/Editor/SettingsEditor.cs | 1 - .../Monitors/Editor/EntityMonitorEditor.cs | 2 +- .../ComponentTemplateReferenceAttribute.cs | 67 +++++ ...omponentTemplateReferenceAttribute.cs.meta | 11 + .../ComponentTemplateReferenceDrawer.cs | 250 ++++++++++++++++++ .../ComponentTemplateReferenceDrawer.cs.meta | 11 + .../Editor/EntityTemplateEditor.cs | 64 +---- src/Internal/Editor/EcsGUI.cs | 63 ++++- src/Internal/Utils/RectUtility.cs | 38 +-- 10 files changed, 433 insertions(+), 79 deletions(-) create mode 100644 src/EntityTemplate/ComponentTemplateReferenceAttribute.cs create mode 100644 src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta create mode 100644 src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs create mode 100644 src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta diff --git a/src/Connectors/EcsEntityConnect.cs b/src/Connectors/EcsEntityConnect.cs index 78db7ff..0f6a22b 100644 --- a/src/Connectors/EcsEntityConnect.cs +++ b/src/Connectors/EcsEntityConnect.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using UnityEditor; using UnityEngine; +#region UNITY_EDITOR +using UnityEditor; +#endregion namespace DCFApixels.DragonECS { @@ -172,6 +174,7 @@ namespace DCFApixels.DragonECS internal void Autoset_Editor() { Autoset(this); + } [ContextMenu("Autoset Cascade")] internal void AutosetCascade_Editor() diff --git a/src/Debug/Editor/SettingsEditor.cs b/src/Debug/Editor/SettingsEditor.cs index e8e0e39..be5310a 100644 --- a/src/Debug/Editor/SettingsEditor.cs +++ b/src/Debug/Editor/SettingsEditor.cs @@ -1,5 +1,4 @@ #if UNITY_EDITOR -using System; using System.Collections.Generic; using System.Linq; using UnityEditor; diff --git a/src/Debug/Monitors/Editor/EntityMonitorEditor.cs b/src/Debug/Monitors/Editor/EntityMonitorEditor.cs index b3f505e..0581d9c 100644 --- a/src/Debug/Monitors/Editor/EntityMonitorEditor.cs +++ b/src/Debug/Monitors/Editor/EntityMonitorEditor.cs @@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS.Unity.Editors bool isAlive = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world); using (new EditorGUI.DisabledScope(!isAlive)) { - if (GUILayout.Button("Delete Entity")) + if (GUILayout.Button("Delete Entity", GUILayout.Height(36f))) { world.DelEntity(id); } diff --git a/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs b/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs new file mode 100644 index 0000000..3a3c372 --- /dev/null +++ b/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs @@ -0,0 +1,67 @@ +using System; +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace DCFApixels.DragonECS +{ + [Serializable] + public struct ComponentTemplateProperty : IEquatable + { + [SerializeReference, ComponentTemplateReference] + private IComponentTemplate _template; + public ComponentTemplateProperty(IComponentTemplate template) + { + _template = template; + } + + public IComponentTemplate Template + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _template; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set { _template = value; } + } + public Type Type + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _template.Type; } + } + public bool IsNull + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _template == null; } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Apply(short worldID, int entityID) { _template.Apply(worldID, entityID); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public object GetRaw() { return _template.GetRaw(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void OnGizmos(Transform transform, IComponentTemplate.GizmosMode mode) { _template.OnGizmos(transform, mode); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void OnValidate(UnityEngine.Object obj) { _template.OnValidate(obj); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void SetRaw(object raw) { _template.SetRaw(raw); } + + public bool Equals(ComponentTemplateProperty other) + { + return _template == other._template; + } + public override int GetHashCode() + { + return _template.GetHashCode(); + } + public static bool operator ==(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template == b._template; } + public static bool operator !=(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template != b._template; } + + public static bool operator ==(ComponentTemplateProperty a, Null? b) { return a.IsNull; } + public static bool operator ==(Null? a, ComponentTemplateProperty b) { return b.IsNull; } + + public static bool operator !=(ComponentTemplateProperty a, Null? b) { return !a.IsNull; } + public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; } + + public readonly struct Null { } + } + + + public sealed class ComponentTemplateReferenceAttribute : PropertyAttribute { } +} \ No newline at end of file diff --git a/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta b/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta new file mode 100644 index 0000000..92c9ce3 --- /dev/null +++ b/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6231d6781930a694696d09c3d55fc2fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs new file mode 100644 index 0000000..88afa19 --- /dev/null +++ b/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs @@ -0,0 +1,250 @@ +#if UNITY_EDITOR +using DCFApixels.DragonECS.Unity.Internal; +using System; +using System.Reflection; +using UnityEditor; +using UnityEngine; + +namespace DCFApixels.DragonECS.Unity.Editors +{ + + [CustomPropertyDrawer(typeof(ComponentTemplateReferenceAttribute), true)] + public class ComponentTemplateReferenceDrawer : PropertyDrawer + { + private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f); + + private float Padding => EditorGUIUtility.standardVerticalSpacing; + + private const float DamagedComponentHeight = 18f * 2f; + + private static bool _isInit; + private static GenericMenu _genericMenu; + #region Init + private static void Init() + { + if (_genericMenu == null) { _isInit = false; } + if (_isInit) { return; } + + _genericMenu = new GenericMenu(); + + var componentTemplateDummies = ComponentTemplateTypeCache.Dummies; + foreach (var dummy in componentTemplateDummies) + { + if (dummy.Type.GetCustomAttribute() == null) + { + Debug.LogWarning($"Type {dummy.Type.Name} does not have the [Serializable] attribute"); + continue; + } + ITypeMeta meta = dummy is ITypeMeta metaOverride ? metaOverride : dummy.Type.ToMeta(); + string name = meta.Name; + string description = meta.Description.Text; + MetaGroup group = meta.Group; + + if (group.Name.Length > 0) + { + name = group.Name + name; + } + + if (string.IsNullOrEmpty(description) == false) + { + name = $"{name} [i]"; + } + _genericMenu.AddItem(new GUIContent(name, description), false, SelectComponent, dummy); + } + + _isInit = true; + } + [ThreadStatic] + private static SerializedProperty currentProperty; + private static void SelectComponent(object dummy) + { + currentProperty.managedReferenceValue = ((IComponentTemplate)dummy).Clone(); + currentProperty.isExpanded = false; + currentProperty.serializedObject.ApplyModifiedProperties(); + } + #endregion + + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + IComponentTemplate template = property.managedReferenceValue as IComponentTemplate; + if (template == null || property.managedReferenceValue == null) + { + return EditorGUIUtility.singleLineHeight + Padding * 2f; + } + + try + { + ComponentTemplateBase customTemplate = property.managedReferenceValue as ComponentTemplateBase; + if (customTemplate != null) + { + property = property.FindPropertyRelative("component"); + } + } + catch (Exception) + { + property = null; + } + if (property == null) + { + return DamagedComponentHeight; + } + + var propsCounter = property.Copy(); + int lastDepth = propsCounter.depth; + bool next = propsCounter.Next(true) && lastDepth < propsCounter.depth; + int propCount = next ? -1 : 0; + while (next) + { + propCount++; + next = propsCounter.Next(false); + } + bool isEmpty = propCount <= 0; + + + return (isEmpty ? EditorGUIUtility.singleLineHeight : EditorGUI.GetPropertyHeight(property, label)) + Padding * 4f; + } + + + + public override void OnGUI(Rect position, SerializedProperty componentRefProp, GUIContent label) + { + Init(); + var counter = componentRefProp.Copy(); + + int positionCountr = int.MaxValue; + while (counter.NextVisible(false)) + { + positionCountr--; + } + + IComponentTemplate template = componentRefProp.managedReferenceValue as IComponentTemplate; + if (template == null || componentRefProp.managedReferenceValue == null) + { + DrawSelectionPopup(position, componentRefProp, label); + return; + } + + Type componentType; + SerializedProperty componentProperty = componentRefProp; + try + { + ComponentTemplateBase customTemplate = componentProperty.managedReferenceValue as ComponentTemplateBase; + if (customTemplate != null) + { + componentProperty = componentRefProp.FindPropertyRelative("component"); + componentType = customTemplate.GetType().GetField("component", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FieldType; + } + else + { + componentType = componentProperty.managedReferenceValue.GetType(); + } + + if (componentType == null || componentProperty == null) + { + throw new NullReferenceException(); + } + } + catch (Exception e) + { + Debug.LogException(e, componentRefProp.serializedObject.targetObject); + DrawDamagedComponent(position, "Damaged component template."); + return; + } + + //сюда попадают уже валидные компоненты + + ITypeMeta meta = template is ITypeMeta metaOverride ? metaOverride : template.Type.ToMeta(); + string name = meta.Name; + string description = meta.Description.Text; + + int propCount = EcsGUI.GetChildPropertiesCount(componentProperty, componentType, out bool isEmpty); + + Color panelColor = EcsGUI.SelectPanelColor(meta, positionCountr, -1).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + + Color alphaPanelColor = panelColor; + alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA; + + + EditorGUI.BeginChangeCheck(); + GUI.Box(position, "", UnityEditorUtility.GetStyle(alphaPanelColor)); + + Rect paddingPosition = RectUtility.AddPadding(position, Padding * 2f); + + #region Draw Component Block + Rect removeButtonRect = position; + removeButtonRect.center -= new Vector2(0, removeButtonRect.height); + removeButtonRect.yMin = removeButtonRect.yMax; + removeButtonRect.yMax += HeadIconsRect.height; + removeButtonRect.xMin = removeButtonRect.xMax - HeadIconsRect.width; + removeButtonRect.center += Vector2.up * Padding * 1f; + + bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect); + + if (propCount <= 0) + { + label.text = $"{label.text} ({name})"; + EditorGUI.LabelField(paddingPosition, label); + Rect emptyPos = paddingPosition; + emptyPos.xMin += EditorGUIUtility.labelWidth; + if (isEmpty) + { + using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) + { + GUI.Label(emptyPos, "empty"); + } + } + EditorGUI.BeginProperty(paddingPosition, label, componentRefProp); + EditorGUI.EndProperty(); + } + else + { + label.text = $"{label.text} ({name})"; + if (componentProperty.propertyType == SerializedPropertyType.Generic) + { + EditorGUI.PropertyField(paddingPosition, componentProperty, label, true); + } + else + { + Rect r = RectUtility.AddPadding(paddingPosition, 0, 20f, 0, 0); + EditorGUI.PropertyField(r, componentProperty, label, true); + } + } + if (isRemoveComponent) + { + componentRefProp.managedReferenceValue = null; + } + if (string.IsNullOrEmpty(description) == false) + { + Rect tooltipIconRect = HeadIconsRect; + tooltipIconRect.center = removeButtonRect.center; + tooltipIconRect.center -= Vector2.right * tooltipIconRect.width; + EcsGUI.DescriptionIcon(tooltipIconRect, description); + } + #endregion + + if (EditorGUI.EndChangeCheck()) + { + componentProperty.serializedObject.ApplyModifiedProperties(); + EditorUtility.SetDirty(componentProperty.serializedObject.targetObject); + } + } + + private void DrawSelectionPopup(Rect position, SerializedProperty componentRefProp, GUIContent label) + { + EditorGUI.LabelField(position, label); + //Rect buttonRect = RectUtility.AddPadding(position, EditorGUIUtility.labelWidth, 20f, 0f, 0f); + Rect buttonRect = RectUtility.AddPadding(position, EditorGUIUtility.labelWidth, 0f, 0f, 0f); + if (GUI.Button(buttonRect, "Select")) + { + currentProperty = componentRefProp; + _genericMenu.ShowAsContext(); + } + } + private void DrawDamagedComponent(Rect position, string message) + { + EditorGUI.HelpBox(position, message, MessageType.Warning); + } + } +} +#endif \ No newline at end of file diff --git a/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta b/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta new file mode 100644 index 0000000..03dce75 --- /dev/null +++ b/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dbf91ec8124942340b7f095474db92b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index ac4e4c1..f5654e8 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -9,10 +9,8 @@ namespace DCFApixels.DragonECS.Unity.Editors { internal abstract class EntityTemplateEditorBase : Editor { - private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 19f, 19f); - private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 19f, 19f); + private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f); - private GUIStyle _removeButtonStyle; private GenericMenu _genericMenu; private bool _isInit = false; @@ -28,21 +26,6 @@ namespace DCFApixels.DragonECS.Unity.Editors if (_genericMenu == null) { _isInit = false; } if (_isInit) { return; } - var tmpstylebase = UnityEditorUtility.GetStyle(new Color(0.9f, 0f, 0.22f), 0.5f); - var tmpStyle = UnityEditorUtility.GetStyle(new Color(1f, 0.5f, 0.7f), 0.5f); - - _removeButtonStyle = new GUIStyle(EditorStyles.linkLabel); - _removeButtonStyle.alignment = TextAnchor.MiddleCenter; - - _removeButtonStyle.normal = tmpstylebase.normal; - _removeButtonStyle.hover = tmpStyle.normal; - _removeButtonStyle.active = tmpStyle.normal; - _removeButtonStyle.focused = tmpStyle.normal; - - _removeButtonStyle.padding = new RectOffset(0, 0, 0, 0); - _removeButtonStyle.margin = new RectOffset(0, 0, 0, 0); - _removeButtonStyle.border = new RectOffset(0, 0, 0, 0); - _genericMenu = new GenericMenu(); var componentTemplateDummies = ComponentTemplateTypeCache.Dummies; @@ -187,40 +170,11 @@ namespace DCFApixels.DragonECS.Unity.Editors string name = meta.Name; string description = meta.Description.Text; - bool isEmpty = componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0; - var propsCounter = componentProperty.Copy(); - int lastDepth = propsCounter.depth; - bool next = propsCounter.Next(true) && lastDepth < propsCounter.depth; - int propCount = next ? -1 : 0; - while (next) - { - propCount++; - next = propsCounter.Next(false); - } + int propCount = EcsGUI.GetChildPropertiesCount(componentProperty, componentType, out bool isEmpty); + float padding = EditorGUIUtility.standardVerticalSpacing; - Color panelColor; - if (meta.IsCustomColor) - { - panelColor = meta.Color.ToUnityColor(); - } - else - { - switch (AutoColorMode) - { - case ComponentColorMode.Auto: - panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; - break; - case ComponentColorMode.Rainbow: - Color hsv = Color.HSVToRGB(1f / (Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE)) * index, 1, 1); - panelColor = hsv.Desaturate(0.48f) / 1.18f; - break; - default: - panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); - break; - } - } - panelColor = panelColor.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + Color panelColor = EcsGUI.SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); Color alphaPanelColor = panelColor; alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA; @@ -232,8 +186,8 @@ namespace DCFApixels.DragonECS.Unity.Editors #region Draw Component Block removeButtonRect.yMin = removeButtonRect.yMax; - removeButtonRect.yMax += RemoveButtonRect.height; - removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width; + removeButtonRect.yMax += HeadIconsRect.height; + removeButtonRect.xMin = removeButtonRect.xMax - HeadIconsRect.width; removeButtonRect.center += Vector2.up * padding * 2f; bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect); @@ -273,7 +227,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } if (string.IsNullOrEmpty(description) == false) { - Rect tooltipIconRect = TooltipIconRect; + Rect tooltipIconRect = HeadIconsRect; tooltipIconRect.center = removeButtonRect.center; tooltipIconRect.center -= Vector2.right * tooltipIconRect.width; EcsGUI.DescriptionIcon(tooltipIconRect, description); @@ -301,8 +255,8 @@ namespace DCFApixels.DragonECS.Unity.Editors float padding = EditorGUIUtility.standardVerticalSpacing; removeButtonRect.yMin = removeButtonRect.yMax; - removeButtonRect.yMax += RemoveButtonRect.height; - removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width; + removeButtonRect.yMax += HeadIconsRect.height; + removeButtonRect.xMin = removeButtonRect.xMax - HeadIconsRect.width; removeButtonRect.center += Vector2.up * padding * 2f; bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect); diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 0c7a18c..4f5938e 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -26,6 +26,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public struct ColorScope : IDisposable { private readonly Color _value; + public ColorScope(float r, float g, float b, float a = 1f) : this(new Color(r, g, b, a)) { } public ColorScope(Color value) { _value = GUI.color; @@ -50,7 +51,15 @@ namespace DCFApixels.DragonECS.Unity.Editors GUI.contentColor = _value; } } + private static ContentColorScope SetContentColor(Color value) => new ContentColorScope(value); + private static ContentColorScope SetContentColor(float r, float g, float b, float a = 1f) => new ContentColorScope(r, g, b, a); + private static ColorScope SetColor(Color value) => new ColorScope(value); + private static ColorScope SetColor(float r, float g, float b, float a = 1f) => new ColorScope(r, g, b, a); + private static EditorGUI.DisabledScope Enable => new EditorGUI.DisabledScope(false); + private static EditorGUI.DisabledScope Disable => new EditorGUI.DisabledScope(true); + private static EditorGUI.DisabledScope SetEnable(bool value) => new EditorGUI.DisabledScope(!value); #endregion + private static readonly BindingFlags fieldFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; internal readonly static Color GrayColor = new Color32(100, 100, 100, 255); @@ -119,8 +128,11 @@ namespace DCFApixels.DragonECS.Unity.Editors #region small elems public static void DrawIcon(Rect position, Texture icon, float iconPadding, string description) { - GUI.Label(position, UnityEditorUtility.GetLabel(string.Empty, description)); - GUI.DrawTexture(RectUtility.AddPadding(position, iconPadding), icon); + using (SetColor(GUI.enabled ? GUI.color : GUI.color * new Color(1f, 1f, 1f, 0.4f))) + { + GUI.Label(position, UnityEditorUtility.GetLabel(string.Empty, description)); + GUI.DrawTexture(RectUtility.AddPadding(position, iconPadding), icon); + } } public static (bool, bool) IconButtonGeneric(Rect position) { @@ -259,6 +271,51 @@ namespace DCFApixels.DragonECS.Unity.Editors } #endregion + internal static int GetChildPropertiesCount(SerializedProperty property, Type type, out bool isEmpty) + { + int result = GetChildPropertiesCount(property); + isEmpty = result <= 0 && type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0; + return result; + } + internal static int GetChildPropertiesCount(SerializedProperty property) + { + var propsCounter = property.Copy(); + int lastDepth = propsCounter.depth; + bool next = propsCounter.Next(true) && lastDepth < propsCounter.depth; + int result = next ? -1 : 0; + while (next) + { + result++; + next = propsCounter.Next(false); + } + return result; + } + public static Color SelectPanelColor(ITypeMeta meta, int index, int total) + { + Color panelColor; + if (meta.IsCustomColor) + { + panelColor = meta.Color.ToUnityColor(); + } + else + { + switch (AutoColorMode) + { + case ComponentColorMode.Auto: + panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; + break; + case ComponentColorMode.Rainbow: + int localTotal = Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE); + Color hsv = Color.HSVToRGB(1f / localTotal * (index % localTotal), 1, 1); + panelColor = hsv.Desaturate(0.48f) / 1.18f; + break; + default: + panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); + break; + } + } + return panelColor; + } public static bool AddComponentButtons(Rect position) { position = RectUtility.AddPadding(position, 20f, 20f, 12f, 2f); @@ -352,7 +409,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } if (isWithFoldout == false || IsShowRuntimeComponents) { - if (EcsGUI.Layout.AddComponentButtons()) + if (AddComponentButtons()) { GenericMenu genericMenu = RuntimeComponentsUtility.GetAddComponentGenericMenu(world); RuntimeComponentsUtility.CurrentEntityID = entityID; diff --git a/src/Internal/Utils/RectUtility.cs b/src/Internal/Utils/RectUtility.cs index e341fbf..82e033e 100644 --- a/src/Internal/Utils/RectUtility.cs +++ b/src/Internal/Utils/RectUtility.cs @@ -4,7 +4,7 @@ namespace DCFApixels.DragonECS.Unity.Internal { internal static class RectUtility { - public static (Rect, Rect) HorizontalSliceLerp(Rect rect, float t) + public static (Rect, Rect) HorizontalSliceLerp(in this Rect rect, float t) { Rect l = rect; Rect r = rect; @@ -12,7 +12,7 @@ namespace DCFApixels.DragonECS.Unity.Internal r.xMin += rect.width * t; return (l, r); } - public static (Rect, Rect) HorizontalSliceLeft(Rect rect, float with) + public static (Rect, Rect) HorizontalSliceLeft(in this Rect rect, float with) { Rect l = rect; Rect r = rect; @@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS.Unity.Internal r.xMin += with; return (l, r); } - public static (Rect, Rect) HorizontalSliceRight(Rect rect, float with) + public static (Rect, Rect) HorizontalSliceRight(in this Rect rect, float with) { Rect l = rect; Rect r = rect; @@ -29,7 +29,7 @@ namespace DCFApixels.DragonECS.Unity.Internal return (l, r); } - public static (Rect, Rect) VerticalSliceTop(Rect rect, float height) + public static (Rect, Rect) VerticalSliceTop(in this Rect rect, float height) { Rect t = rect; Rect b = rect; @@ -37,7 +37,7 @@ namespace DCFApixels.DragonECS.Unity.Internal b.yMin += height; return (t, b); } - public static (Rect, Rect) VerticalSliceBottom(Rect rect, float height) + public static (Rect, Rect) VerticalSliceBottom(in this Rect rect, float height) { Rect t = rect; Rect b = rect; @@ -46,28 +46,30 @@ namespace DCFApixels.DragonECS.Unity.Internal return (t, b); } - public static Rect AddPadding(Rect rect, float verticalHorizontal) + public static Rect AddPadding(in this Rect rect, float verticalHorizontal) { return AddPadding(rect, verticalHorizontal, verticalHorizontal, verticalHorizontal, verticalHorizontal); } - public static Rect AddPadding(Rect rect, float horizontal, float vertical) + public static Rect AddPadding(in this Rect rect, float horizontal, float vertical) { return AddPadding(rect, horizontal, horizontal, vertical, vertical); } - public static Rect AddPadding(Rect rect, float left, float right, float top, float bottom) + public static Rect AddPadding(in this Rect rect, float left, float right, float top, float bottom) { - rect.xMin += left; - rect.xMax -= right; - rect.yMin += top; - rect.yMax -= bottom; + Rect result = rect; + result.xMin += left; + result.xMax -= right; + result.yMin += top; + result.yMax -= bottom; + return result; + } + public static Rect Move(in this Rect rect, Vector2 addVector) + { + Rect result = rect; + result.center += addVector; return rect; } - public static Rect Move(Rect rect, Vector2 addVector) - { - rect.center += addVector; - return rect; - } - public static Rect Move(Rect rect, float addX, float addY) + public static Rect Move(in this Rect rect, float addX, float addY) { return Move(rect, new Vector2(addX, addY)); } From 90cda16424bcf8d89e4f803dff06025f6d68fa03 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 19:59:57 +0800 Subject: [PATCH 05/10] update --- src/Buildin/UnityComponents.cs | 10 ++++- ...ribute.cs => ComponentTemplateProperty.cs} | 11 +++-- ...meta => ComponentTemplateProperty.cs.meta} | 0 ....cs => ComponentTemplatePropertyDrawer.cs} | 37 ++++++++-------- ...> ComponentTemplatePropertyDrawer.cs.meta} | 0 src/Internal/Editor/EcsGUI.cs | 42 ++++++------------- 6 files changed, 47 insertions(+), 53 deletions(-) rename src/EntityTemplate/{ComponentTemplateReferenceAttribute.cs => ComponentTemplateProperty.cs} (93%) rename src/EntityTemplate/{ComponentTemplateReferenceAttribute.cs.meta => ComponentTemplateProperty.cs.meta} (100%) rename src/EntityTemplate/Editor/{ComponentTemplateReferenceDrawer.cs => ComponentTemplatePropertyDrawer.cs} (89%) rename src/EntityTemplate/Editor/{ComponentTemplateReferenceDrawer.cs.meta => ComponentTemplatePropertyDrawer.cs.meta} (100%) diff --git a/src/Buildin/UnityComponents.cs b/src/Buildin/UnityComponents.cs index e6a17f3..f71ad55 100644 --- a/src/Buildin/UnityComponents.cs +++ b/src/Buildin/UnityComponents.cs @@ -1,23 +1,27 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using UnityEngine; namespace DCFApixels.DragonECS { internal static class UnityComponentConsts { - private const string UNITY_COMPONENT_NAME = "UnityComponent"; + internal const string UNITY_COMPONENT_NAME = "UnityComponent"; public static readonly MetaGroup BaseGroup = new MetaGroup(UNITY_COMPONENT_NAME); public static readonly MetaGroup ColliderGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Collider/"); public static readonly MetaGroup JointGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Joint/"); } [Serializable] [MetaColor(255 / 3, 255, 0)] + [MetaDescription("Component-reference to Unity object for EcsPool")] + [MetaGroup(UnityComponentConsts.UNITY_COMPONENT_NAME)] public struct UnityComponent : IEcsComponent, IEnumerable//IntelliSense hack where T : Component { public T obj; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnityComponent(T obj) { this.obj = obj; @@ -30,6 +34,10 @@ namespace DCFApixels.DragonECS { throw new NotImplementedException(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator T(UnityComponent a) { return a.obj; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator UnityComponent(T a) { return new UnityComponent(a); } } #region Unity Component Templates diff --git a/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs b/src/EntityTemplate/ComponentTemplateProperty.cs similarity index 93% rename from src/EntityTemplate/ComponentTemplateReferenceAttribute.cs rename to src/EntityTemplate/ComponentTemplateProperty.cs index 3a3c372..c467896 100644 --- a/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs +++ b/src/EntityTemplate/ComponentTemplateProperty.cs @@ -9,11 +9,11 @@ namespace DCFApixels.DragonECS { [SerializeReference, ComponentTemplateReference] private IComponentTemplate _template; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ComponentTemplateProperty(IComponentTemplate template) { _template = template; } - public IComponentTemplate Template { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -41,27 +41,26 @@ namespace DCFApixels.DragonECS public void OnValidate(UnityEngine.Object obj) { _template.OnValidate(obj); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetRaw(object raw) { _template.SetRaw(raw); } - public bool Equals(ComponentTemplateProperty other) { return _template == other._template; } + public override bool Equals(object obj) + { + return obj is ComponentTemplateProperty other && Equals(other); + } public override int GetHashCode() { return _template.GetHashCode(); } public static bool operator ==(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template == b._template; } public static bool operator !=(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template != b._template; } - public static bool operator ==(ComponentTemplateProperty a, Null? b) { return a.IsNull; } public static bool operator ==(Null? a, ComponentTemplateProperty b) { return b.IsNull; } - public static bool operator !=(ComponentTemplateProperty a, Null? b) { return !a.IsNull; } public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; } - public readonly struct Null { } } - public sealed class ComponentTemplateReferenceAttribute : PropertyAttribute { } } \ No newline at end of file diff --git a/src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta b/src/EntityTemplate/ComponentTemplateProperty.cs.meta similarity index 100% rename from src/EntityTemplate/ComponentTemplateReferenceAttribute.cs.meta rename to src/EntityTemplate/ComponentTemplateProperty.cs.meta diff --git a/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs similarity index 89% rename from src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs rename to src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs index 88afa19..2552384 100644 --- a/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs +++ b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs @@ -7,9 +7,23 @@ using UnityEngine; namespace DCFApixels.DragonECS.Unity.Editors { - + [CustomPropertyDrawer(typeof(ComponentTemplateProperty), true)] + internal class ComponentTemplatePropertyDrawer : PropertyDrawer + { + private ComponentTemplateReferenceDrawer _drawer = new ComponentTemplateReferenceDrawer(); + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + property.Next(true); + return _drawer.GetPropertyHeight(property, label); + } + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + property.Next(true); + _drawer.OnGUI(position, property, label); + } + } [CustomPropertyDrawer(typeof(ComponentTemplateReferenceAttribute), true)] - public class ComponentTemplateReferenceDrawer : PropertyDrawer + internal class ComponentTemplateReferenceDrawer : PropertyDrawer { private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f); @@ -19,6 +33,7 @@ namespace DCFApixels.DragonECS.Unity.Editors private static bool _isInit; private static GenericMenu _genericMenu; + #region Init private static void Init() { @@ -64,7 +79,6 @@ namespace DCFApixels.DragonECS.Unity.Editors } #endregion - public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { IComponentTemplate template = property.managedReferenceValue as IComponentTemplate; @@ -90,19 +104,9 @@ namespace DCFApixels.DragonECS.Unity.Editors return DamagedComponentHeight; } - var propsCounter = property.Copy(); - int lastDepth = propsCounter.depth; - bool next = propsCounter.Next(true) && lastDepth < propsCounter.depth; - int propCount = next ? -1 : 0; - while (next) - { - propCount++; - next = propsCounter.Next(false); - } - bool isEmpty = propCount <= 0; + int propCount = EcsGUI.GetChildPropertiesCount(property); - - return (isEmpty ? EditorGUIUtility.singleLineHeight : EditorGUI.GetPropertyHeight(property, label)) + Padding * 4f; + return (propCount <= 0 ? EditorGUIUtility.singleLineHeight : EditorGUI.GetPropertyHeight(property, label)) + Padding * 4f; } @@ -167,7 +171,7 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorGUI.BeginChangeCheck(); - GUI.Box(position, "", UnityEditorUtility.GetStyle(alphaPanelColor)); + EditorGUI.DrawRect(position, alphaPanelColor); Rect paddingPosition = RectUtility.AddPadding(position, Padding * 2f); @@ -233,7 +237,6 @@ namespace DCFApixels.DragonECS.Unity.Editors private void DrawSelectionPopup(Rect position, SerializedProperty componentRefProp, GUIContent label) { EditorGUI.LabelField(position, label); - //Rect buttonRect = RectUtility.AddPadding(position, EditorGUIUtility.labelWidth, 20f, 0f, 0f); Rect buttonRect = RectUtility.AddPadding(position, EditorGUIUtility.labelWidth, 0f, 0f, 0f); if (GUI.Button(buttonRect, "Select")) { diff --git a/src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs.meta similarity index 100% rename from src/EntityTemplate/Editor/ComponentTemplateReferenceDrawer.cs.meta rename to src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs.meta diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 4f5938e..cc9fbe0 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -4,6 +4,8 @@ using System; using System.Reflection; using UnityEditor; using UnityEngine; +using UnityObject = UnityEngine.Object; +using UnityComponent = UnityEngine.Component; namespace DCFApixels.DragonECS.Unity.Editors { @@ -339,6 +341,10 @@ namespace DCFApixels.DragonECS.Unity.Editors public static class Layout { + public static void DrawEmptyComponentProperty(bool isDisplayEmpty) + { + + } public static void DrawWorldBaseInfo(EcsWorld world) { bool isNull = world == null || world.IsDestroyed || world.id == 0; @@ -436,30 +442,8 @@ namespace DCFApixels.DragonECS.Unity.Editors if (meta.IsHidden == false || IsShowHidden) { object data = pool.GetRaw(entityID); - //Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); - Color panelColor; - if (meta.IsCustomColor) - { - panelColor = meta.Color.ToUnityColor(); - } - else - { - switch (AutoColorMode) - { - case ComponentColorMode.Auto: - panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; - break; - case ComponentColorMode.Rainbow: - Color hsv = Color.HSVToRGB(1f / (Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE)) * index, 1, 1); - panelColor = hsv.Desaturate(0.48f) / 1.18f; - break; - default: - panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); - break; - } - } - panelColor = panelColor.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); + Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); float padding = EditorGUIUtility.standardVerticalSpacing; Rect removeButtonRect = GUILayoutUtility.GetLastRect(); @@ -472,7 +456,7 @@ namespace DCFApixels.DragonECS.Unity.Editors removeButtonRect.yMax += RemoveButtonRect.height; removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width; removeButtonRect.center += Vector2.up * padding * 2f; - if (EcsGUI.CloseButton(removeButtonRect)) + if (CloseButton(removeButtonRect)) { isRemoveComponent = true; } @@ -497,7 +481,7 @@ namespace DCFApixels.DragonECS.Unity.Editors Rect tooltipIconRect = TooltipIconRect; tooltipIconRect.center = removeButtonRect.center; tooltipIconRect.center -= Vector2.right * tooltipIconRect.width; - EcsGUI.DescriptionIcon(tooltipIconRect, meta.Description.Text); + DescriptionIcon(tooltipIconRect, meta.Description.Text); } GUILayout.EndVertical(); @@ -509,7 +493,7 @@ namespace DCFApixels.DragonECS.Unity.Editors outData = data; Type type = data == null ? typeof(void) : data.GetType(); - bool isUnityObject = typeof(UnityEngine.Object).IsAssignableFrom(fieldType); + bool isUnityObject = typeof(UnityObject).IsAssignableFrom(fieldType); if (isUnityObject == false && data == null) { @@ -546,12 +530,12 @@ namespace DCFApixels.DragonECS.Unity.Editors if (isUnityObject) { EditorGUI.BeginChangeCheck(); - var uobj = (UnityEngine.Object)data; + var uobj = (UnityObject)data; - bool isComponent = (typeof(UnityEngine.Component)).IsAssignableFrom(fieldType); + bool isComponent = typeof(UnityComponent).IsAssignableFrom(fieldType); if (isComponent) { - uobj = EditorGUILayout.ObjectField(label, uobj, typeof(UnityEngine.Object), true); + uobj = EditorGUILayout.ObjectField(label, uobj, typeof(UnityObject), true); } else { From 2dd92d3dc6df5b0a374676f3ca8e32fbfe7eb2e6 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 20:31:06 +0800 Subject: [PATCH 06/10] update --- src/Buildin/UnityComponents.cs | 2 +- .../ComponentTemplateProperty.cs | 25 +++++++++---------- .../Templates/ComponentTemplateBase.cs | 6 +---- src/Internal/Editor/EcsGUI.cs | 16 +++++------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/Buildin/UnityComponents.cs b/src/Buildin/UnityComponents.cs index f71ad55..c0cd18f 100644 --- a/src/Buildin/UnityComponents.cs +++ b/src/Buildin/UnityComponents.cs @@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS } [Serializable] [MetaColor(255 / 3, 255, 0)] - [MetaDescription("Component-reference to Unity object for EcsPool")] + [MetaDescription(EcsConsts.AUTHOR, "Component-reference to Unity object for EcsPool")] [MetaGroup(UnityComponentConsts.UNITY_COMPONENT_NAME)] public struct UnityComponent : IEcsComponent, IEnumerable//IntelliSense hack where T : Component diff --git a/src/EntityTemplate/ComponentTemplateProperty.cs b/src/EntityTemplate/ComponentTemplateProperty.cs index c467896..0a382fb 100644 --- a/src/EntityTemplate/ComponentTemplateProperty.cs +++ b/src/EntityTemplate/ComponentTemplateProperty.cs @@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS [Serializable] public struct ComponentTemplateProperty : IEquatable { - [SerializeReference, ComponentTemplateReference] + [SerializeReference] private IComponentTemplate _template; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ComponentTemplateProperty(IComponentTemplate template) @@ -41,23 +41,22 @@ namespace DCFApixels.DragonECS public void OnValidate(UnityEngine.Object obj) { _template.OnValidate(obj); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetRaw(object raw) { _template.SetRaw(raw); } - public bool Equals(ComponentTemplateProperty other) - { - return _template == other._template; - } - public override bool Equals(object obj) - { - return obj is ComponentTemplateProperty other && Equals(other); - } - public override int GetHashCode() - { - return _template.GetHashCode(); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(ComponentTemplateProperty other) { return _template == other._template; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() { return _template.GetHashCode(); } + public override bool Equals(object obj) { return obj is ComponentTemplateProperty other && Equals(other); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template == b._template; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(ComponentTemplateProperty a, ComponentTemplateProperty b) { return a._template != b._template; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(ComponentTemplateProperty a, Null? b) { return a.IsNull; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Null? a, ComponentTemplateProperty b) { return b.IsNull; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(ComponentTemplateProperty a, Null? b) { return !a.IsNull; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; } public readonly struct Null { } } diff --git a/src/EntityTemplate/Templates/ComponentTemplateBase.cs b/src/EntityTemplate/Templates/ComponentTemplateBase.cs index e8105d1..a9b9364 100644 --- a/src/EntityTemplate/Templates/ComponentTemplateBase.cs +++ b/src/EntityTemplate/Templates/ComponentTemplateBase.cs @@ -33,9 +33,7 @@ namespace DCFApixels.DragonECS { #region Properties public abstract Type Type { get; } - public virtual bool IsCustomName { get { return false; } } public virtual string Name { get { return string.Empty; } } - public virtual bool IsCustomColor { get { return false; } } public virtual MetaColor Color { get { return new MetaColor(MetaColor.Black); } } public virtual MetaGroup Group { get { return MetaGroup.Empty; } } public virtual MetaDescription Description { get { return MetaDescription.Empty; } } @@ -59,10 +57,8 @@ namespace DCFApixels.DragonECS protected T component; #region Properties - public override Type Type { get { return typeof(T); } } - public override bool IsCustomName { get { return Meta.IsCustomName; } } + public sealed override Type Type { get { return typeof(T); } } public override string Name { get { return Meta.Name; } } - public override bool IsCustomColor { get { return Meta.IsCustomColor; } } public override MetaColor Color { get { return Meta.Color; } } public override MetaGroup Group { get { return Meta.Group; } } public override MetaDescription Description { get { return Meta.Description; } } diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index cc9fbe0..0ad07d1 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -294,29 +294,25 @@ namespace DCFApixels.DragonECS.Unity.Editors } public static Color SelectPanelColor(ITypeMeta meta, int index, int total) { - Color panelColor; - if (meta.IsCustomColor) + var trueMeta = meta.Type.ToMeta(); + if (trueMeta.IsCustomColor || meta.Color != trueMeta.Color) { - panelColor = meta.Color.ToUnityColor(); + return meta.Color.ToUnityColor(); } else { switch (AutoColorMode) { case ComponentColorMode.Auto: - panelColor = meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; - break; + return meta.Color.ToUnityColor().Desaturate(0.48f) / 1.18f; //.Desaturate(0.48f) / 1.18f; case ComponentColorMode.Rainbow: int localTotal = Mathf.Max(total, EscEditorConsts.AUTO_COLOR_RAINBOW_MIN_RANGE); Color hsv = Color.HSVToRGB(1f / localTotal * (index % localTotal), 1, 1); - panelColor = hsv.Desaturate(0.48f) / 1.18f; - break; + return hsv.Desaturate(0.48f) / 1.18f; default: - panelColor = index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); - break; + return index % 2 == 0 ? new Color(0.40f, 0.40f, 0.40f) : new Color(0.54f, 0.54f, 0.54f); } } - return panelColor; } public static bool AddComponentButtons(Rect position) { From 24ac089d1ec89bb10f6d622124c4bdbce9173f99 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 23:27:45 +0800 Subject: [PATCH 07/10] update --- .../Editor/ComponentTemplatePropertyDrawer.cs | 13 +--------- .../Editor/EntityTemplateEditor.cs | 14 +--------- src/Internal/Editor/EcsGUI.cs | 26 +++++++++++++++++-- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs index 2552384..d16f9ab 100644 --- a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs +++ b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs @@ -188,18 +188,7 @@ namespace DCFApixels.DragonECS.Unity.Editors if (propCount <= 0) { label.text = $"{label.text} ({name})"; - EditorGUI.LabelField(paddingPosition, label); - Rect emptyPos = paddingPosition; - emptyPos.xMin += EditorGUIUtility.labelWidth; - if (isEmpty) - { - using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) - { - GUI.Label(emptyPos, "empty"); - } - } - EditorGUI.BeginProperty(paddingPosition, label, componentRefProp); - EditorGUI.EndProperty(); + EcsGUI.DrawEmptyComponentProperty(paddingPosition, componentRefProp, label.text, isEmpty); } else { diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index f5654e8..5b5ac16 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -194,19 +194,7 @@ namespace DCFApixels.DragonECS.Unity.Editors if (propCount <= 0) { - GUIContent label = UnityEditorUtility.GetLabel(name); - EditorGUILayout.LabelField(name); - Rect emptyPos = GUILayoutUtility.GetLastRect(); - emptyPos.xMin += EditorGUIUtility.labelWidth; - if (isEmpty) - { - using (new EcsGUI.ContentColorScope(1f, 1f, 1f, 0.4f)) - { - GUI.Label(emptyPos, "empty"); - } - } - EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), label, componentRefProp); - EditorGUI.EndProperty(); + EcsGUI.Layout.DrawEmptyComponentProperty(componentRefProp, name, isEmpty); } else { diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 0ad07d1..9b900d6 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -335,11 +335,33 @@ namespace DCFApixels.DragonECS.Unity.Editors return AddClearComponentButton.None; } + public static void DrawEmptyComponentProperty(Rect position, SerializedProperty property, string name, bool isDisplayEmpty) + { + DrawEmptyComponentProperty(position, property, UnityEditorUtility.GetLabel(name), isDisplayEmpty); + } + public static void DrawEmptyComponentProperty(Rect position, SerializedProperty property, GUIContent label, bool isDisplayEmpty) + { + EditorGUI.LabelField(position, label); + if (isDisplayEmpty) + { + using (SetContentColor(1f, 1f, 1f, 0.4f)) + { + GUI.Label(position.AddPadding(EditorGUIUtility.labelWidth, 0, 0, 0), "empty"); + } + } + EditorGUI.BeginProperty(position, label, property); + EditorGUI.EndProperty(); + } + public static class Layout { - public static void DrawEmptyComponentProperty(bool isDisplayEmpty) + public static void DrawEmptyComponentProperty(SerializedProperty property, string name, bool isDisplayEmpty) { - + EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(UnityEditorUtility.GetLabel(name), EditorStyles.label), property, name, isDisplayEmpty); + } + public static void DrawEmptyComponentProperty(SerializedProperty property, GUIContent label, bool isDisplayEmpty) + { + EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(label, EditorStyles.label), property, label, isDisplayEmpty); } public static void DrawWorldBaseInfo(EcsWorld world) { From f8a80a0a720c3ad8323f615b03a0f525be5ac051 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 16 May 2024 23:52:34 +0800 Subject: [PATCH 08/10] up version to 0.3.18 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d731f3..b36bc47 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "displayName": "DragonECS-Unity", "description": "Integration with Unity for DragonECS", "unity": "2021.2", - "version": "0.3.16", + "version": "0.3.18", "repository": { "type": "git", "url": "https://github.com/DCFApixels/DragonECS-Unity.git" From 0b5a6a82470b4f84930f78ea85ea0fe1c803b371 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 17 May 2024 00:18:44 +0800 Subject: [PATCH 09/10] fix display for odin --- .../Editor/ComponentTemplatePropertyDrawer.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs index d16f9ab..3546089 100644 --- a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs +++ b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs @@ -28,6 +28,7 @@ namespace DCFApixels.DragonECS.Unity.Editors private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f); private float Padding => EditorGUIUtility.standardVerticalSpacing; + private float SingleLineWithPadding => EditorGUIUtility.singleLineHeight + Padding * 4f; private const float DamagedComponentHeight = 18f * 2f; @@ -162,7 +163,7 @@ namespace DCFApixels.DragonECS.Unity.Editors string name = meta.Name; string description = meta.Description.Text; - int propCount = EcsGUI.GetChildPropertiesCount(componentProperty, componentType, out bool isEmpty); + int propCount = EcsGUI.GetChildPropertiesCount(componentProperty); Color panelColor = EcsGUI.SelectPanelColor(meta, positionCountr, -1).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE); @@ -187,12 +188,10 @@ namespace DCFApixels.DragonECS.Unity.Editors if (propCount <= 0) { - label.text = $"{label.text} ({name})"; - EcsGUI.DrawEmptyComponentProperty(paddingPosition, componentRefProp, label.text, isEmpty); + EcsGUI.DrawEmptyComponentProperty(paddingPosition, componentRefProp, label, false); } else { - label.text = $"{label.text} ({name})"; if (componentProperty.propertyType == SerializedPropertyType.Generic) { EditorGUI.PropertyField(paddingPosition, componentProperty, label, true); @@ -203,6 +202,18 @@ namespace DCFApixels.DragonECS.Unity.Editors EditorGUI.PropertyField(r, componentProperty, label, true); } } + if (string.IsNullOrEmpty(label.text)) + { + EditorGUI.indentLevel++; + EditorGUI.PrefixLabel(position.AddPadding(0, 0, 0, position.height - SingleLineWithPadding), UnityEditorUtility.GetLabel(name)); + EditorGUI.indentLevel--; + } + else + { + GUI.Label(position.AddPadding(EditorGUIUtility.labelWidth, 0, 0, position.height - SingleLineWithPadding), name); + } + + if (isRemoveComponent) { componentRefProp.managedReferenceValue = null; From 04ad7ad8ca4f2b168e2b33c60d707f41ee3e537d Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 17 May 2024 00:21:57 +0800 Subject: [PATCH 10/10] up version to 0.3.19 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b36bc47..ff23ab7 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "displayName": "DragonECS-Unity", "description": "Integration with Unity for DragonECS", "unity": "2021.2", - "version": "0.3.18", + "version": "0.3.19", "repository": { "type": "git", "url": "https://github.com/DCFApixels/DragonECS-Unity.git"