使用案例
using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UseCase : MonoBehaviour
{
class Msg : IPoolable, IPoolType
{
#region IPoolAble 实现
public void OnRecycled()
{
Log.I("OnRecycled");
}
public bool IsRecycled { get; set; }
#endregion
#region IPoolType 实现
public void Recycle2Cache()
{
SafeObjectPool<Msg>.Instance.Recycle(this);
}
#endregion
}
private void Start()
{
//初始化对象池最大数量100,初始化数量50;
SafeObjectPool<Msg>.Instance.Init(100, 50);
//使用对象池来分配对象
Msg fishOne = SafeObjectPool<Msg>.Instance.Allocate();
//回收对象
fishOne.Recycle2Cache();
}
}
注
需要使用对象池的对象都要继承这两个接口 IPoolable, IPoolType