Updating a List from a Custom Inspector
In order to manage the many states that I'm working with in my game, I am compartmentalizing them into scripts of type State, which is a child of Object. My State Manager has a List that holds all the possible states in a set order.
I will make many different state scripts and I want to be able to use the inspector to drag and drop the State Script into the List. Currently I have the inspector showing the slot where I would put the script, and I can drag and drop the script into window, however nothing happens when I do this. It remains blank.
In the following code snippet PlayerStates in an enum of all possible states.
UnityChanFSM is the state manager.
Any advice on how to update the list is greatly appreciated!
[CustomEditor(typeof(UnityChanFSM))]
public class UnityChanFSMEditor : Editor
{
protected static bool ShowStatePrimarySection; //_primaryStart -> _primaryEnd
public override void OnInspectorGUI()
{
serializedObject.Update();
base.OnInspectorGUI();
UnityChanFSM myUnityChanFSM = (UnityChanFSM)target;
ShowStatePrimarySection = EditorGUILayout.Foldout(ShowStatePrimarySection, "Primary States");
if (ShowStatePrimarySection)
{
for(int i = (int)PlayerStates._primaryStart + 1; i < (int)PlayerStates._primaryEnd; i++)
{
myUnityChanFSM.stateScriptList[i] = (State)EditorGUILayout.ObjectField(((PlayerStates)i).ToString(), myUnityChanFSM.stateScriptList[i], typeof(Object), false);
}
}
serializedObject.ApplyModifiedProperties();
}
Your answer
Follow this Question
Related Questions
Updating a List from a Custom Inspector 0 Answers
Updating a List from a Custom Inspector 0 Answers
Most efficient way to store information in an inspector dropdown menu? 0 Answers
Edit properties of certain list items,Changing properties of objects in a list (c#) 1 Answer
Add GameObject to List by tag not working consistently 1 Answer