-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathVFXBlockUI.cs
More file actions
112 lines (94 loc) · 3.3 KB
/
Copy pathVFXBlockUI.cs
File metadata and controls
112 lines (94 loc) · 3.3 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
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
using System.Linq;
using UnityEngine.Profiling;
using PositionType = UnityEngine.UIElements.Position;
namespace UnityEditor.VFX.UI
{
class VFXBlockUI : VFXNodeUI
{
public new VFXBlockController controller
{
get => base.controller as VFXBlockController;
set => base.controller = value;
}
protected override bool HasPosition()
{
return false;
}
public VFXContextUI context => this.GetFirstAncestorOfType<VFXContextUI>();
public VFXBlockUI()
{
Profiler.BeginSample("VFXBlockUI.VFXBlockUI");
this.AddStyleSheetPath("VFXBlock");
pickingMode = PickingMode.Position;
capabilities &= ~Capabilities.Ascendable;
capabilities |= Capabilities.Selectable | Capabilities.Droppable;
this.AddManipulator(new SelectionDropper());
RegisterCallback<MouseEnterEvent>(OnMouseHover);
RegisterCallback<MouseLeaveEvent>(OnMouseHover);
RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
Profiler.EndSample();
style.position = PositionType.Relative;
}
// On purpose -- until we support Drag&Drop I suppose
public override void SetPosition(Rect newPos)
{
style.position = PositionType.Relative;
}
protected override void SelfChange()
{
base.SelfChange();
if (controller.model.enabled)
RemoveFromClassList("block-disabled");
else
AddToClassList("block-disabled");
if (!controller.model.isValid)
AddToClassList("invalid");
else
RemoveFromClassList("invalid");
}
public override bool superCollapsed => false;
private void OnDetachFromPanel(DetachFromPanelEvent evt)
{
var view = evt.originPanel.visualTree.Q<VFXView>();
if (view != null)
{
UpdateHover(view, false);
}
}
private void OnMouseHover(EventBase evt)
{
Profiler.BeginSample("VFXNodeUI.OnMouseOver");
try
{
var view = GetFirstAncestorOfType<VFXView>();
if (view != null)
{
UpdateHover(view, evt.eventTypeId == MouseEnterEvent.TypeId());
}
}
finally
{
Profiler.EndSample();
}
}
private void UpdateHover(VFXView view, bool isHovered)
{
var blackboard = view.blackboard;
if (blackboard == null)
return;
var attributes = controller.model is IVFXAttributeUsage attributeUsage
? attributeUsage.usedAttributes.Select(x => x.name)
: controller.model.attributes.Select(x => x.attrib.name);
foreach (var row in blackboard.GetAttributeRowsFromNames(attributes.ToArray()))
{
if (isHovered)
row.AddToClassList("hovered");
else
row.RemoveFromClassList("hovered");
}
}
}
}