Question by
Jeomar · Jan 15, 2018 at 01:13 PM ·
c#editor-scriptingeditorguieditorguilayoutcustom inspector
Trying to add EditorGUILabels and am getting a couple errors.
Trying to create EditorGUILabels in the inspector but I am getting a couple errors. Any suggestions or help to fix would be greatly appreciated.
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(KeyboardTracker))]
public class KeyboardTrackerEditor : MonoBehaviour
{
public override void OnInspectorGUI()
{
KeyboardTracker target = null;
KeyboardTracker keyboardTracker = target as KeyboardTracker;
EditorGUILayout.LabelField("Axis", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
if(keyboardTracker.axisKeys.Length == 0)
{
EditorGUILayout.HelpBox("No axes defined in InputManager.", MessageType.Info);
}
else
{
SerializedProperty serializedProperty = serializedObject.FindProperty("axisKeys");
{
for (int i = 0; i < keyboardTracker.axisKeys.Length; i++)
{
EditorGUILayout.PropertyField(serializedProperty.GetArrayElementAtIndex(i), new GUIContent("Axis" + i));
}
}
EditorGUI.indentLevel--;
EditorGUILayout.LabelField("Buttons", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
if (keyboardTracker.axisKeys.Length == 0)
{
EditorGUILayout.HelpBox("No buttons defined in InputManager.", MessageType.Info);
}
else
{
for (int i = 0; i < keyboardTracker.buttonKeys.Length; i++)
{
keyboardTracker.buttonKeys[i] = (KeyCode)EditorGUILayout.EnumPopup("Button " + i, keyboardTracker.buttonKeys[i]);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Editor Int sliders affecting each other 0 Answers
How to create an Editor for Imported Objects imported from a ScriptedImporter? 1 Answer
How to Create a Collapsible Hamburger Menu Icon Custom Inspector/Editor 1 Answer
Access an Array of class inside another Array of class? (EditorGUILayout) 1 Answer
Dynamic casting? 1 Answer