OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.visualeffectgraph@6.9.0-preview / Editor / GraphView / Elements / VFXEditableDataAnchor.cs
1 using UnityEditor.Experimental.GraphView;
2 using UnityEngine;
3 using UnityEngine.UIElements;
4 using System.Collections.Generic;
5 using Type = System.Type;
6 using UnityEngine.Profiling;
7
8 namespace UnityEditor.VFX.UI
9 {
10     partial class VFXEditableDataAnchor : VFXDataAnchor
11     {
12         PropertyRM      m_PropertyRM;
13
14         VFXView m_View;
15
16
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)
19         {
20             Profiler.BeginSample("VFXEditableDataAnchor.Create");
21
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);
26             Profiler.EndSample();
27             return anchor;
28         }
29
30         protected VFXEditableDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
31         {
32             Profiler.BeginSample("VFXEditableDataAnchor.VFXEditableDataAnchor");
33             RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
34             RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
35             Profiler.EndSample();
36         }
37
38         public void AssetMoved()
39         {
40             m_PropertyRM.UpdateGUI(true);
41         }
42
43
44         void OnAttachToPanel(AttachToPanelEvent e)
45         {
46             m_View = GetFirstAncestorOfType<VFXView>();
47             if( m_View == null)
48             {
49                 //This can happen with asynchnous events.
50                 return;
51             }
52             m_View.allDataAnchors.Add(this);
53         }
54
55         void OnDetachFromPanel(DetachFromPanelEvent e)
56         {
57             if (m_View != null)
58                 m_View.allDataAnchors.Remove(this);
59         }
60
61         public float GetPreferredLabelWidth()
62         {
63             if (m_PropertyRM == null) return 0;
64             return m_PropertyRM.GetPreferredLabelWidth();
65         }
66
67         public float GetPreferredControlWidth()
68         {
69             if (m_PropertyRM == null) return 0;
70             return m_PropertyRM.GetPreferredControlWidth();
71         }
72
73         public void SetLabelWidth(float label)
74         {
75             m_PropertyRM.SetLabelWidth(label);
76         }
77
78         public void ForceUpdate()
79         {
80             m_PropertyRM.ForceUpdate();
81         }
82
83         void BuildProperty()
84         {
85             Profiler.BeginSample("VFXNodeUI.BuildProperty");
86             if (m_PropertyRM != null)
87             {
88                 Remove(m_PropertyRM);
89             }
90             m_PropertyRM = PropertyRM.Create(controller, 100);
91             if (m_PropertyRM != null)
92             {
93                 Add(m_PropertyRM);
94             }
95             Profiler.EndSample();
96         }
97
98         public override void SelfChange(int change)
99         {
100             Profiler.BeginSample("VFXEditableDataAnchor.SelfChange");
101             base.SelfChange(change);
102
103             if (m_PropertyRM == null || !m_PropertyRM.IsCompatible(controller))
104                 BuildProperty();
105
106             OnRecompile(false);
107             Profiler.EndSample();
108         }
109
110         public void OnRecompile(bool valueOnly)
111         {
112             if (m_PropertyRM != null && controller != null)
113             {
114                 if (!valueOnly)
115                 {
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();
121                 }
122                 else
123                     m_PropertyRM.UpdateValue();
124             }
125         }
126
127         public Rect internalRect
128         {
129             get
130             {
131                 Rect layout = this.layout;
132                 return new Rect(0.0f, 0.0f, layout.width, layout.height);
133             }
134         }
135
136         public override bool ContainsPoint(Vector2 localPoint)
137         {
138             return internalRect.Contains(localPoint);
139         }
140     }
141 }