/// <summary> /// 将某个游戏子系统加入到创建列表中,初始化(如果有)将立即执行,如果有更新将于下一帧执行 /// 游戏子系统如需更新需要重写基类相关函数 /// </summary> /// <typeparam name="T">游戏子系统类型</typeparam> /// <param name="isInit">是否执行初始化</param> /// <param name="isUpdate">是否更新</param> /// <param name="isFixUpdate">是否固定帧率更新</param> /// <param name="isLateUpdte">是否延迟更新</param> public void addObjToCreateList <T>(bool isInit, bool isUpdate, bool isFixUpdate = false, bool isLateUpdte = false) { GameObjectInfo info = new GameObjectInfo(); info._type = Type.GetType(typeof(T).FullName); object t = Activator.CreateInstance(info._type); info._obj = t; info._isInit = isInit; info._isUpdate = isUpdate; info._isFixUpdate = isFixUpdate; info._isLateUpdate = isLateUpdte; gameSubSystemAddList_.Add(info); if (isInit) { ((GameSubSystem)t).init(); } }
virtual public void update() { for (int i = 0; i < gameSubSystemRemoveList.Count; i++) { Type t = gameSubSystemRemoveList[i].GetType(); gameSubSystemList_.Remove(t); gameSubSystemUpdateList_.Remove(t); gameSubSystemFixUpdateList_.Remove(t); gameSubSystemLateUpdateList_.Remove(t); } for (int i = 0; i < gameSubSystemAddList_.Count; i++) { GameObjectInfo goi = gameSubSystemAddList_[i]; createObject(goi._obj, goi._type, goi._isUpdate, goi._isFixUpdate, goi._isLateUpdate); } gameSubSystemRemoveList.Clear(); gameSubSystemAddList_.Clear(); Dictionary <Type, GameSubSystem> .Enumerator enumrator = gameSubSystemUpdateList_.GetEnumerator(); while (enumrator.MoveNext()) { enumrator.Current.Value.update(Time.deltaTime); } }