Refactor BattleSprites out of BattleController
This commit is contained in:
parent
737a851283
commit
eb51ebace0
8 changed files with 110 additions and 61 deletions
|
|
@ -10,13 +10,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private int STARTING_INSIGHT = 3;
|
||||
|
||||
// Inspector public
|
||||
public HeroInfoUI heroUIPrefab;
|
||||
public GameObject uiCanvas;
|
||||
public BattlePlayerControls battlePlayerControls;
|
||||
public EnergyUI heroEnergyUI;
|
||||
public EnergyUI monsterEnergyUI;
|
||||
public Material hitEffectMaterial;
|
||||
public RuntimeAnimatorController runtimeAnimatorController;
|
||||
public BattleSprites battleSprites;
|
||||
|
||||
// Private
|
||||
private HeroCardDatabase heroCardDatabase;
|
||||
|
|
@ -26,12 +24,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private PlayArea playArea;
|
||||
|
||||
private BattleHero[] heroes;
|
||||
private Dictionary<BattleHero, GameObject> heroSprites;
|
||||
private Dictionary<BattleHero, HeroInfoUI> heroUIs;
|
||||
|
||||
private BattleMonster[] monsters;
|
||||
private Dictionary<BattleMonster, GameObject> monsterSprites;
|
||||
private Dictionary<BattleMonster, HeroInfoUI> monsterUIs;
|
||||
|
||||
private BattleState state;
|
||||
private EnergyPool heroEnergy;
|
||||
|
|
@ -66,55 +60,25 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.insightLevel = new InsightLevel(STARTING_INSIGHT);
|
||||
|
||||
this.heroes = new BattleHero[parameters.HeroIds.Length];
|
||||
this.heroSprites = new Dictionary<BattleHero, GameObject>();
|
||||
this.heroUIs = new Dictionary<BattleHero, HeroInfoUI>();
|
||||
for (int i = 0; i < this.heroes.Length; i++) {
|
||||
HeroId id = parameters.HeroIds[i];
|
||||
|
||||
BattleHero hero = new BattleHero(id);
|
||||
hero.Init();
|
||||
this.heroes[i] = hero;
|
||||
|
||||
GameObject sprite = HeroDatabase.createHeroSprite(id);
|
||||
this.heroSprites[hero] = sprite;
|
||||
sprite.name = "Hero" + i + "_Sprite";
|
||||
PositionSprite(TeamChoice.Heroes, sprite, i);
|
||||
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, hero, this.hitEffectMaterial, this.runtimeAnimatorController);
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
hero.OnHit += bps.NotifyHit;
|
||||
hero.OnDeath += bps.NotifyDeath;
|
||||
|
||||
HeroInfoUI heroUI = (HeroInfoUI) Instantiate(this.heroUIPrefab.gameObject, this.uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
heroUI.Init(sprite, hero);
|
||||
this.heroUIs[hero] = heroUI;
|
||||
}
|
||||
|
||||
this.monsters = new BattleMonster[parameters.MonsterIds.Length];
|
||||
this.monsterSprites = new Dictionary<BattleMonster, GameObject>();
|
||||
this.monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < this.monsters.Length; i++) {
|
||||
MonsterId id = parameters.MonsterIds[i];
|
||||
|
||||
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
||||
monster.Init();
|
||||
this.monsters[i] = monster;
|
||||
|
||||
GameObject sprite = MonsterDatabase.createMonsterSprite(id);
|
||||
this.monsterSprites[monster] = sprite;
|
||||
sprite.name = "Monster" + i + "_Sprite";
|
||||
PositionSprite(TeamChoice.Monsters, sprite, i);
|
||||
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, monster, this.hitEffectMaterial, this.runtimeAnimatorController);
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
monster.OnHit += bps.NotifyHit;
|
||||
monster.OnDeath += bps.NotifyDeath;
|
||||
|
||||
HeroInfoUI monsterUI = (HeroInfoUI) Instantiate(this.heroUIPrefab.gameObject, this.uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
monsterUI.Init(sprite, monster);
|
||||
this.monsterUIs[monster] = monsterUI;
|
||||
}
|
||||
|
||||
|
||||
this.battleSprites.Init(this.heroes, this.monsters);
|
||||
|
||||
BattleParticipant[] cardOwners = new BattleParticipant[parameters.HCardIds.Length];
|
||||
for (int i = 0; i < parameters.HCardIds.Length; i++) {
|
||||
cardOwners[i] = this.heroes[parameters.HCardOwnerIndexes[i]];
|
||||
|
|
@ -148,16 +112,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
||||
}
|
||||
|
||||
private void PositionSprite(TeamChoice team, GameObject sprite, int i) {
|
||||
Vector3 pos;
|
||||
if (team == TeamChoice.Heroes) {
|
||||
pos = new Vector3(-0.8f + -3 + 3 * i, -1.8f, 0);
|
||||
} else {
|
||||
pos = new Vector3(+0.8f + -3 + 3 * i, 1.2f, 0);
|
||||
}
|
||||
sprite.transform.position = pos;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -586,7 +540,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
for (int i = 0; i < n; i++) {
|
||||
BattleHero hero = this.heroes[i];
|
||||
newHeroes[newPositions[i]] = hero;
|
||||
PositionSprite(team, heroSprites[hero], newPositions[i]);
|
||||
this.battleSprites.PositionHero(hero, newPositions[i]);
|
||||
}
|
||||
this.heroes = newHeroes;
|
||||
} else {
|
||||
|
|
@ -594,7 +548,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
for (int i = 0; i < n; i++) {
|
||||
BattleMonster monster = this.monsters[i];
|
||||
newMonsters[newPositions[i]] = monster;
|
||||
PositionSprite(team, monsterSprites[monster], newPositions[i]);
|
||||
this.battleSprites.PositionMonster(monster, newPositions[i]);
|
||||
}
|
||||
this.monsters = newMonsters;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue