Tanoda
CompressibleUIEditor.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using UnityEditor;
11using UnityEditorInternal;
12
14
15 [CustomEditor(typeof(CompressibleUI))]
16 public class CompressibleUIEditor : CustomEditorBase<CompressibleUI> {
17 private ReorderableList list;
18 protected override void OnEnable() {
19 base.OnEnable();
20 list = new ReorderableList(serializedObject,
21 serializedObject.FindProperty("Layers"),
22 true, true, true, true);
23 list.drawHeaderCallback = drawHeader;
24 list.drawElementCallback = drawElement;
25 list.elementHeight = EditorGUIUtility.singleLineHeight * 7;
26 specifyCustomDrawer("Layers", doLayoutList);
27
28 specifyConditionalDrawing(() => showEventTrigger(),
29 "LayerCollapse",
30 "LayerExpand",
31 "LayerDepress");
32 }
33
34 private bool showEventTrigger() {
35 bool showEventTrigger = false;
36 if (target.Layers != null) {
37 for (int i = 0; i < target.Layers.Length; i++) {
38 if (target.Layers[i].TriggerLayerEvent) {
39 showEventTrigger = true;
40 }
41 }
42 }
43 return showEventTrigger;
44 }
45
46 private void doLayoutList(SerializedProperty p) {
47 list.DoLayoutList();
48 }
49
50 private void drawHeader(Rect rect) {
51 EditorGUI.LabelField(rect, "Floating UI Layers");
52 }
53
54 private void drawElement(Rect rect, int index, bool isActive, bool isFocused) {
55 var element = list.serializedProperty.GetArrayElementAtIndex(index);
56 Rect r = rect;
57 r.height /= 7;
58
59 EditorGUI.PropertyField(r, element.FindPropertyRelative("LayerTransform"));
60 r.y += EditorGUIUtility.singleLineHeight;
61 EditorGUI.PropertyField(r, element.FindPropertyRelative("MaxFloatDistance"));
62 r.y += EditorGUIUtility.singleLineHeight;
63 EditorGUI.PropertyField(r, element.FindPropertyRelative("MinFloatDistance"));
64 r.y += EditorGUIUtility.singleLineHeight;
65 EditorGUI.PropertyField(r, element.FindPropertyRelative("Shadow"));
66 r.y += EditorGUIUtility.singleLineHeight;
67 EditorGUI.PropertyField(r, element.FindPropertyRelative("ShadowOnAboveLayer"));
68 r.y += EditorGUIUtility.singleLineHeight;
69 EditorGUI.PropertyField(r, element.FindPropertyRelative("TriggerLayerEvent"));
70 //r.y += EditorGUIUtility.singleLineHeight*1.5f;
71 //r.height /= 10;
72 //EditorGUI.DrawRect(r,new Color(0.25f, 0.25f, 0.25f));
73 //r.height *= 10;
74 }
75 }
76}
void specifyConditionalDrawing(string conditionalName, params string[] dependantProperties)
Specify a list of properties that should only be displayed if the conditional property has a value of...
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.