GvrLaserVisualEditor.cs
6.41 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//-----------------------------------------------------------------------
// <copyright file="GvrLaserVisualEditor.cs" company="Google Inc.">
// Copyright 2017 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-----------------------------------------------------------------------
using System.Collections;
using UnityEditor;
using UnityEngine;
/// <summary>Custom editor for `GvrLaserVisual`.</summary>
/// <remarks>
/// Shows the relationship between the `shrinkLaser` property and other related properties.
/// </remarks>
[CustomEditor(typeof(GvrLaserVisual)), CanEditMultipleObjects]
public class GvrLaserVisualEditor : Editor
{
/// <summary>The name of the **laser color** property.</summary>
public const string LASER_COLOR_PROP_NAME = "laserColor";
/// <summary>The name of the **laser color end** property.</summary>
public const string LASER_COLOR_END_PROP_NAME = "laserColorEnd";
/// <summary>The name of the **max laser distance** property.</summary>
public const string MAX_LASER_DISTANCE_PROP_NAME = "maxLaserDistance";
/// <summary>The name of the **shrink laser** property.</summary>
public const string SHRINK_LASER_PROP_NAME = "shrinkLaser";
/// <summary>The name of the **shrunk scale** property.</summary>
public const string SHURNK_SCALE_PROP_NAME = "shrunkScale";
/// <summary>The name of the **begin shrinking angle (degrees)** property.</summary>
public const string BEGIN_SHRINKING_ANGLE_DEGREES_PROP_NAME = "beginShrinkAngleDegrees";
/// <summary>The name of the **end shrinking angle (degrees)** property.</summary>
public const string END_SHRINKING_ANGLE_DEGREES_PROP_NAME = "endShrinkAngleDegrees";
/// <summary>The name of the **interpolation speed** property.</summary>
public const string LERP_SPEED_PROP_NAME = "lerpSpeed";
/// <summary>The name of the **interpolation threshold** property.</summary>
public const string LERP_THRESHOLD_PROP_NAME = "lerpThreshold";
/// <summary>The name of the **reticle** property.</summary>
public const string RETICLE_PROP_NAME = "reticle";
/// <summary>The name of the **controller** property.</summary>
public const string CONTROLLER_PROP_NAME = "controller";
private const string ITEM_PREFIX = "• ";
private SerializedProperty laserColor;
private SerializedProperty laserColorEnd;
private SerializedProperty maxLaserDistance;
private SerializedProperty shrinkLaser;
private SerializedProperty shrunkScale;
private SerializedProperty beginShrinkAngleDegrees;
private SerializedProperty endShrinkAngleDegrees;
private SerializedProperty lerpSpeed;
private SerializedProperty lerpThreshold;
private SerializedProperty reticle;
private SerializedProperty controller;
/// @cond
/// <summary>A builtin method of the `Editor` class.</summary>
/// <remarks>Implement this function to make a custom inspector.</remarks>
public override void OnInspectorGUI()
{
serializedObject.Update();
// Add clickable script field, as would have been provided by DrawDefaultInspector()
MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false);
EditorGUI.EndDisabledGroup();
// Show properties for the laser visual.
EditorGUILayout.PropertyField(reticle);
EditorGUILayout.PropertyField(controller);
EditorGUILayout.PropertyField(laserColor);
EditorGUILayout.PropertyField(laserColorEnd);
EditorGUILayout.PropertyField(maxLaserDistance);
EditorGUILayout.PropertyField(lerpSpeed);
EditorGUILayout.PropertyField(lerpThreshold);
EditorGUILayout.PropertyField(shrinkLaser);
// Show properties for shrinking animation. Only enabled if shrinkLaser is enabled.
if (!shrinkLaser.boolValue)
{
GUI.enabled = false;
}
EditorGUI.indentLevel++;
Rect shrinkLaserRect = EditorGUILayout.BeginVertical();
shrinkLaserRect = EditorGUI.IndentedRect(shrinkLaserRect);
GUI.Box(shrinkLaserRect, "");
EditorGUILayout.Space();
EditorGUILayout.PropertyField(shrunkScale,
new GUIContent(ITEM_PREFIX + shrunkScale.displayName));
EditorGUILayout.PropertyField(beginShrinkAngleDegrees,
new GUIContent(ITEM_PREFIX + beginShrinkAngleDegrees.displayName));
EditorGUILayout.PropertyField(endShrinkAngleDegrees,
new GUIContent(ITEM_PREFIX + endShrinkAngleDegrees.displayName));
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
EditorGUI.indentLevel--;
if (!shrinkLaser.boolValue)
{
GUI.enabled = true;
}
EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties();
}
/// @endcond
/// <summary>This MonoBehavior's OnEnable behavior.</summary>
private void OnEnable()
{
laserColor = serializedObject.FindProperty(LASER_COLOR_PROP_NAME);
laserColorEnd = serializedObject.FindProperty(LASER_COLOR_END_PROP_NAME);
maxLaserDistance = serializedObject.FindProperty(MAX_LASER_DISTANCE_PROP_NAME);
shrinkLaser = serializedObject.FindProperty(SHRINK_LASER_PROP_NAME);
shrunkScale = serializedObject.FindProperty(SHURNK_SCALE_PROP_NAME);
beginShrinkAngleDegrees = serializedObject.FindProperty(
BEGIN_SHRINKING_ANGLE_DEGREES_PROP_NAME);
endShrinkAngleDegrees = serializedObject.FindProperty(
END_SHRINKING_ANGLE_DEGREES_PROP_NAME);
lerpSpeed = serializedObject.FindProperty(LERP_SPEED_PROP_NAME);
lerpThreshold = serializedObject.FindProperty(LERP_THRESHOLD_PROP_NAME);
reticle = serializedObject.FindProperty(RETICLE_PROP_NAME);
controller = serializedObject.FindProperty(CONTROLLER_PROP_NAME);
}
}