I want to add items from a list into an array using the editor and popup menus
i want to be able to edit the attacks of specific units in the editor so that i can use them in the battle. I believed creating a list of all possible attacks, and then an array of selected attacks should accomplish the job. I want to be able to add items to the array from the list in a popup menu in an editor window.
the battleSystem GameObject houses the list of attacks. Each attack is its own serialized class which has a name and data for gameplay. I want to be able to have the list of possible attacks displayed by Attack.Name, but still be of the Attack class. i add an item to the array then i pick which attacks i want for the unit, then press the "Set attacks" button to transfer the data from the BattleEditor window to the attack array on the PlayerManager. I'm having trouble wrapping my head around the Editor scripting primarily how to setup the popups, how to populate the popups with a label and underlying object, and how to allow me to add multiple attacks. below is my current code.
public class BattleEditor : EditorWindow
{
List<Attack> attacks;
Attack[] SelAttacks;
GameObject battleSystem;
[MenuItem("Window/Battle Editor")]
public static void ShowWindow()
{
GetWindow<BattleEditor>("Battle Editor");
}
public void OnGUI()
{
EditorGUILayout.BeginHorizontal();
battleSystem = (GameObject)EditorGUILayout.ObjectField("BattleSystem:",battleSystem, typeof(GameObject), true);
EditorGUILayout.EndHorizontal();
attacks = battleSystem.GetComponent<BattleSystem>().attacks.ToList();
if(GUILayout.Button("Set Attacks"))
{
foreach (GameObject unit in Selection.gameObjects)
{
unit.GetComponent<PlayerManager>().attacks = SelAttacks;
}
}
}
}
any help would be greatly appreciated.