Skip to content

Commit 9e7999d

Browse files
[VFX] Use New Overlay for VFXEventTest & VisualEffectEditor (#4407)
* Use newly introduced "UnityEditor.Overlays" instead of deprecated SceneViewOverlay I'm using this similar change as reference : https://ono.unity3d.com/unity/from-git/diff-2way/Modules/ParticleSystemEditor/ParticleEffectUI.cs?diff2=98ee5a3e7c2b1bcafcc6b01a687c0536e03baca8&diff1=71a161db37e24385d48e3d72f5cfe23f50a1665f&fulldiff=1&diff=diff * Fix VisualEffectEditor & VFXEventTester * Fix eventTester which wasn't updating m_Effect
1 parent 08146a5 commit 9e7999d

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

com.unity.visualeffectgraph/Editor/Inspector/AdvancedVisualEffectEditor.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,6 @@ ContextAndGizmo GetGizmo()
338338
return context;
339339
}
340340

341-
protected override void OnSceneViewGUI(SceneView sv)
342-
{
343-
base.OnSceneViewGUI(sv);
344-
345-
if (m_GizmoDisplayed && m_GizmoedParameter != null && m_GizmoableParameters.Count > 0 && ((VisualEffect)target).visualEffectAsset != null)
346-
{
347-
ContextAndGizmo context = GetGizmo();
348-
349-
VFXGizmoUtility.Draw(context.context, (VisualEffect)target, context.gizmo);
350-
}
351-
}
352-
353341
class GizmoContext : VFXGizmoUtility.Context
354342
{
355343
public GizmoContext(SerializedObject obj, VFXParameter parameter)
@@ -698,9 +686,16 @@ internal override Bounds GetWorldBoundsOfTarget(UnityObject targetObject)
698686
return base.GetWorldBoundsOfTarget(targetObject);
699687
}
700688

701-
protected override void SceneViewGUICallback(UnityObject tar, SceneView sceneView)
689+
protected override void SceneViewGUICallback()
702690
{
703-
base.SceneViewGUICallback(tar, sceneView);
691+
base.SceneViewGUICallback();
692+
693+
if (m_GizmoDisplayed && m_GizmoedParameter != null && m_GizmoableParameters.Count > 0 && ((VisualEffect)target).visualEffectAsset != null)
694+
{
695+
ContextAndGizmo context = GetGizmo();
696+
VFXGizmoUtility.Draw(context.context, (VisualEffect)target, context.gizmo);
697+
}
698+
704699
if (m_GizmoableParameters.Count > 0)
705700
{
706701
int current = m_GizmoDisplayed ? m_GizmoableParameters.IndexOf(m_GizmoedParameter) : -1;
@@ -731,7 +726,9 @@ protected override void SceneViewGUICallback(UnityObject tar, SceneView sceneVie
731726
context.gizmo.spaceLocalByDefault = context.context.spaceLocalByDefault;
732727
context.gizmo.component = (VisualEffect)target;
733728
Bounds bounds = context.gizmo.CallGetGizmoBounds(context.context.value);
734-
sceneView.Frame(bounds, false);
729+
var sceneView = SceneView.lastActiveSceneView;
730+
if (sceneView)
731+
sceneView.Frame(bounds, false);
735732
}
736733
}
737734
GUI.enabled = saveEnabled;

com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.Collections;
44
using System.Collections.Generic;
55
using UnityEditor;
6+
using UnityEditor.Overlays;
67
using UnityEditor.Experimental;
78
using UnityEditor.SceneManagement;
89
using UnityEngine;
10+
using UnityEngine.SceneManagement;
911
using UnityEngine.VFX;
1012
using UnityEditor.VFX;
1113
using UnityEditor.VFX.UI;
@@ -26,6 +28,8 @@ protected void OnEnable()
2628
protected void OnDisable()
2729
{
2830
SceneView.duringSceneGui -= OnSceneGUI;
31+
if (s_EffectUi == this)
32+
s_EffectUi = null;
2933
}
3034

3135
protected virtual SerializedProperty FindProperty(VFXSetting setting)
@@ -128,6 +132,25 @@ public virtual SerializedProperty DoInspectorGUI()
128132

129133
IGizmoController m_CurrentController;
130134

135+
static VFXSlotContainerEditor s_EffectUi;
136+
[Overlay(typeof(SceneView), k_OverlayId, k_DisplayName)]
137+
class SceneViewVFXSlotContainerOverlay : TransientSceneViewOverlay
138+
{
139+
const string k_OverlayId = "Scene View/Visual Effect Model";
140+
const string k_DisplayName = "Visual Effect Model";
141+
public override bool ShouldDisplay()
142+
{
143+
return s_EffectUi != null;
144+
}
145+
146+
public override void OnGUI()
147+
{
148+
if (s_EffectUi == null)
149+
return;
150+
s_EffectUi.SceneViewGUICallback();
151+
}
152+
}
153+
131154
void OnSceneGUI(SceneView sv)
132155
{
133156
try // make sure we don't break the whole scene
@@ -156,7 +179,11 @@ void OnSceneGUI(SceneView sv)
156179

157180
if (m_CurrentController.gizmoables.Count > 0)
158181
{
159-
SceneViewOverlay.Window(new GUIContent("Choose Gizmo"), SceneViewGUICallback, (int)SceneViewOverlay.Ordering.ParticleEffect, SceneViewOverlay.WindowDisplayOption.OneWindowPerTitle);
182+
s_EffectUi = this;
183+
}
184+
else
185+
{
186+
s_EffectUi = null;
160187
}
161188
}
162189
}
@@ -175,7 +202,7 @@ void OnSceneGUI(SceneView sv)
175202
}
176203
}
177204

178-
protected virtual void SceneViewGUICallback(UnityObject target, SceneView sceneView)
205+
internal virtual void SceneViewGUICallback()
179206
{
180207
if (m_CurrentController == null)
181208
return;
@@ -215,7 +242,8 @@ protected virtual void SceneViewGUICallback(UnityObject target, SceneView sceneV
215242
if (view.controller != null && view.controller.model && view.controller.graph == slotContainer.GetGraph())
216243
{
217244
Bounds b = m_CurrentController.GetGizmoBounds(view.attachedComponent);
218-
if (b.size.sqrMagnitude > Mathf.Epsilon)
245+
var sceneView = SceneView.lastActiveSceneView;
246+
if (b.size.sqrMagnitude > Mathf.Epsilon && sceneView)
219247
sceneView.Frame(b, false);
220248
}
221249
}

com.unity.visualeffectgraph/Editor/Inspector/VisualEffectEditor.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
using UnityEngine.Rendering;
1010
using UnityEngine.VFX;
1111

12+
using UnityEditor.Overlays;
13+
using UnityEditor.Experimental;
14+
using UnityEditor.SceneManagement;
15+
1216
using UnityEditor.VFX;
1317
using UnityEditor.VFX.UI;
1418
using EditMode = UnityEditorInternal.EditMode;
@@ -115,7 +119,7 @@ protected void OnEnable()
115119
m_RendererEditor = new RendererEditor(renderers);
116120

117121
s_FakeObjectSerializedCache = new SerializedObject(targets[0]);
118-
SceneView.duringSceneGui += OnSceneViewGUI;
122+
s_EffectUi = this;
119123
}
120124

121125
protected void OnDisable()
@@ -127,12 +131,14 @@ protected void OnDisable()
127131
effect.playRate = 1.0f;
128132
}
129133
OnDisableWithoutResetting();
134+
if (s_EffectUi == this)
135+
s_EffectUi = null;
130136
}
131137

132138
protected void OnDisableWithoutResetting()
133139
{
134-
SceneView.duringSceneGui -= OnSceneViewGUI;
135-
140+
if (s_EffectUi == this)
141+
s_EffectUi = null;
136142
s_AllEditors.Remove(this);
137143
}
138144

@@ -466,7 +472,7 @@ protected static void SetObjectValue(SerializedProperty prop, object value)
466472
}
467473
}
468474

