Create a list of custom editors
Hi guys! I am working on an AI system based on actions. My goal is to be able to set the actions up for one single gameobject (set the position,rotation, for sitting on chair, washing hands, etc) and than apply that modification to all other bots.
I want to create a static list that holds all the instances of CustomBot at runtime and than applies the modification.
The issue lies when getting the instance reference using this
keyword, it returns null. How can I go about this? Is there any other alternative?
[CustomEditor(typeof(Bot))]
[CanEditMultipleObjects]
public class CustomBot : Editor
{
Bot bot;
float id;
static List<Tuple<float,CustomBot>> customEditors = new List<Tuple<float,CustomBot>>();
private void OnEnable()
{
bot = (Bot)target; // set the bot target
id = bot.transform.position.sqrMagnitude;
LoadEveryThing();
}
void LoadEveryThing()
{
if (customEditors.Find(x => x.Item1 == id) == null)
{
customEditors.Add(Tuple.Create(id,this));
}
}
public override void OnInspectorGUI()
{
if(GUILayout.Button("Update all"))
{
foreach (var item in customEditors)
{
CustomBot bot = item.Item2;
Debug.Log("modifying" + bot); // here bot shows as null
/// update bot
}
}
serializedObject.ApplyModifiedProperties();
}
}
Your answer
Follow this Question
Related Questions
Custom editor, float not saving when enter playmode. 1 Answer
Custom Editor need for Awake function called when game starts 0 Answers
how do i remember a just instantiated prefab as a variable gameobject? 1 Answer
Game Scene lags while starting 0 Answers
Suggest best hosting server for multiplayer Game??? 0 Answers