Tanoda
TransformTweenBehaviourEditor.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 Leap.Unity.Query;
10using System.Collections;
11using System.Collections.Generic;
12using UnityEditor;
13using UnityEngine;
14
16
17 [CanEditMultipleObjects]
18 [CustomEditor(typeof(TransformTweenBehaviour))]
19 public class TransformTweenBehaviourEditor : CustomEditorBase<TransformTweenBehaviour> {
20
21 protected override void OnEnable() {
22 base.OnEnable();
23
25
26 deferProperty("_eventTable");
27 specifyCustomDrawer("_eventTable", drawEventTable);
28 }
29
30 private EnumEventTableEditor _tableEditor;
31 private void drawEventTable(SerializedProperty property) {
32 if (_tableEditor == null) {
33 _tableEditor = new EnumEventTableEditor(property, typeof(TransformTweenBehaviour.EventType));
34 }
35
36 _tableEditor.DoGuiLayout();
37 }
38
39 public override void OnInspectorGUI() {
40
42
43 EditorGUI.BeginDisabledGroup(target.targetTransform == null
44 || target.startTransform == null
45 || Utils.IsObjectPartOfPrefabAsset(target.gameObject));
46
47 EditorGUILayout.BeginHorizontal();
48
49 if (GUILayout.Button(new GUIContent("Set Target" + (targets.Length > 1 ? "s" : "") + " To Start",
50 "If this TransformTweenBehaviour has a valid target and start transform, "
51 + "you can press this button to set the target transform to the start state."))) {
52 Undo.IncrementCurrentGroup();
53 Undo.SetCurrentGroupName("Set Target(s) To Start");
54 foreach (var individualTarget in targets) {
55 Undo.RecordObject(individualTarget.targetTransform, "Move Target To Start");
56 individualTarget.SetTargetToStart();
57 }
58 }
59
60 EditorGUI.EndDisabledGroup();
61
62 EditorGUI.BeginDisabledGroup(target.targetTransform == null
63 || target.endTransform == null
64 || Utils.IsObjectPartOfPrefabAsset(target.gameObject));
65
66 if (GUILayout.Button(new GUIContent("Set Target" + (targets.Length > 1 ? "s" : "") + " To End",
67 "If this TransformTweenBehaviour has a valid target and end transform, "
68 + "you can press this button to set the target transform to the end state."))) {
69 Undo.IncrementCurrentGroup();
70 Undo.SetCurrentGroupName("Set Target(s) To End");
71 foreach (var individualTarget in targets) {
72 Undo.RecordObject(individualTarget.targetTransform, "Move Target To End");
73 individualTarget.SetTargetToEnd();
74 }
75 }
76
77 EditorGUILayout.EndHorizontal();
78
79 EditorGUI.EndDisabledGroup();
80
81 base.OnInspectorGUI();
82 }
83
84 }
85
86}
This is a wrapper MonoBehaviour that demonstrates and exposes some of the basic functionality of the ...
void deferProperty(string propertyName)
Defer rendering of a property until the end of the inspector. Deferred properties are drawn in the RE...
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.