-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathVFXParameterUI.cs
More file actions
201 lines (167 loc) · 6.76 KB
/
Copy pathVFXParameterUI.cs
File metadata and controls
201 lines (167 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Profiling;
namespace UnityEditor.VFX.UI
{
class VFXOutputParameterDataAnchor : VFXOutputDataAnchor
{
public static new VFXOutputParameterDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node)
{
var anchor = new VFXOutputParameterDataAnchor(controller.orientation, controller.direction, controller.portType, node);
anchor.m_EdgeConnector = new VFXEdgeConnector(anchor);
anchor.controller = controller;
anchor.AddManipulator(anchor.m_EdgeConnector);
return anchor;
}
protected VFXOutputParameterDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
{
}
public override bool ContainsPoint(Vector2 localPoint)
{
return base.ContainsPoint(localPoint) && !m_ConnectorText.ContainsPoint(this.ChangeCoordinatesTo(m_ConnectorText, localPoint));
}
}
class VFXInputParameterDataAnchor : VFXDataAnchor
{
public static new VFXInputParameterDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node)
{
var anchor = new VFXInputParameterDataAnchor(controller.orientation, controller.direction, controller.portType, node);
anchor.m_EdgeConnector = new EdgeConnector<VFXDataEdge>(anchor);
anchor.controller = controller;
anchor.AddManipulator(anchor.m_EdgeConnector);
return anchor;
}
protected VFXInputParameterDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
{
}
public override bool ContainsPoint(Vector2 localPoint)
{
return base.ContainsPoint(localPoint) && !m_ConnectorText.ContainsPoint(this.ChangeCoordinatesTo(m_ConnectorText, localPoint));
}
}
static class UXMLHelper
{
const string folderName = VisualEffectAssetEditorUtility.editorResourcesFolder;
public static string GetUXMLPath(string name)
{
string path = null;
if (s_Cache.TryGetValue(name, out path))
{
return path;
}
return GetUXMLPathRecursive("Assets", name);
}
static Dictionary<string, string> s_Cache = new Dictionary<string, string>();
static string GetUXMLPathRecursive(string path, string name)
{
Profiler.BeginSample("UXMLHelper.GetUXMLPathRecursive");
string localFileName = path + "/" + folderName + "/" + name;
if (System.IO.File.Exists(localFileName))
{
Profiler.EndSample();
s_Cache[name] = localFileName;
return localFileName;
}
foreach (var dir in System.IO.Directory.GetDirectories(path))
{
if (dir.Length <= folderName.Length || !dir.EndsWith(folderName) || !"/\\".Contains(dir[dir.Length - folderName.Length - 1]))
{
string result = GetUXMLPathRecursive(dir, name);
if (result != null)
{
Profiler.EndSample();
return result;
}
}
}
Profiler.EndSample();
return null;
}
}
class VFXParameterUI : VFXNodeUI
{
public VFXParameterUI() : base("uxml/VFXParameter")
{
RemoveFromClassList("VFXNodeUI");
styleSheets.Add(VFXView.LoadStyleSheet("VFXParameter"));
styleSheets.Add(EditorGUIUtility.Load("StyleSheets/GraphView/Node.uss") as StyleSheet);
RegisterCallback<MouseEnterEvent>(OnMouseHover);
RegisterCallback<MouseLeaveEvent>(OnMouseHover);
m_ExposedIcon = this.Q<Image>("exposed-icon");
m_SuperCollapsedButton = this.Q("super-collapse-button");
m_SuperCollapsedButton.AddManipulator(new Clickable(OnToggleSuperCollapse));
this.AddManipulator(new SuperCollapser());
m_Pill = this.Q("pill");
}
VisualElement m_Pill;
void OnToggleSuperCollapse()
{
controller.superCollapsed = !controller.superCollapsed;
}
VisualElement m_SuperCollapsedButton;
public new VFXParameterNodeController controller
{
get { return base.controller as VFXParameterNodeController; }
}
public override VFXDataAnchor InstantiateDataAnchor(VFXDataAnchorController controller, VFXNodeUI node)
{
if (controller.direction == Direction.Input)
return VFXInputParameterDataAnchor.Create(controller, node);
else
return VFXOutputParameterDataAnchor.Create(controller, node);
}
Image m_ExposedIcon;
protected override void SelfChange()
{
base.SelfChange();
if (m_ExposedIcon != null)
m_ExposedIcon.visible = controller.parentController.exposed;
if (controller.parentController.exposed)
{
AddToClassList("exposed");
}
else
{
RemoveFromClassList("exposed");
}
if (m_Pill != null)
m_Pill.tooltip = controller.parentController.model.tooltip;
}
public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
if (evt.target == this && controller != null)
{
evt.menu.AppendAction("Convert to Inline", OnConvertToInline, e => DropdownMenuAction.Status.Normal);
evt.menu.AppendSeparator();
}
}
void OnConvertToInline(DropdownMenuAction evt)
{
controller.ConvertToInline();
}
void OnMouseHover(EventBase evt)
{
Profiler.BeginSample("VFXParameterUI.OnMouseOver");
try
{
var view = GetFirstAncestorOfType<VFXView>();
var blackboard = view?.blackboard;
var row = blackboard?.GetRowFromController(controller.parentController);
if (row == null)
return;
if (evt.eventTypeId == MouseEnterEvent.TypeId())
row.AddToClassList("hovered");
else
row.RemoveFromClassList("hovered");
}
finally
{
Profiler.EndSample();
}
}
}
}