using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Tween
{
#region StackObj
public interface IStackObject
{
void OnInit();
void OnPop();
void OnPush();
}
#endregion
#region HeapObjectPool
///
/// 堆对象管理
///
///
public class StackObjectPool where T : new()
{
static Stack stackPool = new Stack();
///
/// Pop对象
///
///
public static T GetObject()
{
T obj;
IStackObject heapObj;
if (stackPool.Count > 0)
{
obj = stackPool.Pop();
heapObj = obj as IStackObject;
}
else
{
obj = new T();
heapObj = obj as IStackObject;
if (heapObj != null)
{
heapObj.OnInit();
}
}
if (heapObj != null)
{
heapObj.OnPop();
}
return obj;
}
///
/// Push对象
///
/// The object.
public static void PutObject(T obj)
{
IStackObject heapObj = obj as IStackObject;
if (heapObj != null)
{
heapObj.OnPush();
}
stackPool.Push(obj);
}
}
#endregion
public class StackObjectDict
{
#region string, object字典
public static Dictionary GetSODict()
{
return StackObjectPool>.GetObject();
}
public static void PutSODict(Dictionary dict)
{
dict.Clear();
StackObjectPool>.PutObject(dict);
}
#endregion
}
}