查漏补缺,缓存池结合异步加载资源
This commit is contained in:
parent
7dd4942be3
commit
204ebeea77
@ -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:
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
/// <summary>
|
||||
/// 池子里的一列容器
|
||||
@ -70,23 +71,31 @@ public class PoolMgr :BaseManager<PoolMgr>
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public GameObject GetObj(string name)
|
||||
public void GetObj(string name,UnityAction<GameObject> 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<GameObject>(name));
|
||||
//将下面的改成异步加载资源,创建对象给外部用
|
||||
ResMgr.GetInstance().LoadAsync<GameObject>(name, (o) =>
|
||||
{
|
||||
o.name = name;
|
||||
callback(o);
|
||||
});
|
||||
|
||||
// obj = GameObject.Instantiate(Resources.Load<GameObject>(name));
|
||||
//把对面名字改得和池子的名字一样
|
||||
obj.name = name;
|
||||
// obj.name = name;
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -25,9 +25,11 @@ public class Test : MonoBehaviour
|
||||
{
|
||||
if(Input.GetMouseButtonDown(0))
|
||||
{
|
||||
// PoolMgr.GetInstance().GetObj("Test/Cube");
|
||||
GameObject obj = ResMgr.GetInstance().Load<GameObject>("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<GameObject>("Test/Cube");
|
||||
obj.transform.localScale = Vector3.one*2;*/
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user