using System.Collections.Generic; using System.Linq; using UnityEngine; public class TeamManager : GameSystemManager { protected Dictionary teamDict = new Dictionary(); public override void Init() { base.Init(); DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; } public override void Release() { base.Release(); DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; } protected void OnBeforePlayerDataInitialize() { teamDict.Clear(); } public void OnHeroChangeEvent(HB124_tagSCLineupInfo vNetData) { var heroPack = PackManager.Instance.GetSinglePack(PackType.Hero); for (int i = 0; i < vNetData.LineupCnt; i++) { var team = GetTeam((TeamType)vNetData.LineupList[i].LineupID); for (int j = 0; j < vNetData.LineupList[i].HeroCnt; j++) { int index = vNetData.LineupList[i].HeroItemIndexList[j]; HeroInfo hero; if (index == 0) { hero = null; } else { var item = heroPack.GetItemByIndex(vNetData.LineupList[i].HeroItemIndexList[j] - 1); if (item == null) { hero = null; Debug.LogError("没有对应的武将数据!"); } hero = HeroManager.Instance.GetHero(item.guid); } team.RefreshServerData(vNetData.LineupList[i].ShapeType, j, hero); } } } public bool HasTeam(TeamType teamType) { return teamDict.ContainsKey(teamType); } public TeamBase GetTeam(TeamType teamType) { TeamBase team = null; if (!teamDict.TryGetValue(teamType, out team)) { team = new TeamBase(teamType); // team.CreateDefault(HeroManager.Instance.GetPowerfulHeroList()); teamDict.Add(teamType, team); } return team; } }