1
0
Fork 0
LaboratoryProtection/Assets/PMaker/Scripts/PMaker.cs

26 lines
793 B
C#
Raw Permalink Normal View History

2023-09-12 15:55:51 +08:00
using System.Linq;
using UnityEngine;
namespace PMaker
{
public static class PMaker
{
// "依赖注入", 基于Unity运行时容器.
public static T Get<T>(string name, bool includeInactive = true) where T : MonoBehaviour
{
return Resources.FindObjectsOfTypeAll<T>()
.Where(_ => _.name == name)
.First();
}
// 检索对象, 基于Unity运行时容器.
public static GameObject Find(string name, bool includeInactive = true)
{
return Resources.FindObjectsOfTypeAll<Transform>()
.Where(_ => _.name == name)
.Select(_ => _.gameObject)
.First();
}
}
}