Skip to content

Commit

Permalink
fix(Editor): prevent crash on build due to UnityEditor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thestonefox committed Sep 20, 2016
1 parent 695a33c commit ff74eae
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Assets/VRTK/Editor/VRTK_AdaptiveQualityEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ public override void OnInspectorGUI()
}

adaptiveQuality.overrideRenderScale = EditorGUILayout.Toggle(
Utilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScale"),
VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScale"),
adaptiveQuality.overrideRenderScale);

EditorGUI.BeginDisabledGroup(!adaptiveQuality.overrideRenderScale);
{
adaptiveQuality.overrideRenderScaleLevel =
EditorGUILayout.IntSlider(
Utilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScaleLevel"),
VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderScaleLevel"),
adaptiveQuality.overrideRenderScaleLevel,
0,
maxRenderScaleLevel);
Expand Down
17 changes: 17 additions & 0 deletions Assets/VRTK/Editor/VRTK_EditorUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace VRTK
{
using UnityEngine;
using UnityEditor;
using System;

public class VRTK_EditorUtilities : MonoBehaviour
{
public static GUIContent BuildGUIContent<T>(string fieldName, string displayOverride = null)
{
var displayName = (displayOverride != null ? displayOverride : ObjectNames.NicifyVariableName(fieldName));
var fieldInfo = typeof(T).GetField(fieldName);
var tooltipAttribute = (TooltipAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TooltipAttribute));
return (tooltipAttribute == null ? new GUIContent(displayName) : new GUIContent(displayName, tooltipAttribute.tooltip));
}
}
}
12 changes: 12 additions & 0 deletions Assets/VRTK/Editor/VRTK_EditorUtilities.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Assets/VRTK/Editor/VRTK_InteractableObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public override void OnInspectorGUI()
{
EditorGUI.indentLevel++;

targ.highlightOnTouch = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("highlightOnTouch"), targ.highlightOnTouch);
targ.highlightOnTouch = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("highlightOnTouch"), targ.highlightOnTouch);
if (targ.highlightOnTouch)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("touchHighlightColor"));
}

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

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

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

EditorGUILayout.PropertyField(serializedObject.FindProperty("allowedGrabControllers"));
targ.precisionSnap = EditorGUILayout.Toggle(Utilities.BuildGUIContent<VRTK_InteractableObject>("precisionSnap", "Precision Grab(Snap)"), targ.precisionSnap);
targ.precisionSnap = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("precisionSnap", "Precision Grab(Snap)"), targ.precisionSnap);
if (!targ.precisionSnap)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("rightSnapHandle"));
Expand All @@ -107,7 +107,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty("hideControllerOnGrab"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("stayGrabbedOnTeleport"));

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

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

GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(Utilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnUse"));
EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent<VRTK_InteractableObject>("rumbleOnUse"));
EditorGUI.indentLevel--;
GUILayout.Label("Strength", GUILayout.MinWidth(49f));
float y = EditorGUILayout.FloatField(targ.rumbleOnUse.y, GUILayout.MinWidth(10f));
Expand Down
10 changes: 0 additions & 10 deletions Assets/VRTK/Scripts/Helper/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace VRTK
{
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
using Highlighters;

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

return objectHighlighter;
}

public static GUIContent BuildGUIContent<T>(string fieldName, string displayOverride = null)
{
var displayName = (displayOverride != null ? displayOverride : ObjectNames.NicifyVariableName(fieldName));
var fieldInfo = typeof(T).GetField(fieldName);
var tooltipAttribute = (TooltipAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TooltipAttribute));
return (tooltipAttribute == null ? new GUIContent(displayName) : new GUIContent(displayName, tooltipAttribute.tooltip));
}
}
}

0 comments on commit ff74eae

Please sign in to comment.