///
/// MIT License - Copyright(c) 2019 Ugo Belfiore
///
///
/// Useful runtime functions
///
public static class ExtUtilityFunction
{
///
/// Get a script. Use it only in editor, it's extremly expensive in performance
/// use: MyScript myScript = ExtUtilityFunction.GetScript();
///
/// type of script
/// return the script found, or null if nothing found
public static T GetScript()
{
object obj = UnityEngine.Object.FindObjectOfType(typeof(T));
if (obj != null)
{
return ((T)obj);
}
return (default(T));
}
///
/// Get a list of scripts. Use it only in editor, it's extremly expensive in performance
/// use: MyScript [] myScript = ExtUtilityFunction.GetScripts();
///
/// type of script
/// return the array of script found
public static T[] GetScripts()
{
object[] obj = UnityEngine.Object.FindObjectsOfType(typeof(T));
T[] objType = new T[obj.Length];
if (obj != null)
{
for (int i = 0; i < obj.Length; i++)
{
objType[i] = (T)obj[i];
}
}
return (objType);
}
}