From b9bbc65996b4e3311f2c67f679b6fb761a6fe156 Mon Sep 17 00:00:00 2001 From: uurha Date: Mon, 9 Sep 2024 01:59:19 +0200 Subject: [PATCH 1/3] Add InternalCore as submodule --- .gitmodules | 4 ++++ Assets/BetterInternalCore | 1 + Assets/BetterInternalCore.meta | 8 ++++++++ Packages/manifest.json | 1 - Packages/packages-lock.json | 7 ------- 5 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .gitmodules create mode 160000 Assets/BetterInternalCore create mode 100644 Assets/BetterInternalCore.meta diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..116f810 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "BetterInternalCore"] + path = Assets/BetterInternalCore + url = git@github.com:techno-dwarf-works/better-internal-core.git + branch = upm diff --git a/Assets/BetterInternalCore b/Assets/BetterInternalCore new file mode 160000 index 0000000..dd654e2 --- /dev/null +++ b/Assets/BetterInternalCore @@ -0,0 +1 @@ +Subproject commit dd654e230a625f65aa84468bfcc24b6d326521c8 diff --git a/Assets/BetterInternalCore.meta b/Assets/BetterInternalCore.meta new file mode 100644 index 0000000..7270de8 --- /dev/null +++ b/Assets/BetterInternalCore.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d406836cf805ec0428794794275dbebc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/manifest.json b/Packages/manifest.json index fb387a3..a64183a 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,6 +1,5 @@ { "dependencies": { - "com.tdw.better.internal.core": "0.0.2", "com.unity.collab-proxy": "2.0.1", "com.unity.feature.development": "1.0.1", "com.unity.ide.rider": "3.0.18", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 3398798..3172caf 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,12 +1,5 @@ { "dependencies": { - "com.tdw.better.internal.core": { - "version": "0.0.2", - "depth": 0, - "source": "registry", - "dependencies": {}, - "url": "https://package.openupm.com" - }, "com.unity.collab-proxy": { "version": "2.0.1", "depth": 0, From ff74a54a99650e25f4f0c0cbe40f4be6baf0fdcb Mon Sep 17 00:00:00 2001 From: uurha Date: Mon, 9 Sep 2024 04:11:38 +0200 Subject: [PATCH 2/3] Update SerializeReferenceField label search logic --- .../Editor/Drawers/SerializeReferenceField.cs | 137 +++++++----------- 1 file changed, 50 insertions(+), 87 deletions(-) diff --git a/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs b/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs index 3b630ca..8a541d1 100644 --- a/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs +++ b/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs @@ -61,17 +61,8 @@ public SerializeReferenceField(SerializedProperty property, string label) PropertyType = property.propertyType; PropertyField = CreatePropertyField(property, label); -#if !UNITY_2022_2_OR_NEWER - var hasLabel = HasLabel(property); - if (!hasLabel && TryCreateBufferLabel(property, out var bufferLabel)) - { - _bufferLabel = bufferLabel; - Insert(0, _bufferLabel); - } -#endif - Add(PropertyField); - + _updateSchedule = schedule.Execute(Update).Every(_updateInterval); style.FlexGrow(StyleDefinition.OneStyleFloat); RegisterCallback(OnAttachToPanel); @@ -103,12 +94,7 @@ private void Update() } #if !UNITY_2022_2_OR_NEWER - var hasLabel = HasLabel(property); - if (hasLabel && _bufferLabel != null) - { - _bufferLabel.RemoveFromHierarchy(); - _bufferLabel = null; - } + ValidateLabel(property); #endif var newType = property.managedReferenceFullTypename; @@ -127,11 +113,7 @@ private void Update() finally { #if !UNITY_2022_2_OR_NEWER - if (!hasLabel && TryCreateBufferLabel(property, out var label)) - { - _bufferLabel = label; - Insert(0, _bufferLabel); - } + ValidateLabel(property); #endif } @@ -154,6 +136,31 @@ private void Update() property.Dispose(); } + private void ValidateLabel(SerializedProperty property) + { + if (!IsLast()) + { + if (_bufferLabel == null) return; + _bufferLabel.RemoveFromHierarchy(); + _bufferLabel = null; + + return; + } + + var hasLabel = HasLabel(); + switch (hasLabel) + { + case true when _bufferLabel != null: + _bufferLabel.RemoveFromHierarchy(); + _bufferLabel = null; + break; + case false when _bufferLabel == null && TryCreateBufferLabel(property, out var bufferLabel): + _bufferLabel = bufferLabel; + Insert(0, _bufferLabel); + break; + } + } + private void ReactToEditorChange() { UpdateSerializedObjectIfNeeded(); @@ -174,76 +181,21 @@ private void UpdateSerializedObjectIfNeeded() EditorApplication.delayCall += ClearRecentObjects; } - private bool HasLabel(SerializedProperty property) + private bool HasLabel() { - return ValidateBaseField(property); + return HasValidLabel(); } - private bool ValidateBaseField(SerializedProperty property) + private bool IsLast() { - var propertyType = property.propertyType; - switch (propertyType) - { - case SerializedPropertyType.Generic: - return property.isArray && HasValidLabel(); - case SerializedPropertyType.Integer: - return HasValidLabel(); - case SerializedPropertyType.Boolean: - return HasValidLabel(); - case SerializedPropertyType.Float: - return HasValidLabel(); - case SerializedPropertyType.String: - return HasValidLabel(); - case SerializedPropertyType.Color: - return HasValidLabel(); - case SerializedPropertyType.ObjectReference: - return HasValidLabel(); - case SerializedPropertyType.LayerMask: - return HasValidLabel(); - case SerializedPropertyType.Enum: - return HasValidLabel>(); - case SerializedPropertyType.Vector2: - return HasValidLabel(); - case SerializedPropertyType.Vector3: - return HasValidLabel(); - case SerializedPropertyType.Vector4: - return HasValidLabel(); - case SerializedPropertyType.Rect: - return HasValidLabel(); - case SerializedPropertyType.ArraySize: - return HasValidLabel(); - case SerializedPropertyType.Character: - return HasValidLabel(); - case SerializedPropertyType.AnimationCurve: - return HasValidLabel(); - case SerializedPropertyType.Bounds: - return HasValidLabel(); - case SerializedPropertyType.Gradient: - return HasValidLabel(); - case SerializedPropertyType.Quaternion: - return HasValidLabel(); - case SerializedPropertyType.ExposedReference: - return false; - case SerializedPropertyType.FixedBufferSize: - return false; - case SerializedPropertyType.Vector2Int: - return HasValidLabel(); - case SerializedPropertyType.Vector3Int: - return HasValidLabel(); - case SerializedPropertyType.RectInt: - return HasValidLabel(); - case SerializedPropertyType.BoundsInt: - return HasValidLabel(); - case SerializedPropertyType.Hash128: - return HasValidLabel(); - default: - return false; - } + var builder = this.Query().Descendents().Build(); + var query = builder.Last(); + return query == this; } - private bool HasValidLabel() + private bool HasValidLabel() where TBaseField : BaseField { - if (TryGetBaseField(out var baseField)) + if (TryGetBaseField(out var baseField)) { return baseField.labelElement != null; } @@ -251,10 +203,16 @@ private bool HasValidLabel() return false; } - private bool TryGetBaseField(out BaseField baseField) + private bool TryGetBaseField(out BaseField baseField) where TBaseField : BaseField { - baseField = PropertyField.Query().Children>().First(); - var validParent = baseField.parent == PropertyField; + baseField = PropertyField.Query().Children().First(); + + if (baseField == null) + { + return false; + } + + var validParent = baseField.GetFirstAncestorOfType() == PropertyField; if (!validParent) { baseField = null; @@ -334,5 +292,10 @@ private UndoPropertyModification[] OnPropertyModification(UndoPropertyModificati return modifications; } + + ~SerializeReferenceField() + { + _updateSchedule?.Pause(); + } } } \ No newline at end of file From 7ca0b83b4087ec966e3018d44ce893c98b549888 Mon Sep 17 00:00:00 2001 From: uurha Date: Mon, 9 Sep 2024 04:11:49 +0200 Subject: [PATCH 3/3] Update package.json --- Assets/BetterCommons/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/BetterCommons/package.json b/Assets/BetterCommons/package.json index 9759d55..8393767 100644 --- a/Assets/BetterCommons/package.json +++ b/Assets/BetterCommons/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.commons", "displayName": "Better Commons", - "version": "0.0.55", + "version": "0.0.56", "unity": "2021.3", "description": " ", "dependencies": {