Advertisement
SebastianLague

Load objects editor example

Jan 2nd, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. public class ExampleEditor : EditorWindow {
  7.  
  8.     GameObject[] myObjects;
  9.  
  10.     [MenuItem ("Window/My Window")]
  11.     static void Init () {
  12.         ExampleEditor window = (ExampleEditor)EditorWindow.GetWindow (typeof (ExampleEditor));
  13.         window.Show();
  14.  
  15.     }
  16.  
  17.     void OnEnable() {
  18.         LoadObjects ();
  19.     }
  20.  
  21.     void LoadObjects() {
  22.  
  23.         GameObject[] allObjs = Resources.FindObjectsOfTypeAll<GameObject> ();
  24.         List<GameObject> objsWithTag = new List<GameObject> ();
  25.  
  26.         foreach (GameObject o in allObjs) {
  27.             if (o.tag == "myTag") {
  28.                 objsWithTag.Add (o);
  29.                 Debug.Log ("Add: " + o.name);
  30.             }
  31.         }
  32.  
  33.         myObjects = objsWithTag.ToArray ();
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement