using System.Collections; using System.Collections.Generic; using UnityEngine; public class BattleObjMgr : Singleton { private List redCampList => new List(redCampDict.Values); private List blueCampList => new List(blueCampDict.Values); private Dictionary redCampDict = new Dictionary(); private Dictionary blueCampDict = new Dictionary(); public void Init(int _levelId, TeamBase _redTeam, TeamBase _blueTeam = null) { if (_levelId == 0 && _blueTeam == null) { Debug.LogError("BattleObjMgr Init Error: _levelId == 0 && _blueTeam == null 关卡id没有(不是PVE) 也没有蓝色队伍信息(也不是PVP))"); return; } if (_levelId != 0 && _blueTeam != null) { Debug.LogError("BattleObjMgr Init Error: _levelId!= 0 && _blueTeam != null 关卡id有(是PVE) 也有蓝色队伍信息(也不是PVP))"); return; } if (_levelId != 0) { _blueTeam = new TeamBase(); _blueTeam.InitByLevelId(_levelId); } CreateTeam(redCampDict, _redTeam); CreateTeam(blueCampDict, _blueTeam); } protected void CreateTeam(Dictionary campDict, TeamBase teamBase) { DestroyTeam(campDict); for (int i = 0; i < teamBase.teamHeros.Length; i++) { TeamHero teamHero = teamBase.teamHeros[i]; if (teamHero != null) { BattleObject battleObj = BattleObjectFactory.CreateBattleObject(teamHero); battleObj.Init(teamHero); campDict.Add(teamHero.heroIndex, battleObj); } } } protected void DestroyTeam(Dictionary campDict) { foreach (var item in campDict) { BattleObject battleObj = item.Value; if (battleObj!= null) { BattleObjectFactory.DestroyBattleObject(battleObj); } } campDict.Clear(); } public void Release() { DestroyTeam(redCampDict); DestroyTeam(blueCampDict); } public void Run() { foreach (var item in redCampDict) { item.Value.Run(); } foreach (var item in blueCampDict) { item.Value.Run(); } } }