30 lines
748 B
C#
30 lines
748 B
C#
using System.Collections.Generic;
|
|
public class NotePoolManager : BasePool<BaseNote>
|
|
{
|
|
protected override void OnCreate(BaseNote obj)
|
|
{
|
|
obj.OnNoteUesd += ReturnBaseNoteToPool;
|
|
}
|
|
protected override void OnGet(BaseNote obj)
|
|
{
|
|
base.OnGet(obj);
|
|
}
|
|
protected override void OnRelease(BaseNote obj)
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 泛型note回收方法
|
|
/// </summary>
|
|
/// <param name="note"></param>
|
|
public void ReturnBaseNoteToPool(BaseNote note)
|
|
{
|
|
//如果字典中没有该类的对象池,则创建一个
|
|
var type = note.GetType();
|
|
if (!Pools.ContainsKey(type)) Pools[type] = new Stack<BaseNote>();
|
|
Pools[type].Push(note);
|
|
note.gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|