Note about custom inspector

NOTE: If you're confused any way, just send me an email and I'll be happy to help!

  • If you take a look in the "Scripts > Editor" folder you will find the custom inspector script for both the "LeverItem" and the "LeverSystemController" scripts. You can edit these if you want variables from the appropriate scripts to appear in the inspectorn

Example Editor Script:

As you can see below, we can set the "EditorGUILayout.PropertyField" to add a new reference to a field or variable in the inspector.

  • At the top of the editor script we create a serialized property to hold the field we'll use like this:

SerializedProperty _objectType;
  • We then go to the "OnEnable" method and find the appropriate field reference

_objectType = serializedObject.FindProperty(nameof(_objectType));
  • With the "OnInspectorGUI" method we then apply the property by using:

EditorGUILayout.PropertyField(_objectType);
  • See the full code below:

public override void OnInspectorGUI()
        {
            GUI.enabled = false;
            EditorGUILayout.ObjectField("Script:", MonoScript.FromMonoBehaviour((LeverItem)target), typeof(LeverItem), false);
            GUI.enabled = true;

            EditorGUILayout.Space(5);

            LeverItem _leverItem = (LeverItem)target;

            EditorGUILayout.PropertyField(_objectType);

            EditorGUILayout.Space(5);

            if (_leverItem._objectType == LeverItem.ObjectType.Lever)
            {
                EditorGUILayout.PropertyField(leverNumber);
                EditorGUILayout.Space(5);
            }

            EditorGUILayout.PropertyField(animationName);

            EditorGUILayout.Space(10);

            EditorGUILayout.LabelField("Controller Reference", EditorStyles.toolbarTextField);
            EditorGUILayout.PropertyField(_leverSystemController);

            serializedObject.ApplyModifiedProperties();
        }

Last updated