Skip to content

Commit ff74eae

Browse files
committed
fix(Editor): prevent crash on build due to UnityEditor
The method used for generating the labels in the Unity Custom Editors was located in the `Utilities` script which is included in the main build, however this script included the `UnityEditor` package which doesn't get included at build time and therefore would crash any builds. The solution is to have an Editor Utilities script within the Editor directory as that doesn't get included in the build and keeps the build files clean.
1 parent 695a33c commit ff74eae

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

Assets/VRTK/Editor/VRTK_AdaptiveQualityEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ public override void OnInspectorGUI()
9999
}
100100

101101
adaptiveQuality.overrideRenderScale = EditorGUILayout.Toggle(
102-
Utilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScale"),
102+
VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScale"),
103103
adaptiveQuality.overrideRenderScale);
104104

105105
EditorGUI.BeginDisabledGroup(!adaptiveQuality.overrideRenderScale);
106106
{
107107
adaptiveQuality.overrideRenderScaleLevel =
108108
EditorGUILayout.IntSlider(
109-
Utilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScaleLevel"),
109+
VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScaleLevel"),
110110
adaptiveQuality.overrideRenderScaleLevel,
111111
0,
112112
maxRenderScaleLevel);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace VRTK
2+
{
3+
using UnityEngine;
4+
using UnityEditor;
5+
using System;
6+
7+
public class VRTK_EditorUtilities : MonoBehaviour
8+
{
9+
public static GUIContent BuildGUIContent<T>(string fieldName, string displayOverride = null)
10+
{
11+
var displayName = (displayOverride != null ? displayOverride : ObjectNames.NicifyVariableName(fieldName));
12+
var fieldInfo = typeof(T).GetField(fieldName);
13+
var tooltipAttribute = (TooltipAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TooltipAttribute));
14+
return (tooltipAttribute == null ? new GUIContent(displayName) : new GUIContent(displayName, tooltipAttribute.tooltip));
15+
}
16+
}
17+
}

Assets/VRTK/Editor/VRTK_EditorUtilities.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/VRTK/Editor/VRTK_InteractableObjectEditor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public override void OnInspectorGUI()
3737
{
3838
EditorGUI.indentLevel++;
3939

40-
targ.highlightOnTouch = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("highlightOnTouch"), targ.highlightOnTouch);
40+
targ.highlightOnTouch = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("highlightOnTouch"), targ.highlightOnTouch);
4141
if (targ.highlightOnTouch)
4242
{
4343
EditorGUILayout.PropertyField(serializedObject.FindProperty("touchHighlightColor"));
4444
}
4545

4646
GUILayout.BeginHorizontal();
47-
EditorGUILayout.PrefixLabel(Utilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnTouch"));
47+
EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnTouch"));
4848
EditorGUI.indentLevel--;
4949
GUILayout.Label("Strength", GUILayout.MinWidth(49f));
5050
float y = EditorGUILayout.FloatField(targ.rumbleOnTouch.y, GUILayout.MinWidth(10f));
@@ -62,7 +62,7 @@ public override void OnInspectorGUI()
6262

6363
//Grab Layout
6464
GUILayout.Space(10);
65-
targ.isGrabbable = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("isGrabbable"), targ.isGrabbable);
65+
targ.isGrabbable = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("isGrabbable"), targ.isGrabbable);
6666
if (targ.isGrabbable != isGrabbableLastState && targ.isGrabbable)
6767
{
6868
viewGrab = true;
@@ -86,7 +86,7 @@ public override void OnInspectorGUI()
8686
EditorGUILayout.PropertyField(serializedObject.FindProperty("grabOverrideButton"));
8787

8888
GUILayout.BeginHorizontal();
89-
EditorGUILayout.PrefixLabel(Utilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnGrab"));
89+
EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnGrab"));
9090
EditorGUI.indentLevel--;
9191
GUILayout.Label("Strength", GUILayout.MinWidth(49f));
9292
float y = EditorGUILayout.FloatField(targ.rumbleOnGrab.y, GUILayout.MinWidth(10f));
@@ -97,7 +97,7 @@ public override void OnInspectorGUI()
9797
GUILayout.EndHorizontal();
9898

9999
EditorGUILayout.PropertyField(serializedObject.FindProperty("allowedGrabControllers"));
100-
targ.precisionSnap = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("precisionSnap", "Precision Grab(Snap)"), targ.precisionSnap);
100+
targ.precisionSnap = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("precisionSnap", "Precision Grab(Snap)"), targ.precisionSnap);
101101
if (!targ.precisionSnap)
102102
{
103103
EditorGUILayout.PropertyField(serializedObject.FindProperty("rightSnapHandle"));
@@ -107,7 +107,7 @@ public override void OnInspectorGUI()
107107
EditorGUILayout.PropertyField(serializedObject.FindProperty("hideControllerOnGrab"));
108108
EditorGUILayout.PropertyField(serializedObject.FindProperty("stayGrabbedOnTeleport"));
109109

110-
targ.grabAttachMechanic = (VRTK_InteractableObject.GrabAttachType)EditorGUILayout.EnumPopup(Utilities.BuildGUIContent<VRTK_InteractableObject>("grabAttachMechanic"), targ.grabAttachMechanic);
110+
targ.grabAttachMechanic = (VRTK_InteractableObject.GrabAttachType)EditorGUILayout.EnumPopup(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("grabAttachMechanic"), targ.grabAttachMechanic);
111111
if (Array.IndexOf(hasDetachThreshold, targ.grabAttachMechanic) >= 0)
112112
{
113113
EditorGUILayout.PropertyField(serializedObject.FindProperty("detachThreshold"));
@@ -125,7 +125,7 @@ public override void OnInspectorGUI()
125125
}
126126

127127
GUILayout.Space(10);
128-
targ.isUsable = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("isUsable"), targ.isUsable);
128+
targ.isUsable = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("isUsable"), targ.isUsable);
129129
if (targ.isUsable != isUsableLastState && targ.isUsable)
130130
{
131131
viewUse = true;
@@ -149,7 +149,7 @@ public override void OnInspectorGUI()
149149
EditorGUILayout.PropertyField(serializedObject.FindProperty("pointerActivatesUseAction"));
150150

151151
GUILayout.BeginHorizontal();
152-
EditorGUILayout.PrefixLabel(Utilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnUse"));
152+
EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnUse"));
153153
EditorGUI.indentLevel--;
154154
GUILayout.Label("Strength", GUILayout.MinWidth(49f));
155155
float y = EditorGUILayout.FloatField(targ.rumbleOnUse.y, GUILayout.MinWidth(10f));

Assets/VRTK/Scripts/Helper/Utilities.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace VRTK
22
{
33
using UnityEngine;
4-
using UnityEditor;
5-
using System;
64
using System.Reflection;
75
using Highlighters;
86

@@ -160,13 +158,5 @@ public static VRTK_BaseHighlighter GetActiveHighlighter(GameObject obj)
160158

161159
return objectHighlighter;
162160
}
163-
164-
public static GUIContent BuildGUIContent<T>(string fieldName, string displayOverride = null)
165-
{
166-
var displayName = (displayOverride != null ? displayOverride : ObjectNames.NicifyVariableName(fieldName));
167-
var fieldInfo = typeof(T).GetField(fieldName);
168-
var tooltipAttribute = (TooltipAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TooltipAttribute));
169-
return (tooltipAttribute == null ? new GUIContent(displayName) : new GUIContent(displayName, tooltipAttribute.tooltip));
170-
}
171161
}
172162
}

0 commit comments

Comments
 (0)