From 40fb4613b33e6ec13d1c8d4170e0ca3fe8b121d6 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Fri, 17 Sep 2021 17:18:04 +0200 Subject: [PATCH 01/11] Custom texture field to properly filter texture by dimension (2D, 3D...) --- .../Views/Properties/ObjectPropertyRM.cs | 143 +++++++++--------- .../Views/Properties/TexturePicker.cs | 34 +++++ .../Views/Properties/TexturePicker.cs.meta | 11 ++ .../UIResources/uss/ObjectPropertyRM.uss | 52 +++++++ .../UIResources/uss/ObjectPropertyRM.uss.meta | 11 ++ 5 files changed, 177 insertions(+), 74 deletions(-) create mode 100644 com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs create mode 100644 com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta create mode 100644 com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss create mode 100644 com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss.meta diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index 23f47b29360..e75c9c27526 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -1,34 +1,51 @@ -using System.Collections.Generic; -using System.Reflection; using UnityEngine; -using UnityEngine.Rendering; using UnityEngine.UIElements; -using UnityEditor.UIElements; -using UnityEditor.VFX; -using UnityEditor.VFX.UIElements; -using UnityObject = UnityEngine.Object; -using Type = System.Type; +using UnityObject = UnityEngine.Object; using ObjectField = UnityEditor.VFX.UI.VFXLabeledField; namespace UnityEditor.VFX.UI { class ObjectPropertyRM : PropertyRM { + readonly ObjectField m_ObjectField; + readonly VisualElement m_Container; + readonly TextField m_TextField; + readonly Image m_TextureIcon; + public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base(controller, labelWidth) { - m_ObjectField = new ObjectField(m_Label); - if (controller.portType == typeof(Texture2D) || controller.portType == typeof(Texture3D) || controller.portType == typeof(Cubemap)) - m_ObjectField.control.objectType = typeof(Texture); + + m_Container = new VisualElement(); + m_Container.styleSheets.Add(VFXView.LoadStyleSheet("ObjectPropertyRM")); + + if (typeof(Texture).IsAssignableFrom(m_Provider.portType)) + { + m_Container.style.flexDirection = FlexDirection.Row; + + m_TextField = new TextField { name = "PickLabel", isReadOnly = true, value = m_Value?.name ?? "None (Texture)"}; + var button = new Button { name = "PickButton" }; + var icon = new VisualElement { name = "PickIcon" }; + m_TextureIcon = new Image { name = "TextureIcon" }; + + button.clicked += OnPickObject; + button.Add(icon); + m_TextField.Add(m_TextureIcon); + m_TextField.Add(button); + m_Container.Add(m_TextField); + } else + { + m_ObjectField = new ObjectField(m_Label); m_ObjectField.control.objectType = controller.portType; + m_ObjectField.control.allowSceneObjects = false; + m_ObjectField.style.flexGrow = 1f; + m_ObjectField.style.flexShrink = 1f; + RegisterCallback(StopKeyPropagation); + m_Container.Add(m_ObjectField); + } - m_ObjectField.RegisterCallback>(OnValueChanged); - m_ObjectField.control.allowSceneObjects = false; - m_ObjectField.style.flexGrow = 1f; - m_ObjectField.style.flexShrink = 1f; - RegisterCallback(StopKeyPropagation); - Add(m_ObjectField); + Add(m_Container); } public override float GetPreferredControlWidth() @@ -36,86 +53,64 @@ public override float GetPreferredControlWidth() return 120; } - void StopKeyPropagation(KeyDownEvent e) + public override void UpdateGUI(bool force) { - e.StopPropagation(); + if (m_ObjectField != null) + { + if (force) + m_ObjectField.SetValueWithoutNotify(null); + m_ObjectField.SetValueWithoutNotify(m_Value); + } } - public void OnValueChanged(ChangeEvent onObjectChanged) + public override void SetValue(object obj) // object setvalue should accept null { - UnityObject newValue = m_ObjectField.value; - if (typeof(Texture).IsAssignableFrom(m_Provider.portType)) + try { - Texture tex = newValue as Texture; - - if (tex != null) - { - if (m_Provider.portType == typeof(Texture2D)) - { - if (tex.dimension != TextureDimension.Tex2D) - { - Debug.LogError("Wrong Texture Dimension"); - - newValue = null; - } - } - else if (m_Provider.portType == typeof(Texture3D)) - { - if (tex.dimension != TextureDimension.Tex3D) - { - Debug.LogError("Wrong Texture Dimension"); - - newValue = null; - } - } - else if (m_Provider.portType == typeof(Cubemap)) - { - if (tex.dimension != TextureDimension.Cube) - { - Debug.LogError("Wrong Texture Dimension"); - - newValue = null; - } - } - } + m_Value = (UnityObject)obj; + SelectHandler(m_Value as Texture, false); } - m_Value = newValue; - NotifyValueChanged(); + catch (System.Exception) + { + Debug.Log("Error Trying to convert" + (obj != null ? obj.GetType().Name : "null") + " to " + typeof(UnityObject).Name); + } + + UpdateGUI(!object.ReferenceEquals(m_Value, obj)); } - ObjectField m_ObjectField; + public override bool showsEverything { get { return true; } } protected override void UpdateEnabled() { - m_ObjectField.SetEnabled(propertyEnabled); + m_Container.SetEnabled(propertyEnabled); } protected override void UpdateIndeterminate() { - m_ObjectField.visible = !indeterminate; + m_Container.visible = !indeterminate; } - public override void UpdateGUI(bool force) + void StopKeyPropagation(KeyDownEvent e) { - if (force) - m_ObjectField.SetValueWithoutNotify(null); - m_ObjectField.SetValueWithoutNotify(m_Value); + e.StopPropagation(); } - public override void SetValue(object obj) // object setvalue should accept null + void OnPickObject() { - try - { - m_Value = (UnityObject)obj; - } - catch (System.Exception) + TexturePicker.Pick(m_Provider.portType, SelectHandler); + } + + void SelectHandler(Texture texture, bool isCanceled) + { + if (!isCanceled) { - Debug.Log("Error Trying to convert" + (obj != null ? obj.GetType().Name : "null") + " to " + typeof(UnityObject).Name); + m_Value = texture; + m_TextureIcon.image = texture != null + ? AssetPreview.GetMiniTypeThumbnail(texture) + : AssetPreview.GetMiniTypeThumbnail(typeof(Texture)); + m_TextField.value = m_Value?.name ?? "None (Texture)"; + NotifyValueChanged(); } - - UpdateGUI(!object.ReferenceEquals(m_Value, obj)); } - - public override bool showsEverything { get { return true; } } } } diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs new file mode 100644 index 00000000000..fd9ca809817 --- /dev/null +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; + +using UnityEngine; +using UnityEngine.Search; + + +namespace UnityEditor.VFX.UI +{ + static class TexturePicker + { + internal static void Pick(Type textureType, Action selectHandler) + { + var view = Search.SearchService.ShowObjectPicker( + (x, y) => selectHandler(x as Texture, y), + null, + null, + "Texture", + textureType); + view.itemIconSize = 1f; + + // Until the "viewState" API is made public (should be in 2022.1) we use reflection to remove the inspector button + var quickSearchType = typeof(Search.SearchService).Assembly.GetType("UnityEditor.Search.QuickSearch"); + var viewStateInfo = + quickSearchType?.GetProperty("viewState", BindingFlags.Instance | BindingFlags.NonPublic); + var state = viewStateInfo?.GetValue(view); + if (state != null) + { + var flagsInfo = state.GetType().GetField("flags", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); + flagsInfo?.SetValue(state, SearchViewFlags.DisableInspectorPreview); + } + } + } +} diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta new file mode 100644 index 00000000000..75118e24b7a --- /dev/null +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5d16230795523674f9ceb4a508a001bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss new file mode 100644 index 00000000000..83302325f01 --- /dev/null +++ b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss @@ -0,0 +1,52 @@ +#PickIcon +{ + width: 12px; + height: 12px; + background-image: var(--unity-icons-picker); +} + +#PickButton +{ + margin: 0px 1px 0px -21px; + padding: 0; + border-width: 0; + border-bottom-left-radius: 0px; + border-top-left-radius: 0px; + width:16px; + height:15px; + justify-content: center; + align-items: center; + align-self: center; + background-color: var(--unity-colors-object_field_button-background); +} + +#PickLabel +{ + flex-grow: 1; +} + + +#TextureIcon +{ + margin-left: 2px; + position: absolute; + align-self: center; + width: 12px; + height: 12px; +} + +#PickLabel > TextInput +{ + margin-right: 4px; + padding: 0 22px 0 18px; +} + +#VFXIcon +{ + margin-left: 2px; + position: absolute; + align-self: center; + width: 12px; + height: 12px; + background-image: url("project:///Packages/com.unity.visualeffectgraph/Editor/UIResources/VFX/vfx_graph_icon_gray_dark.png"); +} diff --git a/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss.meta b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss.meta new file mode 100644 index 00000000000..124da0506ed --- /dev/null +++ b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b40791d0947b6d94fbabbb8da581185f +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 From 5afdeced2a084377a458b51e2475b8067a99d7e1 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Fri, 17 Sep 2021 18:29:37 +0200 Subject: [PATCH 02/11] Use the custom object picker for every type, not only textures --- .../Views/Properties/ObjectPropertyRM.cs | 90 ++++++------------- .../Views/Properties/TexturePicker.cs | 8 +- 2 files changed, 31 insertions(+), 67 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index e75c9c27526..64c28aac319 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -2,64 +2,43 @@ using UnityEngine.UIElements; using UnityObject = UnityEngine.Object; -using ObjectField = UnityEditor.VFX.UI.VFXLabeledField; namespace UnityEditor.VFX.UI { class ObjectPropertyRM : PropertyRM { - readonly ObjectField m_ObjectField; readonly VisualElement m_Container; readonly TextField m_TextField; - readonly Image m_TextureIcon; + readonly Image m_ValueIcon; public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base(controller, labelWidth) { - m_Container = new VisualElement(); m_Container.styleSheets.Add(VFXView.LoadStyleSheet("ObjectPropertyRM")); - if (typeof(Texture).IsAssignableFrom(m_Provider.portType)) - { - m_Container.style.flexDirection = FlexDirection.Row; - - m_TextField = new TextField { name = "PickLabel", isReadOnly = true, value = m_Value?.name ?? "None (Texture)"}; - var button = new Button { name = "PickButton" }; - var icon = new VisualElement { name = "PickIcon" }; - m_TextureIcon = new Image { name = "TextureIcon" }; - - button.clicked += OnPickObject; - button.Add(icon); - m_TextField.Add(m_TextureIcon); - m_TextField.Add(button); - m_Container.Add(m_TextField); - } - else - { - m_ObjectField = new ObjectField(m_Label); - m_ObjectField.control.objectType = controller.portType; - m_ObjectField.control.allowSceneObjects = false; - m_ObjectField.style.flexGrow = 1f; - m_ObjectField.style.flexShrink = 1f; - RegisterCallback(StopKeyPropagation); - m_Container.Add(m_ObjectField); - } + m_Container.style.flexDirection = FlexDirection.Row; + + m_TextField = new TextField { name = "PickLabel", isReadOnly = true, value = m_Value?.name ?? "None (Texture)"}; + var button = new Button { name = "PickButton" }; + var icon = new VisualElement { name = "PickIcon" }; + m_ValueIcon = new Image { name = "TextureIcon" }; + + button.clicked += OnPickObject; + button.Add(icon); + m_TextField.Add(m_ValueIcon); + m_TextField.Add(button); + m_Container.Add(m_TextField); Add(m_Container); } - public override float GetPreferredControlWidth() - { - return 120; - } + public override float GetPreferredControlWidth() => 120; public override void UpdateGUI(bool force) { - if (m_ObjectField != null) + if (force) { - if (force) - m_ObjectField.SetValueWithoutNotify(null); - m_ObjectField.SetValueWithoutNotify(m_Value); + NotifyValueChanged(); } } @@ -67,8 +46,11 @@ public override void SetValue(object obj) // object setvalue should accept null { try { - m_Value = (UnityObject)obj; - SelectHandler(m_Value as Texture, false); + m_Value = (Object)obj; + m_ValueIcon.image = obj != null + ? AssetPreview.GetMiniTypeThumbnail(m_Value) + : AssetPreview.GetMiniTypeThumbnail(m_Provider.portType); + m_TextField.value = m_Value?.name ?? $"None ({m_Provider.portType.Name})"; } catch (System.Exception) { @@ -78,37 +60,19 @@ public override void SetValue(object obj) // object setvalue should accept null UpdateGUI(!object.ReferenceEquals(m_Value, obj)); } - public override bool showsEverything { get { return true; } } + public override bool showsEverything => true; - protected override void UpdateEnabled() - { - m_Container.SetEnabled(propertyEnabled); - } + protected override void UpdateEnabled() => m_Container.SetEnabled(propertyEnabled); - protected override void UpdateIndeterminate() - { - m_Container.visible = !indeterminate; - } + protected override void UpdateIndeterminate() => m_Container.visible = !indeterminate; - void StopKeyPropagation(KeyDownEvent e) - { - e.StopPropagation(); - } - - void OnPickObject() - { - TexturePicker.Pick(m_Provider.portType, SelectHandler); - } + void OnPickObject() => TexturePicker.Pick(m_Provider.portType, SelectHandler); - void SelectHandler(Texture texture, bool isCanceled) + void SelectHandler(Object obj, bool isCanceled) { if (!isCanceled) { - m_Value = texture; - m_TextureIcon.image = texture != null - ? AssetPreview.GetMiniTypeThumbnail(texture) - : AssetPreview.GetMiniTypeThumbnail(typeof(Texture)); - m_TextField.value = m_Value?.name ?? "None (Texture)"; + SetValue(obj); NotifyValueChanged(); } } diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs index fd9ca809817..34c65abea89 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs @@ -9,15 +9,15 @@ namespace UnityEditor.VFX.UI { static class TexturePicker { - internal static void Pick(Type textureType, Action selectHandler) + internal static void Pick(Type textureType, Action selectHandler) { var view = Search.SearchService.ShowObjectPicker( - (x, y) => selectHandler(x as Texture, y), + selectHandler, null, null, - "Texture", + textureType.Name, textureType); - view.itemIconSize = 1f; + view.itemIconSize = 3f; // Until the "viewState" API is made public (should be in 2022.1) we use reflection to remove the inspector button var quickSearchType = typeof(Search.SearchService).Assembly.GetType("UnityEditor.Search.QuickSearch"); From f5f71675e736fd32b798f36c2cb93e6215c4f845 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Fri, 17 Sep 2021 19:12:56 +0200 Subject: [PATCH 03/11] Simplified even further the code, renamed class and cleaned up style --- ...TexturePicker.cs => CustomObjectPicker.cs} | 5 ++--- ...ker.cs.meta => CustomObjectPicker.cs.meta} | 2 +- .../Views/Properties/ObjectPropertyRM.cs | 20 +++++++------------ .../UIResources/uss/ObjectPropertyRM.uss | 12 ++--------- 4 files changed, 12 insertions(+), 27 deletions(-) rename com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/{TexturePicker.cs => CustomObjectPicker.cs} (93%) rename com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/{TexturePicker.cs.meta => CustomObjectPicker.cs.meta} (83%) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs similarity index 93% rename from com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs rename to com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index 34c65abea89..be7ff76479e 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -1,13 +1,12 @@ using System; using System.Reflection; -using UnityEngine; using UnityEngine.Search; namespace UnityEditor.VFX.UI { - static class TexturePicker + static class CustomObjectPicker { internal static void Pick(Type textureType, Action selectHandler) { @@ -17,7 +16,7 @@ internal static void Pick(Type textureType, Action sel null, textureType.Name, textureType); - view.itemIconSize = 3f; + view.itemIconSize = 5f; // Until the "viewState" API is made public (should be in 2022.1) we use reflection to remove the inspector button var quickSearchType = typeof(Search.SearchService).Assembly.GetType("UnityEditor.Search.QuickSearch"); diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs.meta similarity index 83% rename from com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta rename to com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs.meta index 75118e24b7a..8762993af72 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/TexturePicker.cs.meta +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5d16230795523674f9ceb4a508a001bd +guid: 98b9e46b09f5f0c41b5a5aeac1a08222 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index 64c28aac319..743d8da66d0 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -7,18 +7,14 @@ namespace UnityEditor.VFX.UI { class ObjectPropertyRM : PropertyRM { - readonly VisualElement m_Container; readonly TextField m_TextField; readonly Image m_ValueIcon; public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base(controller, labelWidth) { - m_Container = new VisualElement(); - m_Container.styleSheets.Add(VFXView.LoadStyleSheet("ObjectPropertyRM")); + styleSheets.Add(VFXView.LoadStyleSheet("ObjectPropertyRM")); - m_Container.style.flexDirection = FlexDirection.Row; - - m_TextField = new TextField { name = "PickLabel", isReadOnly = true, value = m_Value?.name ?? "None (Texture)"}; + m_TextField = new TextField { name = "PickLabel", isReadOnly = true }; var button = new Button { name = "PickButton" }; var icon = new VisualElement { name = "PickIcon" }; m_ValueIcon = new Image { name = "TextureIcon" }; @@ -27,9 +23,7 @@ public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base button.Add(icon); m_TextField.Add(m_ValueIcon); m_TextField.Add(button); - m_Container.Add(m_TextField); - - Add(m_Container); + Add(m_TextField); } public override float GetPreferredControlWidth() => 120; @@ -54,7 +48,7 @@ public override void SetValue(object obj) // object setvalue should accept null } catch (System.Exception) { - Debug.Log("Error Trying to convert" + (obj != null ? obj.GetType().Name : "null") + " to " + typeof(UnityObject).Name); + Debug.Log($"Error Trying to convert {obj?.GetType().Name ?? "null"} to {nameof(Object)}"); } UpdateGUI(!object.ReferenceEquals(m_Value, obj)); @@ -62,11 +56,11 @@ public override void SetValue(object obj) // object setvalue should accept null public override bool showsEverything => true; - protected override void UpdateEnabled() => m_Container.SetEnabled(propertyEnabled); + protected override void UpdateEnabled() => SetEnabled(propertyEnabled); - protected override void UpdateIndeterminate() => m_Container.visible = !indeterminate; + protected override void UpdateIndeterminate() => visible = !indeterminate; - void OnPickObject() => TexturePicker.Pick(m_Provider.portType, SelectHandler); + void OnPickObject() => CustomObjectPicker.Pick(m_Provider.portType, SelectHandler); void SelectHandler(Object obj, bool isCanceled) { diff --git a/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss index 83302325f01..0962f1b6400 100644 --- a/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss +++ b/com.unity.visualeffectgraph/Editor/UIResources/uss/ObjectPropertyRM.uss @@ -23,6 +23,8 @@ #PickLabel { flex-grow: 1; + flex-shrink: 1; + margin: 1px 0; } @@ -40,13 +42,3 @@ margin-right: 4px; padding: 0 22px 0 18px; } - -#VFXIcon -{ - margin-left: 2px; - position: absolute; - align-self: center; - width: 12px; - height: 12px; - background-image: url("project:///Packages/com.unity.visualeffectgraph/Editor/UIResources/VFX/vfx_graph_icon_gray_dark.png"); -} From e4f7623aa01cd92a1a80dbf44cd39fcefed548eb Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Fri, 17 Sep 2021 19:34:26 +0200 Subject: [PATCH 04/11] Updated changelog --- com.unity.visualeffectgraph/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 04717d21ef3..fba7e366224 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Prevent VFX Graph compilation each time a property's min/max value is changed - Prevent vfx re-compilation in some cases when a value has not changed - Eye dropper in the color fields kept updating after pressing the Esc key +- Texture picker lists only textures with expected dimensions (2D, 3D, Cubemap) ## [12.0.0] - 2021-01-11 ### Added From f30099d136f265aefa9c36e84ab171ce51b598f7 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 21 Sep 2021 10:00:54 +0200 Subject: [PATCH 05/11] Added support for drag&drop in custom object field When object is of any type of texture it now also accept RenderTexture --- .../Views/Properties/CustomObjectPicker.cs | 87 ++++++++++++++++--- .../Views/Properties/ObjectPropertyRM.cs | 69 +++++++++++++-- 2 files changed, 141 insertions(+), 15 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index be7ff76479e..0368d2fdfac 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -1,27 +1,26 @@ using System; +using System.Collections.Generic; using System.Reflection; +using UnityEditor.Search; +using UnityEngine; using UnityEngine.Search; +using Object = UnityEngine.Object; namespace UnityEditor.VFX.UI { static class CustomObjectPicker { - internal static void Pick(Type textureType, Action selectHandler) + internal static void Pick(Type type, Action selectHandler) { - var view = Search.SearchService.ShowObjectPicker( - selectHandler, - null, - null, - textureType.Name, - textureType); - view.itemIconSize = 5f; + var view = typeof(Texture).IsAssignableFrom(type) + ? GetTexturePickerView(type, selectHandler) + : GetGenericView(type, selectHandler); // Until the "viewState" API is made public (should be in 2022.1) we use reflection to remove the inspector button var quickSearchType = typeof(Search.SearchService).Assembly.GetType("UnityEditor.Search.QuickSearch"); - var viewStateInfo = - quickSearchType?.GetProperty("viewState", BindingFlags.Instance | BindingFlags.NonPublic); + var viewStateInfo = quickSearchType?.GetProperty("viewState", BindingFlags.Instance | BindingFlags.NonPublic); var state = viewStateInfo?.GetValue(view); if (state != null) { @@ -29,5 +28,73 @@ internal static void Pick(Type textureType, Action sel flagsInfo?.SetValue(state, SearchViewFlags.DisableInspectorPreview); } } + + static ISearchView GetGenericView(Type type, Action selectHandler) + { + return Search.SearchService.ShowObjectPicker( + selectHandler, + null, + null, + type.Name, + type); + } + + static ISearchView GetTexturePickerView(Type type, Action selectHandler) + { + var view = Search.SearchService.ShowPicker( + Search.SearchService.CreateContext(CreateTextureProvider(type)), + (x, y) => selectHandler(x?.ToObject(), y), + null, + null, + null, + type.Name, + 5f); + view.itemIconSize = 5f; + + return view; + } + + static SearchProvider CreateTextureProvider(Type type) + { + return new SearchProvider("tex", "Texture", (context, provider) => FetchTextures(type, context.searchQuery)); + } + + static IEnumerable FetchTextures(Type type, string userQuery) + { + // This piece of code is meant to put RenderTextures in a separate tab + // But the display is right now buggy, so keep it for later use when display issue is fixed + //var createGroupProviderMethod = typeof(Search.SearchUtils).GetMethod("CreateGroupProvider", BindingFlags.NonPublic|BindingFlags.Static); + //SearchProvider textureGroupProvider = null; + //SearchProvider renderTextureGroupProvider = null; + //if (createGroupProviderMethod != null) + //{ + // textureGroupProvider = createGroupProviderMethod.Invoke(null, new object[] { adbProvider, type.Name, 0, true }) as SearchProvider; + // renderTextureGroupProvider = createGroupProviderMethod.Invoke(null, new object[] { adbProvider, "Render Textures", 1, true }) as SearchProvider;; + //} + + var adbProvider = Search.SearchService.GetProvider("adb"); + using (var query = Search.SearchService.CreateContext(adbProvider, $"t:{type.Name} {userQuery}")) + using (var request = Search.SearchService.Request(query)) + { + foreach (var r in request) + { + //r.provider = textureGroupProvider; + yield return r; + } + } + + if (type != typeof(RenderTexture)) + { + using (var query = Search.SearchService.CreateContext(adbProvider, $"t:{nameof(RenderTexture)} {userQuery}")) + using (var request = Search.SearchService.Request(query)) + { + foreach (var r in request) + { + //r.provider = renderTextureGroupProvider; + yield return r; + } + } + } + } } } diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index 743d8da66d0..4da3b385e7c 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -1,4 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; + using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.UIElements; using UnityObject = UnityEngine.Object; @@ -7,8 +12,16 @@ namespace UnityEditor.VFX.UI { class ObjectPropertyRM : PropertyRM { + static readonly Dictionary s_TypeToDimensionMap = new() + { + {typeof(Texture2D), TextureDimension.Tex2D}, + {typeof(Texture3D), TextureDimension.Tex3D}, + {typeof(Cubemap), TextureDimension.Cube}, + }; + readonly TextField m_TextField; readonly Image m_ValueIcon; + readonly TextureDimension m_textureDimension; public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base(controller, labelWidth) { @@ -24,6 +37,15 @@ public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base m_TextField.Add(m_ValueIcon); m_TextField.Add(button); Add(m_TextField); + + RegisterCallback(OnDragUpdate); + RegisterCallback(OnDragEnter); + RegisterCallback(OnDragPerformed); + + if (!s_TypeToDimensionMap.TryGetValue(m_Provider.portType, out m_textureDimension)) + { + m_textureDimension = TextureDimension.Unknown; + } } public override float GetPreferredControlWidth() => 120; @@ -40,18 +62,18 @@ public override void SetValue(object obj) // object setvalue should accept null { try { - m_Value = (Object)obj; + m_Value = (UnityObject)obj; m_ValueIcon.image = obj != null ? AssetPreview.GetMiniTypeThumbnail(m_Value) : AssetPreview.GetMiniTypeThumbnail(m_Provider.portType); m_TextField.value = m_Value?.name ?? $"None ({m_Provider.portType.Name})"; } - catch (System.Exception) + catch (Exception) { - Debug.Log($"Error Trying to convert {obj?.GetType().Name ?? "null"} to {nameof(Object)}"); + Debug.Log($"Error Trying to convert {obj?.GetType().Name ?? "null"} to Object"); } - UpdateGUI(!object.ReferenceEquals(m_Value, obj)); + UpdateGUI(!ReferenceEquals(m_Value, obj)); } public override bool showsEverything => true; @@ -62,7 +84,7 @@ public override void SetValue(object obj) // object setvalue should accept null void OnPickObject() => CustomObjectPicker.Pick(m_Provider.portType, SelectHandler); - void SelectHandler(Object obj, bool isCanceled) + void SelectHandler(UnityObject obj, bool isCanceled) { if (!isCanceled) { @@ -70,5 +92,42 @@ void SelectHandler(Object obj, bool isCanceled) NotifyValueChanged(); } } + + bool CanDrag() + { + if (DragAndDrop.objectReferences.Length == 1) + { + var type = DragAndDrop.objectReferences[0].GetType(); + if (m_Provider.portType.IsAssignableFrom(type)) + { + return true; + } + + if (m_textureDimension != TextureDimension.Unknown && DragAndDrop.objectReferences[0] is Texture texture) + { + return texture.dimension == m_textureDimension; + } + } + + return false; + } + + void OnDragEnter(DragEnterEvent evt) + { + DragAndDrop.visualMode = CanDrag() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; + evt.StopPropagation(); + } + + void OnDragUpdate(DragUpdatedEvent evt) + { + DragAndDrop.visualMode = CanDrag() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; + evt.StopPropagation(); + } + + void OnDragPerformed(DragPerformEvent evt) + { + var dragObject = DragAndDrop.objectReferences.First(); + SelectHandler(dragObject, false); + } } } From 9e9583d64d4b69e3e5aa361ce88cb9377b8f7a7c Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 21 Sep 2021 10:43:59 +0200 Subject: [PATCH 06/11] Added error feedback on texture slots if the value has wrong dimensions --- .../Slots/Implementations/VFXSlotTexture2D.cs | 13 +++++++++---- .../Slots/Implementations/VFXSlotTexture3D.cs | 10 ++++++++-- .../Slots/Implementations/VFXSlotTextureCube.cs | 8 ++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture2D.cs b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture2D.cs index 74ae425528e..7fda6acd61b 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture2D.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture2D.cs @@ -1,14 +1,19 @@ -using System; -using System.Collections.Generic; using UnityEngine; - -using UnityObject = UnityEngine.Object; +using UnityEngine.Rendering; namespace UnityEditor.VFX { [VFXInfo(type = typeof(Texture2D))] class VFXSlotTexture2D : VFXSlotObject { + protected override void GenerateErrors(VFXInvalidateErrorReporter manager) + { + if (value is Texture texture && texture.dimension != TextureDimension.Tex2D) + manager.RegisterError("Slot_Value_Incorrect_Texture2D", VFXErrorType.Error, "This slot expects a Texture2D"); + + base.GenerateErrors(manager); + } + public override VFXValue DefaultExpression(VFXValue.Mode mode) { return new VFXTexture2DValue(0, mode); diff --git a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture3D.cs b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture3D.cs index b43f3180a7c..0e3fc4b452f 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture3D.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTexture3D.cs @@ -1,6 +1,4 @@ -using System; using UnityEngine; -using UnityEngine.VFX; using UnityEngine.Rendering; @@ -9,6 +7,14 @@ namespace UnityEditor.VFX [VFXInfo(type = typeof(Texture3D))] class VFXSlotTexture3D : VFXSlotObject { + protected override void GenerateErrors(VFXInvalidateErrorReporter manager) + { + if (value is Texture texture && texture.dimension != TextureDimension.Tex3D) + manager.RegisterError("Slot_Value_Incorrect_Texture3D", VFXErrorType.Error, "This slot expects a Texture3D"); + + base.GenerateErrors(manager); + } + public override VFXValue DefaultExpression(VFXValue.Mode mode) { return new VFXTexture3DValue(0, mode); diff --git a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTextureCube.cs b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTextureCube.cs index 525da6bf877..e4dbe55e5a3 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTextureCube.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Slots/Implementations/VFXSlotTextureCube.cs @@ -8,6 +8,14 @@ namespace UnityEditor.VFX [VFXInfo(type = typeof(Cubemap))] class VFXSlotTextureCube : VFXSlotObject { + protected override void GenerateErrors(VFXInvalidateErrorReporter manager) + { + if (value is Texture texture && texture.dimension != TextureDimension.Cube) + manager.RegisterError("Slot_Value_Incorrect_TextureCube", VFXErrorType.Error, "This slot expects a Cubemap"); + + base.GenerateErrors(manager); + } + public override VFXValue DefaultExpression(VFXValue.Mode mode) { return new VFXTextureCubeValue(0, mode); From b163b3783d10aa75309ee174fc0c3588f1b15450 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 21 Sep 2021 18:55:23 +0200 Subject: [PATCH 07/11] Fixed formatting issue --- .../Editor/GraphView/Views/Properties/ObjectPropertyRM.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index 4da3b385e7c..c53892ad309 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -14,9 +14,9 @@ class ObjectPropertyRM : PropertyRM { static readonly Dictionary s_TypeToDimensionMap = new() { - {typeof(Texture2D), TextureDimension.Tex2D}, - {typeof(Texture3D), TextureDimension.Tex3D}, - {typeof(Cubemap), TextureDimension.Cube}, + { typeof(Texture2D), TextureDimension.Tex2D }, + { typeof(Texture3D), TextureDimension.Tex3D }, + { typeof(Cubemap), TextureDimension.Cube }, }; readonly TextField m_TextField; @@ -29,7 +29,7 @@ public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base m_TextField = new TextField { name = "PickLabel", isReadOnly = true }; var button = new Button { name = "PickButton" }; - var icon = new VisualElement { name = "PickIcon" }; + var icon = new VisualElement { name = "PickIcon" }; m_ValueIcon = new Image { name = "TextureIcon" }; button.clicked += OnPickObject; From 26a9dd2cb21eddcf2d6eb67664947fd9bb1c28d2 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Mon, 4 Oct 2021 11:35:07 +0200 Subject: [PATCH 08/11] Filter render textures to match expected dimensions --- .../Views/Properties/CustomObjectPicker.cs | 23 +++++++++++-------- .../Views/Properties/ObjectPropertyRM.cs | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index 0368d2fdfac..506377e2687 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -4,6 +4,7 @@ using UnityEditor.Search; using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.Search; using Object = UnityEngine.Object; @@ -12,10 +13,10 @@ namespace UnityEditor.VFX.UI { static class CustomObjectPicker { - internal static void Pick(Type type, Action selectHandler) + internal static void Pick(Type type, TextureDimension textureDimension, Action selectHandler) { var view = typeof(Texture).IsAssignableFrom(type) - ? GetTexturePickerView(type, selectHandler) + ? GetTexturePickerView(type, textureDimension, selectHandler) : GetGenericView(type, selectHandler); // Until the "viewState" API is made public (should be in 2022.1) we use reflection to remove the inspector button @@ -39,10 +40,10 @@ static ISearchView GetGenericView(Type type, Action selectHandler) type); } - static ISearchView GetTexturePickerView(Type type, Action selectHandler) + static ISearchView GetTexturePickerView(Type type, TextureDimension textureDimension, Action selectHandler) { var view = Search.SearchService.ShowPicker( - Search.SearchService.CreateContext(CreateTextureProvider(type)), + Search.SearchService.CreateContext(CreateTextureProvider(type, textureDimension)), (x, y) => selectHandler(x?.ToObject(), y), null, null, @@ -54,12 +55,12 @@ static ISearchView GetTexturePickerView(Type type, Action selectHa return view; } - static SearchProvider CreateTextureProvider(Type type) + static SearchProvider CreateTextureProvider(Type type, TextureDimension textureDimension) { - return new SearchProvider("tex", "Texture", (context, provider) => FetchTextures(type, context.searchQuery)); + return new SearchProvider("tex", "Texture", (context, provider) => FetchTextures(type, textureDimension, context.searchQuery)); } - static IEnumerable FetchTextures(Type type, string userQuery) + static IEnumerable FetchTextures(Type type, TextureDimension textureDimension, string userQuery) { // This piece of code is meant to put RenderTextures in a separate tab // But the display is right now buggy, so keep it for later use when display issue is fixed @@ -90,8 +91,12 @@ static IEnumerable FetchTextures(Type type, string userQuery) { foreach (var r in request) { - //r.provider = renderTextureGroupProvider; - yield return r; + var rt = r.ToObject(); + if (rt.dimension == textureDimension) + { + //r.provider = renderTextureGroupProvider; + yield return r; + } } } } diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index c53892ad309..fff7ed46be3 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -82,7 +82,7 @@ public override void SetValue(object obj) // object setvalue should accept null protected override void UpdateIndeterminate() => visible = !indeterminate; - void OnPickObject() => CustomObjectPicker.Pick(m_Provider.portType, SelectHandler); + void OnPickObject() => CustomObjectPicker.Pick(m_Provider.portType, m_textureDimension, SelectHandler); void SelectHandler(UnityObject obj, bool isCanceled) { From 507b4cd310f52c8c24f74a7215b1e0b2cd8e0947 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Mon, 4 Oct 2021 17:39:40 +0200 Subject: [PATCH 09/11] Click to show object in project + list packages resources in search window --- .../GraphView/Views/Properties/CustomObjectPicker.cs | 10 ++++++---- .../GraphView/Views/Properties/ObjectPropertyRM.cs | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index 506377e2687..b641ccca519 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -57,7 +57,7 @@ static ISearchView GetTexturePickerView(Type type, TextureDimension textureDimen static SearchProvider CreateTextureProvider(Type type, TextureDimension textureDimension) { - return new SearchProvider("tex", "Texture", (context, provider) => FetchTextures(type, textureDimension, context.searchQuery)); + return new SearchProvider("tex", "Texture", (context, _) => FetchTextures(type, textureDimension, context.searchQuery)); } static IEnumerable FetchTextures(Type type, TextureDimension textureDimension, string userQuery) @@ -73,8 +73,9 @@ static IEnumerable FetchTextures(Type type, TextureDimension texture // renderTextureGroupProvider = createGroupProviderMethod.Invoke(null, new object[] { adbProvider, "Render Textures", 1, true }) as SearchProvider;; //} - var adbProvider = Search.SearchService.GetProvider("adb"); - using (var query = Search.SearchService.CreateContext(adbProvider, $"t:{type.Name} {userQuery}")) + var providers = new[] {Search.SearchService.GetProvider("adb")}; + + using (var query = Search.SearchService.CreateContext(providers, $"t:{type.Name} {userQuery}", SearchFlags.Packages)) using (var request = Search.SearchService.Request(query)) { foreach (var r in request) @@ -86,11 +87,12 @@ static IEnumerable FetchTextures(Type type, TextureDimension texture if (type != typeof(RenderTexture)) { - using (var query = Search.SearchService.CreateContext(adbProvider, $"t:{nameof(RenderTexture)} {userQuery}")) + using (var query = Search.SearchService.CreateContext(providers, $"t:{nameof(RenderTexture)} {userQuery}", SearchFlags.Packages)) using (var request = Search.SearchService.Request(query)) { foreach (var r in request) { + if (r == null) continue; var rt = r.ToObject(); if (rt.dimension == textureDimension) { diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs index fff7ed46be3..bb398324789 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/ObjectPropertyRM.cs @@ -38,6 +38,7 @@ public ObjectPropertyRM(IPropertyRMProvider controller, float labelWidth) : base m_TextField.Add(button); Add(m_TextField); + m_TextField.RegisterCallback(OnClickToShow); RegisterCallback(OnDragUpdate); RegisterCallback(OnDragEnter); RegisterCallback(OnDragPerformed); @@ -93,6 +94,11 @@ void SelectHandler(UnityObject obj, bool isCanceled) } } + void OnClickToShow(ClickEvent evt) + { + EditorGUI.PingObjectOrShowPreviewOnClick(m_Value, Rect.zero); + } + bool CanDrag() { if (DragAndDrop.objectReferences.Length == 1) From 9607ae00668f07c8986058f90bf12b7f0fcdaf8b Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 5 Oct 2021 16:01:49 +0200 Subject: [PATCH 10/11] Use the search window options to enable/disable package results instead of hard coding it --- .../GraphView/Views/Properties/CustomObjectPicker.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index b641ccca519..e06582067f2 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -57,10 +57,10 @@ static ISearchView GetTexturePickerView(Type type, TextureDimension textureDimen static SearchProvider CreateTextureProvider(Type type, TextureDimension textureDimension) { - return new SearchProvider("tex", "Texture", (context, _) => FetchTextures(type, textureDimension, context.searchQuery)); + return new SearchProvider("tex", "Texture", (context, _) => FetchTextures(type, textureDimension, context)); } - static IEnumerable FetchTextures(Type type, TextureDimension textureDimension, string userQuery) + static IEnumerable FetchTextures(Type type, TextureDimension textureDimension, SearchContext context) { // This piece of code is meant to put RenderTextures in a separate tab // But the display is right now buggy, so keep it for later use when display issue is fixed @@ -73,9 +73,10 @@ static IEnumerable FetchTextures(Type type, TextureDimension texture // renderTextureGroupProvider = createGroupProviderMethod.Invoke(null, new object[] { adbProvider, "Render Textures", 1, true }) as SearchProvider;; //} + var userQuery = context.searchQuery; var providers = new[] {Search.SearchService.GetProvider("adb")}; - using (var query = Search.SearchService.CreateContext(providers, $"t:{type.Name} {userQuery}", SearchFlags.Packages)) + using (var query = Search.SearchService.CreateContext(providers, $"t:{type.Name} {userQuery}", context.options)) using (var request = Search.SearchService.Request(query)) { foreach (var r in request) @@ -87,7 +88,7 @@ static IEnumerable FetchTextures(Type type, TextureDimension texture if (type != typeof(RenderTexture)) { - using (var query = Search.SearchService.CreateContext(providers, $"t:{nameof(RenderTexture)} {userQuery}", SearchFlags.Packages)) + using (var query = Search.SearchService.CreateContext(providers, $"t:{nameof(RenderTexture)} {userQuery}", context.options)) using (var request = Search.SearchService.Request(query)) { foreach (var r in request) From a0c6404bb75afa9cc64d05aa25fae2033385a7b0 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 5 Oct 2021 18:41:53 +0200 Subject: [PATCH 11/11] Fixed formatting issue --- .../Editor/GraphView/Views/Properties/CustomObjectPicker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs index e06582067f2..11c6d4ef59f 100644 --- a/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs +++ b/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/CustomObjectPicker.cs @@ -74,7 +74,7 @@ static IEnumerable FetchTextures(Type type, TextureDimension texture //} var userQuery = context.searchQuery; - var providers = new[] {Search.SearchService.GetProvider("adb")}; + var providers = new[] { Search.SearchService.GetProvider("adb") }; using (var query = Search.SearchService.CreateContext(providers, $"t:{type.Name} {userQuery}", context.options)) using (var request = Search.SearchService.Request(query))