26 lines
793 B
C#
26 lines
793 B
C#
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();
|
|
}
|
|
}
|
|
} |