how would I display an array correctly with from an editor script?
I'm trying to make an ai that would act differently depending on which gamemode they are set to. I just started working on it, but I wanted to clean up the inspector so I looked into editor scripts. However, for the life of me, I cannot get the array of "waypoints" to display correctly. I have an enum of the different game modes and a switch statement inside the editor script and I want it to display different fields based off of which game mode you choose. This is what I am trying to accomplish: I have an array of waypoints in my character script and I put [hideInInspector] so it wouldn't show up unless the specific game mode was chosen. I have a code that should display the waypoints, and it does... kinda. It displays the name of the array, but not the actual list itself. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grunt_Ai : MonoBehaviour
{
[HideInInspector]
[Header("Domination")]
[SerializeField]
public GameObject[] waypoints;
private void Start()
{
switch (mode)
{
case (gameMode.CTF):
break;
case (gameMode.domination):
waypoints = GameObject.FindGameObjectsWithTag("Waypoints");
if(waypoints.Length <= 0)
{
Debug.Log("No waypoints!");
}
break;
case (gameMode.TDM):
break;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Grunt_Ai))]
public class Grunt_AI_Cleanup : Editor
{
SerializedProperty waypoints;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var Grunt_Ai = target as Grunt_Ai;
switch (Grunt_Ai.mode)
{
case (Grunt_Ai.gameMode.CTF):
break;
case (Grunt_Ai.gameMode.domination):
SerializedObject so = new SerializedObject(target);
SerializedProperty sp = so.FindProperty("waypoints");
EditorGUILayout.PropertyField(sp, true);
serializedObject.ApplyModifiedProperties();
break;
case (Grunt_Ai.gameMode.TDM):
break;
}
}
}
After inputting this code, this is what I get:
and if i take off [hideInInspector], this is what it look:
Any help is appreciated and thanks in advance!