Skip to content

Instantly share code, notes, and snippets.

@glitchersgames
Created June 11, 2018 09:05
Show Gist options
  • Save glitchersgames/c1d33a635fa0ca76e38de0591bb1b798 to your computer and use it in GitHub Desktop.
Save glitchersgames/c1d33a635fa0ca76e38de0591bb1b798 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Glitchers
{
public static class FindInterfaces
{
public static List<T> Find<T>( )
{
List<T> interfaces = new List<T>();
GameObject[] rootGameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
foreach( var rootGameObject in rootGameObjects )
{
T[] childrenInterfaces = rootGameObject.GetComponentsInChildren<T>();
foreach( var childInterface in childrenInterfaces )
{
interfaces.Add(childInterface);
}
}
return interfaces;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment