using System.Collections.Generic;
|
|
[XLua.LuaCallCSharp]
|
public class FlyObjectManager : Singleton<FlyObjectManager>
|
|
{
|
|
private ObjectPool<IFlyObject> m_FlyObjectPool;
|
private List<IFlyObject> m_RemoveList;
|
|
private Dictionary<int, List<IFlyObject>> m_FlyObjectDict = null;
|
private Dictionary<int, ObjectPool<IFlyObject>> m_FlyObjectPoolDict = null;
|
|
public void Initialize()
|
{
|
m_FlyObjectPool = new ObjectPool<IFlyObject>(OnGet, OnRelease);
|
m_RemoveList = new List<IFlyObject>();
|
m_FlyObjectDict = new Dictionary<int, List<IFlyObject>>();
|
m_FlyObjectPoolDict = new Dictionary<int, ObjectPool<IFlyObject>>();
|
}
|
|
public IFlyObject Create(FlyObject.InitInfo initInfo)
|
{
|
|
SoFlyObject _so = ScriptableObjectLoader.LoadSoFlyObject(initInfo.configId);
|
int _intType = (int)_so.type;
|
|
IFlyObject _obj = null;
|
|
ObjectPool<IFlyObject> _pool = null;
|
|
if (m_FlyObjectPoolDict.TryGetValue(_intType, out _pool) == false)
|
{
|
_pool = new ObjectPool<IFlyObject>(OnGet, OnRelease);
|
m_FlyObjectPoolDict.Add(_intType, _pool);
|
}
|
|
if (_so.type == SoFlyObject.E_FlyObjectType.Cyclotron)
|
{
|
|
}
|
else if (_so.type == SoFlyObject.E_FlyObjectType.Normal)
|
{
|
if (_pool.inactivedCount == 0)
|
{
|
_pool.Add(new FoNormal());
|
}
|
}
|
else if (_so.type == SoFlyObject.E_FlyObjectType.Transmit)
|
{
|
|
if (_pool.inactivedCount == 0)
|
{
|
_pool.Add(new FoTransmit());
|
}
|
}
|
else if (_so.type == SoFlyObject.E_FlyObjectType.Follow)
|
{
|
|
if (_pool.inactivedCount == 0)
|
{
|
_pool.Add(new FoFollow());
|
}
|
}
|
|
_obj = _pool.Get();
|
_obj.Initialize(initInfo);
|
|
List<IFlyObject> _list = null;
|
|
if (m_FlyObjectDict.TryGetValue(_intType, out _list) == false)
|
{
|
_list = new List<IFlyObject>();
|
m_FlyObjectDict.Add(_intType, _list);
|
}
|
|
_list.Add(_obj);
|
|
return _obj;
|
}
|
|
public void Update()
|
{
|
List<IFlyObject> _list = null;
|
ObjectPool<IFlyObject> _pool = null;
|
int _intType = (int)SoFlyObject.E_FlyObjectType.Normal;
|
|
if (m_FlyObjectDict.TryGetValue(_intType, out _list))
|
{
|
for (int i = 0; i < _list.Count; ++i)
|
{
|
_list[i].Update();
|
if (_list[i].IsOver())
|
{
|
_list[i].OnOver();
|
m_RemoveList.Add(_list[i]);
|
}
|
}
|
}
|
|
_intType = (int)SoFlyObject.E_FlyObjectType.Transmit;
|
|
if (m_FlyObjectDict.TryGetValue(_intType, out _list))
|
{
|
for (int i = 0; i < _list.Count; ++i)
|
{
|
_list[i].Update();
|
if (_list[i].IsOver())
|
{
|
_list[i].OnOver();
|
m_RemoveList.Add(_list[i]);
|
}
|
}
|
}
|
|
|
_intType = (int)SoFlyObject.E_FlyObjectType.Follow;
|
|
if (m_FlyObjectDict.TryGetValue(_intType, out _list))
|
{
|
for (int i = 0; i < _list.Count; ++i)
|
{
|
_list[i].Update();
|
if (_list[i].IsOver())
|
{
|
_list[i].OnOver();
|
m_RemoveList.Add(_list[i]);
|
}
|
}
|
}
|
|
for (int i = 0; i < m_RemoveList.Count; ++i)
|
{
|
if (m_RemoveList[i].IsOver())
|
{
|
if (m_RemoveList[i] is FoNormal)
|
{
|
_intType = (int)SoFlyObject.E_FlyObjectType.Normal;
|
}
|
else if (m_RemoveList[i] is FoTransmit)
|
{
|
_intType = (int)SoFlyObject.E_FlyObjectType.Transmit;
|
}
|
else if (m_RemoveList[i] is FoFollow)
|
{
|
_intType = (int)SoFlyObject.E_FlyObjectType.Follow;
|
}
|
|
if (m_FlyObjectPoolDict.TryGetValue(_intType, out _pool) == false)
|
{
|
continue;
|
}
|
|
if (m_FlyObjectPoolDict.TryGetValue(_intType, out _pool) == false)
|
{
|
continue;
|
}
|
|
if (m_FlyObjectDict.TryGetValue(_intType, out _list) == false)
|
{
|
continue;
|
}
|
|
_pool.Release(m_RemoveList[i]);
|
_list.Remove(m_RemoveList[i]);
|
}
|
}
|
|
m_RemoveList.Clear();
|
}
|
|
private void OnGet(IFlyObject obj)
|
{
|
|
}
|
|
private void OnRelease(IFlyObject obj)
|
{
|
obj.UnInitialize();
|
}
|
|
}
|