diff --git a/Assets/Resources/Test/Cube.prefab b/Assets/Resources/Test/Cube.prefab index a279e16..3609d29 100644 --- a/Assets/Resources/Test/Cube.prefab +++ b/Assets/Resources/Test/Cube.prefab @@ -113,7 +113,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3745365020364595915} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 278639fb612259b4890f4f8615f9305f, type: 3} m_Name: diff --git a/Assets/Scripts/ProjectBase/Pool/PoolMgr.cs b/Assets/Scripts/ProjectBase/Pool/PoolMgr.cs index de83e62..04e371f 100644 --- a/Assets/Scripts/ProjectBase/Pool/PoolMgr.cs +++ b/Assets/Scripts/ProjectBase/Pool/PoolMgr.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Events; /// /// 池子里的一列容器 @@ -70,23 +71,31 @@ public class PoolMgr :BaseManager /// /// /// - public GameObject GetObj(string name) + public void GetObj(string name,UnityAction callback) { - GameObject obj = null; + //GameObject obj = null; //有容器,且容器有物品,可以拿 if(poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0) { - obj = poolDic[name].GetObj(); + //obj = poolDic[name].GetObj(); + callback(poolDic[name].GetObj()); } else { - obj = GameObject.Instantiate(Resources.Load(name)); + //将下面的改成异步加载资源,创建对象给外部用 + ResMgr.GetInstance().LoadAsync(name, (o) => + { + o.name = name; + callback(o); + }); + + // obj = GameObject.Instantiate(Resources.Load(name)); //把对面名字改得和池子的名字一样 - obj.name = name; + // obj.name = name; } - return obj; + } /// diff --git a/Assets/Scripts/ProjectBase/Test/Test.cs b/Assets/Scripts/ProjectBase/Test/Test.cs index ae81c1a..abd3bd3 100644 --- a/Assets/Scripts/ProjectBase/Test/Test.cs +++ b/Assets/Scripts/ProjectBase/Test/Test.cs @@ -25,9 +25,11 @@ public class Test : MonoBehaviour { if(Input.GetMouseButtonDown(0)) { - // PoolMgr.GetInstance().GetObj("Test/Cube"); - GameObject obj = ResMgr.GetInstance().Load("Test/Cube"); - obj.transform.localScale = Vector3.one*2; + PoolMgr.GetInstance().GetObj("Test/Cube",(o)=> { + o.transform.localScale = Vector3.one * 2; + }); + /*GameObject obj = ResMgr.GetInstance().Load("Test/Cube"); + obj.transform.localScale = Vector3.one*2;*/ } if (Input.GetMouseButtonDown(1))