From 8ccd95ea0ff9af1fd3dc67e012acc2bfd0067226 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:29:48 +0800 Subject: [PATCH] update ref repairer --- src/Buildin/UnityComponent.cs | 1 + src/Connectors/EcsEntityConnect.cs | 4 +- src/Connectors/GameObjectConnect.cs | 1 + src/Internal/Editor/EcsGUI.cs | 1 + src/Internal/ScriptsCache.cs | 1 - .../RefRepairer/Editor/RefRepairerWindow.cs | 181 ++++++++++++------ 6 files changed, 124 insertions(+), 65 deletions(-) diff --git a/src/Buildin/UnityComponent.cs b/src/Buildin/UnityComponent.cs index 7c5a03f..ccc2976 100644 --- a/src/Buildin/UnityComponent.cs +++ b/src/Buildin/UnityComponent.cs @@ -19,6 +19,7 @@ namespace DCFApixels.DragonECS [MetaColor(MetaColor.DragonCyan)] [MetaGroup(EcsUnityConsts.PACK_GROUP, EcsConsts.COMPONENTS_GROUP)] [MetaDescription(EcsConsts.AUTHOR, "Component-reference to Unity object for EcsPool.")] + [MetaTags(MetaTags.ENGINE_MEMBER)] public struct UnityComponent : IEcsComponent, IEnumerable//IntelliSense hack where T : Component { diff --git a/src/Connectors/EcsEntityConnect.cs b/src/Connectors/EcsEntityConnect.cs index 03822fe..99ce7c9 100644 --- a/src/Connectors/EcsEntityConnect.cs +++ b/src/Connectors/EcsEntityConnect.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using UnityEngine; -#region UNITY_EDITOR +#if UNITY_EDITOR using UnityEditor; using DCFApixels.DragonECS.Unity.Internal; using DCFApixels.DragonECS.Unity; -#endregion +#endif namespace DCFApixels.DragonECS { diff --git a/src/Connectors/GameObjectConnect.cs b/src/Connectors/GameObjectConnect.cs index c768a8c..81bf4a4 100644 --- a/src/Connectors/GameObjectConnect.cs +++ b/src/Connectors/GameObjectConnect.cs @@ -11,6 +11,7 @@ namespace DCFApixels.DragonECS [MetaID("14AC6B239201C6A60337AF3384D237E7")] [MetaGroup(EcsUnityConsts.PACK_GROUP, EcsConsts.COMPONENTS_GROUP)] [MetaDescription(EcsConsts.AUTHOR, "This component is automatically added if an entity is connected to one of the EcsEntityConnect. It also contains a reference to the connected EcsEntityConnect.")] + [MetaTags(MetaTags.ENGINE_MEMBER)] public readonly struct GameObjectConnect : IEcsComponent, IEcsComponentLifecycle { public readonly EcsEntityConnect Connect; diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index a988ead..9797a98 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -235,6 +235,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public static FontStyleScope SetFontStyle(FontStyle value) => new FontStyleScope(GUI.skin.label, value); public static FontStyleScope SetFontStyle(GUIStyle target) => new FontStyleScope(target); public static FontSizeScope SetFontSize(GUIStyle target, int value) => new FontSizeScope(target, value); + public static FontSizeScope SetFontSize(int value) => new FontSizeScope(GUI.skin.label, value); public static FontSizeScope SetFontSize(GUIStyle target) => new FontSizeScope(target); public static AlignmentScope SetAlignment(GUIStyle target, TextAnchor value) => new AlignmentScope(target, value); public static AlignmentScope SetAlignment(TextAnchor value) => new AlignmentScope(GUI.skin.label, value); diff --git a/src/Internal/ScriptsCache.cs b/src/Internal/ScriptsCache.cs index ea37bb7..22ed304 100644 --- a/src/Internal/ScriptsCache.cs +++ b/src/Internal/ScriptsCache.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using UnityEditor; -using UnityEditorInternal; using UnityEngine; namespace DCFApixels.DragonECS.Unity.Editors diff --git a/src/Tools/RefRepairer/Editor/RefRepairerWindow.cs b/src/Tools/RefRepairer/Editor/RefRepairerWindow.cs index 78eeb5e..8e139fd 100644 --- a/src/Tools/RefRepairer/Editor/RefRepairerWindow.cs +++ b/src/Tools/RefRepairer/Editor/RefRepairerWindow.cs @@ -15,6 +15,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors [MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)] public static void Open() { + _isNoFound = false; var wnd = GetWindow(); wnd.titleContent = new GUIContent(TITLE); wnd.minSize = new Vector2(140f, 140f); @@ -147,81 +148,137 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors private Vector2 _scrollViewPosition; + private static bool _isNoFound = false; + private GUIStyle _panel; + private void OnGUI() { - if (_missingRefContainer.IsEmplty) + //if (_panel == null) { - if (GUILayout.Button("Collect missing references")) + _panel = new GUIStyle(); + _panel.padding = new RectOffset(5, 5, 5, 5); + } + using (EcsGUI.Layout.BeginVertical(_panel)) + { + const string LIST_EMPTY_MESSAGE = "List of Missings is Empty"; + const string COLLECT_BUTTON = "Collect Missings"; + if (_missingRefContainer.IsEmplty) { - if (TryInit()) + GUILayout.Label("", GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); + using (EcsGUI.SetFontSize(14)) + using (EcsGUI.SetFontSize(GUI.skin.button, 14)) + using (EcsGUI.SetAlignment(value: TextAnchor.MiddleCenter)) { - _missingRefContainer.Collect(); - _cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray(); - InitList(); + Vector2 center = GUILayoutUtility.GetLastRect().center; + Vector2 labelSize = GUI.skin.label.CalcSize(UnityEditorUtility.GetLabel(LIST_EMPTY_MESSAGE)); + Vector2 buttonSize = GUI.skin.button.CalcSize(UnityEditorUtility.GetLabel(COLLECT_BUTTON)); + labelSize *= 1.2f; + buttonSize *= 1.2f; + Rect r; + r = new Rect(Vector2.zero, labelSize); + r.center = center; + r.y -= labelSize.y / 2f; + GUI.Label(r, LIST_EMPTY_MESSAGE); + r = new Rect(Vector2.zero, buttonSize); + r.center = center; + r.y += buttonSize.y / 2f; + if (Event.current.type == EventType.MouseDown && EcsGUI.HitTest(r)) + { + _isNoFound = false; + } + if (GUI.Button(r, COLLECT_BUTTON, GUI.skin.button)) + { + if (TryInit()) + { + _missingRefContainer.Collect(); + _cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray(); + InitList(); + if (_missingRefContainer.IsEmplty) + { + _isNoFound = true; + } + } + } + + GUIContent label = UnityEditorUtility.GetLabel("Missing references not found in the project."); + labelSize = GUI.skin.label.CalcSize(label); + r.y += labelSize.y * 1.1f; + r.xMin -= labelSize.x / 2f; + r.xMax += labelSize.x / 2f; + if (_isNoFound) + { + GUI.Label(r, label); + } + } + return; + } + + if (_missingRefContainer.MissingsResolvingDatas.Count != _cachedMissingsResolvingDatas.Length) + { + _cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray(); + InitList(); + } + + var bc = EcsGUI.SetBackgroundColor(Color.black, 0.5f); + using (EcsGUI.Layout.BeginVertical(EditorStyles.helpBox)) + { + bc.Dispose(); + _scrollViewPosition = GUILayout.BeginScrollView(_scrollViewPosition, GUILayout.ExpandHeight(true)); + _reorderableResolvingDataList.DoLayoutList(); + GUILayout.EndScrollView(); + } + GUILayout.Space(4f); + + using (EcsGUI.Layout.BeginVertical(GUILayout.ExpandHeight(false))) + { + //GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandHeight(false)); + + var data = _selectedMissingsResolvingData; + Rect rect = GUILayoutUtility.GetRect( + EditorGUIUtility.currentViewWidth, + (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 3f + EditorGUIUtility.standardVerticalSpacing * 2f) + .AddPadding(EditorGUIUtility.standardVerticalSpacing); + + + if (data == null) + { + using (EcsGUI.SetAlignment(TextAnchor.MiddleCenter)) + { + GUI.Label(rect, "Select any record"); + } + } + else + { + using (EcsGUI.CheckChanged()) + { + rect.height = EditorGUIUtility.singleLineHeight; + rect = rect.Move(0, EditorGUIUtility.standardVerticalSpacing); + string ClassName = DrawEditableLine(rect, "Name:", data.OldTypeData.ClassName, data.NewTypeData.ClassName); + rect = rect.Move(0, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); + string NamespaceName = DrawEditableLine(rect, "Namespace:", data.OldTypeData.NamespaceName, data.NewTypeData.NamespaceName); + rect = rect.Move(0, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); + string AssemblyName = DrawEditableLine(rect, "Assembly:", data.OldTypeData.AssemblyName, data.NewTypeData.AssemblyName); + if (EcsGUI.Changed) + { + data.NewTypeData = new Internal.TypeData(ClassName, NamespaceName, AssemblyName); + } + } } } - return; - } - if (GUILayout.Button("Repaire missing references")) - { - _selectedMissingsResolvingData = null; - RepaireFileUtility.RepaieAsset(_missingRefContainer); - } - - if (_missingRefContainer.MissingsResolvingDatas.Count != _cachedMissingsResolvingDatas.Length) - { - _cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray(); - InitList(); - } - - var bc = EcsGUI.SetBackgroundColor(Color.black, 0.5f); - using (EcsGUI.Layout.BeginVertical(EditorStyles.helpBox)) - { - bc.Dispose(); - _scrollViewPosition = GUILayout.BeginScrollView(_scrollViewPosition, GUILayout.ExpandHeight(true)); - _reorderableResolvingDataList.DoLayoutList(); - GUILayout.EndScrollView(); - } - - - - GUILayout.BeginVertical(GUILayout.ExpandHeight(false)); - //GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandHeight(false)); - - var data = _selectedMissingsResolvingData; - Rect rect = GUILayoutUtility.GetRect( - EditorGUIUtility.currentViewWidth, - (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 3f + EditorGUIUtility.standardVerticalSpacing * 2f) - .AddPadding(EditorGUIUtility.standardVerticalSpacing); - - - if (data == null) - { - using (EcsGUI.SetAlignment(TextAnchor.MiddleCenter)) + using (EcsGUI.Layout.BeginHorizontal(GUILayout.Height(26f))) { - GUI.Label(rect, "Select any record"); - } - } - else - { - using (EcsGUI.CheckChanged()) - { - rect.height = EditorGUIUtility.singleLineHeight; - rect = rect.Move(0, EditorGUIUtility.standardVerticalSpacing); - string ClassName = DrawEditableLine(rect, "Name:", data.OldTypeData.ClassName, data.NewTypeData.ClassName); - rect = rect.Move(0, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); - string NamespaceName = DrawEditableLine(rect, "Namespace:", data.OldTypeData.NamespaceName, data.NewTypeData.NamespaceName); - rect = rect.Move(0, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); - string AssemblyName = DrawEditableLine(rect, "Assembly:", data.OldTypeData.AssemblyName, data.NewTypeData.AssemblyName); - if (EcsGUI.Changed) + if (GUILayout.Button("Re-Collect", GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(false))) { - data.NewTypeData = new RefRepairer.Internal.TypeData(ClassName, NamespaceName, AssemblyName); + + } + if (GUILayout.Button("Repaire missing references", GUILayout.ExpandHeight(true))) + { + _selectedMissingsResolvingData = null; + RepaireFileUtility.RepaieAsset(_missingRefContainer); } } } - - GUILayout.EndVertical(); }