duck

Find gameobjects whose tag matches parent menu group

Nov 10th, 2015
2,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. public static class GameObjectTools
  5. {
  6.     // usage:  GameObjectTools.FindObjectsInTagGroup("ParentGroup");
  7.     // will return all in ParentGroup/ChildGroup1 ParentGroup/ChildGroup2 etc...
  8.     public static GameObject[] FindObjectsInTagGroup(string group)
  9.     {
  10.         string[] tags = UnityEditorInternal.InternalEditorUtility.tags;
  11.         var objs = new List<GameObject>();
  12.         for(int n=0; n<tags.Length; ++n)
  13.         {
  14.             if (tags[n].StartsWith(group+"/"))
  15.             {
  16.                 objs.AddRange( GameObject.FindGameObjectsWithTag(tags[n]));
  17.             }
  18.         }
  19.         return objs.ToArray();
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment