using UnityEngine; using XFramework; using XFramework.Objects; /// /// 根据名称通过对象池生成一个Resources下的 Prefab /// public class ResourcesCreater { /// /// 创建一个预制件 默认加入对象池 /// /// 预制件名称 /// 是否加入对象池 /// public static GameObject InstantiatePrefab(string prefabName, bool usePool = true) { string path = ResourcesManager.GetPath(prefabName); if (!string.IsNullOrEmpty(path)) { if (usePool) return ObjectPool.Instance.Instantiate(Resources.Load(path)); else return GameObject.Instantiate(Resources.Load(path)); } else { Debug.LogError($"未查询到名称为{prefabName}资源的具体路径,需检查是否存在该资源并更新了ResMap!"); return null; } } /// /// 创建一个预制件 /// /// 预制件名称 /// parentTrans /// 是否加入对象池 /// public static GameObject InstantiatePrefab(string prefabName, Transform transform, bool usePool = true) { string path = ResourcesManager.GetPath(prefabName); if (!string.IsNullOrEmpty(path)) { if (usePool) return ObjectPool.Instance.Instantiate((GameObject)Resources.Load(path), transform); else return GameObject.Instantiate(Resources.Load(path), transform); } else { Debug.LogError($"未查询到名称为{prefabName}资源的具体路径,需检查是否存在该资源并更新了ResMap!"); return null; } } }