Skip to content

Instantly share code, notes, and snippets.

@bzgeb
Created September 21, 2012 17:42
Show Gist options
  • Save bzgeb/3762866 to your computer and use it in GitHub Desktop.
Save bzgeb/3762866 to your computer and use it in GitHub Desktop.
Custom inspector with a dropdown
using UnityEngine;
using UnityEditor;
[CustomEditor (typeof(Trigger))]
[CanEditMultipleObjects()]
public class TriggerEditor : Editor
{
private SerializedObject obj;
private SerializedProperty radius;
private SerializedProperty priority;
string[] options = {"high", "medium", "low"};
int index = 0;
public void OnEnable ()
{
obj = new SerializedObject (target);
radius = obj.FindProperty ("radius");
priority = obj.FindProperty ("priority");
if (priority == null)
index = 0;
else
index = priority.intValue;
}
public override void OnInspectorGUI ()
{
obj.Update ();
GUIStyle style = new GUIStyle ();
style.font = EditorStyles.boldFont;
EditorGUILayout.LabelField ("Trigger", style, null);
EditorGUILayout.PropertyField (radius);
if (radius.floatValue < 0) {
radius.floatValue = 0;
}
// Make a horizontal layout for priority
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.LabelField ("Priority");
index = EditorGUILayout.Popup (index, options);
EditorGUILayout.EndHorizontal ();
priority.intValue = index;
obj.ApplyModifiedProperties ();
}
public void OnSceneGUI ()
{
// Implement what you want to see in scene view here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment