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