new-horizons/NewHorizons/Utility/SearchUtilities.cs

77 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;
namespace NewHorizons.Utility
{
public static class SearchUtilities
{
public static List<T> FindObjectsOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = GameObject.FindObjectsOfType<T>();
List<T> finalList = new List<T>();
for (var i = 0; i < firstList.Length; i++)
{
if (firstList[i].name == name)
{
finalList.Add(firstList[i]);
}
}
return finalList;
}
public static T FindObjectOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = GameObject.FindObjectsOfType<T>();
List<T> finalList = new List<T>();
for (var i = 0; i < firstList.Length; i++)
{
if (firstList[i].name == name)
{
return firstList[i];
}
}
return null;
}
public static List<T> FindResourcesOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = Resources.FindObjectsOfTypeAll<T>();
List<T> finalList = new List<T>();
for (var i = 0; i < firstList.Length; i++)
{
if (firstList[i].name == name)
{
finalList.Add(firstList[i]);
}
}
return finalList;
}
public static T FindResourceOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = Resources.FindObjectsOfTypeAll<T>();
for (var i = 0; i < firstList.Length; i++)
{
if (firstList[i].name == name)
{
return firstList[i];
}
}
return null;
}
}
}