using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class BattleObjMgr : Singleton<BattleObjMgr>
|
{
|
private List<BattleObject> redCampList => new List<BattleObject>(redCampDict.Values);
|
private List<BattleObject> blueCampList => new List<BattleObject>(blueCampDict.Values);
|
private Dictionary<int, BattleObject> redCampDict = new Dictionary<int, BattleObject>();
|
private Dictionary<int, BattleObject> blueCampDict = new Dictionary<int, BattleObject>();
|
|
public void Init(TeamBase _redTeam, TeamBase _blueTeam)
|
{
|
CreateTeam(redCampDict, _redTeam);
|
CreateTeam(blueCampDict, _blueTeam);
|
}
|
|
protected void CreateTeam(Dictionary<int, BattleObject> 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<int, BattleObject> 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();
|
}
|
}
|
|
public void ResumeGame()
|
{
|
foreach (var item in redCampList)
|
{
|
item.ResumeGame();
|
}
|
|
foreach (var item in blueCampList)
|
{
|
item.ResumeGame();
|
}
|
}
|
|
public void PauseGame()
|
{
|
foreach (var item in redCampList)
|
{
|
item.PauseGame();
|
}
|
|
foreach (var item in blueCampList)
|
{
|
item.PauseGame();
|
}
|
}
|
}
|