forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertyDrawer.cs
More file actions
71 lines (60 loc) · 2.74 KB
/
Copy pathPropertyDrawer.cs
File metadata and controls
71 lines (60 loc) · 2.74 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Reflection;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor
{
// Base class to derive custom property drawers from. Use this to create custom drawers
// for your own [[Serializable]] classes or for script variables with custom [[PropertyAttribute]]s.
public abstract class PropertyDrawer : GUIDrawer
{
internal PropertyAttribute m_Attribute;
internal FieldInfo m_FieldInfo;
// The [[PropertyAttribute]] for the property. Not applicable for custom class drawers. (RO)
public PropertyAttribute attribute { get { return m_Attribute; } }
// The reflection FieldInfo for the member this property represents. (RO)
public FieldInfo fieldInfo { get { return m_FieldInfo; } }
internal void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
{
ScriptAttributeUtility.s_DrawerStack.Push(this);
OnGUI(position, property, label);
ScriptAttributeUtility.s_DrawerStack.Pop();
}
// Override this method to make your own GUI for the property based on IMGUI.
public virtual void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.DefaultPropertyField(position, property, label);
EditorGUI.LabelField(position, label, EditorGUIUtility.TempContent("No GUI Implemented"));
}
// Override this method to make your own GUI for the property based on UIElements.
public virtual VisualElement CreatePropertyGUI(SerializedProperty property)
{
return null;
}
internal float GetPropertyHeightSafe(SerializedProperty property, GUIContent label)
{
ScriptAttributeUtility.s_DrawerStack.Push(this);
float height = GetPropertyHeight(property, label);
ScriptAttributeUtility.s_DrawerStack.Pop();
return height;
}
// Override this method to specify how tall the GUI for this field is in pixels.
public virtual float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.kSingleLineHeight;
}
internal bool CanCacheInspectorGUISafe(SerializedProperty property)
{
ScriptAttributeUtility.s_DrawerStack.Push(this);
bool canCache = CanCacheInspectorGUI(property);
ScriptAttributeUtility.s_DrawerStack.Pop();
return canCache;
}
public virtual bool CanCacheInspectorGUI(SerializedProperty property)
{
return true;
}
}
}