using System.Collections.Generic; [XLua.LuaCallCSharp] public class FlyObjectManager : Singleton { private ObjectPool m_FlyObjectPool; private List m_RemoveList; private Dictionary> m_FlyObjectDict = null; private Dictionary> m_FlyObjectPoolDict = null; public void Initialize() { m_FlyObjectPool = new ObjectPool(OnGet, OnRelease); m_RemoveList = new List(); m_FlyObjectDict = new Dictionary>(); m_FlyObjectPoolDict = new Dictionary>(); } public IFlyObject Create(FlyObject.InitInfo initInfo) { SoFlyObject _so = ScriptableObjectLoader.LoadSoFlyObject(initInfo.configId); int _intType = (int)_so.type; IFlyObject _obj = null; ObjectPool _pool = null; if (m_FlyObjectPoolDict.TryGetValue(_intType, out _pool) == false) { _pool = new ObjectPool(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 _list = null; if (m_FlyObjectDict.TryGetValue(_intType, out _list) == false) { _list = new List(); m_FlyObjectDict.Add(_intType, _list); } _list.Add(_obj); return _obj; } public void Update() { List _list = null; ObjectPool _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(); } }