- Home /
How do I change inspector values of other game objects using a custom Editor Window
I am trying to assign IDs to all my Game Objects, Each has a different type of script attached on them but all of them has the "id" property. (public,int) I want to do so using a custom Editor Window. I know the code I wrote executes when I press the button I created, but it's not changing the "id" property in the related objects' inspector. This is the code I wrote in the Editor Window Script:
 [MenuItem("Phoenix Game Studio/Fix ID Manager")]
     public static void ShowWindow()
     {
         GetWindow<WindowEditor>("Fix ID Manager");
     }
 
     void OnGUI()
     {
         GUILayout.Label("Fix IDs Based on Object Positions", EditorStyles.boldLabel);
 
         if (GUILayout.Button("Fix IDs Based on Position"))
         {
             
             int id = 0;
             /////////////////////////////////////////////////
             //Find Enemies
             AIManager[] enemies = FindObjectsOfType<AIManager>();
             //Sort by X Value
             enemies.OrderBy(gameObject => gameObject.transform.position.x);
             for (int i = 0; i < enemies.Length; i++)
             {
                 enemies[i].id = id;
                 //enemies[i].id = EditorGUILayout.IntField(enemies[i].id);
                 id++;
             }
             /////////////////////////////////////////////////
             /////////////////////////////////////////////////
             //Find Pickable Scripts
             PickableObject[] pickableScript = FindObjectsOfType<PickableObject>();
             //Sort by X Value
             pickableScript.OrderBy(gameObject => gameObject.transform.position.x);
             for (int i = 0; i < pickableScript.Length; i++)
             {
                 pickableScript[i].id = id;
                 id++;
             }
             /////////////////////////////////////////////////
             /////////////////////////////////////////////////
             //Find Destructable objects
             Destructable[] destructableObjects = FindObjectsOfType<Destructable>();
             //Sort by X Value
             destructableObjects.OrderBy(gameObject => gameObject.transform.position.x);
             for (int i = 0; i < destructableObjects.Length; i++)
             {
                 destructableObjects[i].id = id;
                 id++;
             }
             /////////////////////////////////////////////////
            Debug.Log("IDs has been set");
 }
Your answer
 
 
             Follow this Question
Related Questions
How do I change inspector values of other game objects using a custom Editor Window 0 Answers
How do I change inspector values of other game objects using a custom Editor Window 0 Answers
Create Spells through classes in custom editor? 1 Answer
Reorderable list of UnityEvents 2 Answers
Make a custom inspector that shows a group of variables in form of list 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                