1 using UnityEditor.Experimental.GraphView;
3 using UnityEngine.UIElements;
4 using System.Collections.Generic;
5 using Type = System.Type;
6 using UnityEngine.Profiling;
8 namespace UnityEditor.VFX.UI
10 partial class VFXEditableDataAnchor : VFXDataAnchor
12 PropertyRM m_PropertyRM;
17 // TODO This is a workaround to avoid having a generic type for the anchor as generic types mess with USS.
18 public static new VFXEditableDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node)
20 Profiler.BeginSample("VFXEditableDataAnchor.Create");
22 var anchor = new VFXEditableDataAnchor(controller.orientation, controller.direction, controller.portType, node);
23 anchor.m_EdgeConnector = new EdgeConnector<VFXDataEdge>(anchor);
24 anchor.controller = controller;
25 anchor.AddManipulator(anchor.m_EdgeConnector);
30 protected VFXEditableDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
32 Profiler.BeginSample("VFXEditableDataAnchor.VFXEditableDataAnchor");
33 RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
34 RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
38 public void AssetMoved()
40 m_PropertyRM.UpdateGUI(true);
44 void OnAttachToPanel(AttachToPanelEvent e)
46 m_View = GetFirstAncestorOfType<VFXView>();
49 //This can happen with asynchnous events.
52 m_View.allDataAnchors.Add(this);
55 void OnDetachFromPanel(DetachFromPanelEvent e)
58 m_View.allDataAnchors.Remove(this);
61 public float GetPreferredLabelWidth()
63 if (m_PropertyRM == null) return 0;
64 return m_PropertyRM.GetPreferredLabelWidth();
67 public float GetPreferredControlWidth()
69 if (m_PropertyRM == null) return 0;
70 return m_PropertyRM.GetPreferredControlWidth();
73 public void SetLabelWidth(float label)
75 m_PropertyRM.SetLabelWidth(label);
78 public void ForceUpdate()
80 m_PropertyRM.ForceUpdate();
85 Profiler.BeginSample("VFXNodeUI.BuildProperty");
86 if (m_PropertyRM != null)
90 m_PropertyRM = PropertyRM.Create(controller, 100);
91 if (m_PropertyRM != null)
98 public override void SelfChange(int change)
100 Profiler.BeginSample("VFXEditableDataAnchor.SelfChange");
101 base.SelfChange(change);
103 if (m_PropertyRM == null || !m_PropertyRM.IsCompatible(controller))
107 Profiler.EndSample();
110 public void OnRecompile(bool valueOnly)
112 if (m_PropertyRM != null && controller != null)
116 controller.UpdateInfos();
117 bool editable = controller.editable;
118 m_PropertyRM.propertyEnabled = editable && controller.expandedInHierachy;
119 m_PropertyRM.indeterminate = !editable && controller.indeterminate;
120 m_PropertyRM.Update();
123 m_PropertyRM.UpdateValue();
127 public Rect internalRect
131 Rect layout = this.layout;
132 return new Rect(0.0f, 0.0f, layout.width, layout.height);
136 public override bool ContainsPoint(Vector2 localPoint)
138 return internalRect.Contains(localPoint);