forked from Unity-Technologies/Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualElementExtensions.cs
More file actions
89 lines (72 loc) · 3.02 KB
/
VisualElementExtensions.cs
File metadata and controls
89 lines (72 loc) · 3.02 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
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor;
namespace UnityEditor.VFX.UI
{
static class VisualElementExtensions
{
static MethodInfo m_ValidateLayoutMethod;
public static void InternalValidateLayout(this IPanel panel)
{
if (m_ValidateLayoutMethod == null)
m_ValidateLayoutMethod = panel.GetType().GetMethod("ValidateLayout", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
m_ValidateLayoutMethod.Invoke(panel, new object[] {});
}
static PropertyInfo m_OwnerPropertyInfo;
public static GUIView InternalGetGUIView(this IPanel panel)
{
if (m_OwnerPropertyInfo == null)
m_OwnerPropertyInfo = panel.GetType().GetProperty("ownerObject", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
return (GUIView)m_OwnerPropertyInfo.GetValue(panel, new object[] {});
}
public static bool HasFocus(this VisualElement visualElement)
{
if (visualElement.panel == null) return false;
return visualElement.panel.focusController.focusedElement == visualElement;
}
public static void AddStyleSheetPath(this VisualElement visualElement, string path)
{
var sheet = VFXView.LoadStyleSheet(path);
if (sheet != null)
visualElement.styleSheets.Add(sheet);
}
public static void AddStyleSheetPathWithSkinVariant(this VisualElement visualElement, string path)
{
visualElement.AddStyleSheetPath(path);
//if (true)
{
visualElement.AddStyleSheetPath(path + "Dark");
}
/*else
{
visualElement.AddStyleSheetPath(path + "Light");
}*/
}
public static void ResetPositionProperties(this VisualElement visualElement)
{
var style = visualElement.style;
style.position = StyleKeyword.Null;
style.marginLeft = StyleKeyword.Null;
style.marginRight = StyleKeyword.Null;
style.marginBottom = StyleKeyword.Null;
style.marginTop = StyleKeyword.Null;
style.left = StyleKeyword.Null;
style.top = StyleKeyword.Null;
style.right = StyleKeyword.Null;
style.bottom = StyleKeyword.Null;
style.width = StyleKeyword.Null;
style.height = StyleKeyword.Null;
}
public static Vector2 GlobalToBound(this VisualElement visualElement, Vector2 position)
{
return visualElement.worldTransform.inverse.MultiplyPoint3x4(position);
}
public static Vector2 BoundToGlobal(this VisualElement visualElement, Vector2 position)
{
position = visualElement.worldTransform.MultiplyPoint3x4(position);
return position;
}
}
}