469-
protected virtual void SceneViewGUICallback(UnityObject target, SceneView sceneView)
475+
protected virtual void SceneViewGUICallback()
470476
{
471477
VisualEffect effect = ((VisualEffect)targets[0]);
472478
if (effect == null)
@@ -552,9 +558,25 @@ void SetPlayRate(object value)
552558
effect.playRate = rate;
553559
}
554560

555-
protected virtual void OnSceneViewGUI(SceneView sv)
561+
static VisualEffectEditor s_EffectUi;
562+
563+
[Overlay(typeof(SceneView), k_OverlayId, k_DisplayName)]
564+
class SceneViewVFXSlotContainerOverlay : TransientSceneViewOverlay
556565
{
557-
SceneViewOverlay.Window(Contents.headerPlayControls, SceneViewGUICallback, (int)SceneViewOverlay.Ordering.ParticleEffect, target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTitle);
566+
const string k_OverlayId = "Scene View/Visual Effect";
567+
const string k_DisplayName = "Visual Effect";
568+
public override bool ShouldDisplay()
569+
{
570+
return s_EffectUi != null;
571+
}
572+
573+
public override void OnGUI()
574+
{
575+
if (s_EffectUi == null)
576+
return;
577+
578+
s_EffectUi.SceneViewGUICallback();
579+
}
558580
}
559581

560582
private VFXGraph m_graph;

com.unity.visualeffectgraph/Editor/Utilities/EventTester/VFXEventTesterWindow.cs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEditor;
3+
using UnityEditor.Overlays;
34
using UnityEngine.VFX;
45
using UnityEditorInternal;
56
using System.Collections.Generic;
@@ -8,6 +9,25 @@ namespace UnityEditor.VFX
89
{
910
static class VFXEventTesterWindow
1011
{
12+
[Overlay(typeof(SceneView), k_OverlayId, k_DisplayName)]
13+
class SceneViewVFXEventTesterOverlay : TransientSceneViewOverlay
14+
{
15+
const string k_OverlayId = "Scene View/Visual Effect Event Tester";
16+
const string k_DisplayName = "Visual Effect Event Tester";
17+
public override bool ShouldDisplay()
18+
{
19+
if (Selection.activeGameObject && Selection.activeGameObject.TryGetComponent<VisualEffect>(out m_Effect))
20+
return visible;
21+
return false;
22+
}
23+
24+
public override void OnGUI()
25+
{
26+
if (visible)
27+
WindowGUI();
28+
}
29+
}
30+
1131
public static bool visible { get { return s_Visible; } set { SetVisibility(value); } }
1232

1333
static bool s_Visible;
@@ -39,20 +59,9 @@ static void SetVisibility(bool visible)
3959
{
4060
s_Visible = visible;
4161
EditorPrefs.SetBool(PreferenceName, visible);
42-
43-
UpdateVisibility();
4462
}
4563
}
4664

47-
[InitializeOnLoadMethod]
48-
static void UpdateVisibility()
49-
{
50-
if (s_Visible)
51-
SceneView.duringSceneGui += DrawWindow;
52-
else
53-
SceneView.duringSceneGui -= DrawWindow;
54-
}
55-
5665
private static void drawAddDropDown(Rect buttonRect, ReorderableList list)
5766
{
5867
GenericMenu menu = new GenericMenu();
@@ -115,26 +124,6 @@ static void AddColor(object name)
115124
m_Attributes.Add(new EventAttribute(name as string, EventAttributeType.Color, Color.white));
116125
}
117126

118-
static void DrawWindow(SceneView sceneView)
119-
{
120-
if (Selection.activeGameObject != null)
121-
{
122-
if (Selection.activeGameObject.TryGetComponent<VisualEffect>(out m_Effect))
123-
{
124-
SceneViewOverlay.Window(Contents.title, WindowFunction, 599, SceneViewOverlay.WindowDisplayOption.OneWindowPerTitle);
125-
}
126-
else
127-
{
128-
m_Effect = null;
129-
}
130-
}
131-
}
132-
133-
static void WindowFunction(UnityEngine.Object target, SceneView sceneView)
134-
{
135-
WindowGUI();
136-
}
137-
138127
[System.Serializable]
139128
enum EventAttributeType
140129
{

0 commit comments

Comments
 (0)