using System.Collections; using System.Collections.Generic; using UnityEngine; public class BattleController : MonoBehaviour { public HeroId[] heroIds; public MonsterId[] monsterIds; public HeroInfoUI heroUIPrefab; public GameObject uiCanvas; public BattlePlayerControls battlePlayerControls; public BattleHero[] heroes; private GameObject[] heroSprites; private HeroInfoUI[] heroUIs; public BattleMonster[] monsters; private GameObject[] monsterSprites; private HeroInfoUI[] monsterUIs; // Start is called before the first frame update void Start() { heroes = new BattleHero[3]; heroSprites = new GameObject[3]; heroUIs = new HeroInfoUI[3]; for (int i = 0; i < 3; i++) { HeroId id = heroIds[i]; heroes[i] = new BattleHero(id); heroes[i].Init(); heroSprites[i] = HeroDatabase.createHeroSprite(id); heroSprites[i].name = "Hero" + i + "_Sprite"; heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0); BattleParticipantSprite bps = heroSprites[i].AddComponent(); bps.Init(battlePlayerControls); BattleParticipant participant = heroes[i]; bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); heroUIs[i].Init(heroSprites[i], heroes[i]); } monsters = new BattleMonster[3]; monsterSprites = new GameObject[3]; monsterUIs = new HeroInfoUI[3]; for (int i = 0; i < 3; i++) { MonsterId id = monsterIds[i]; monsters[i] = MonsterDatabase.createMonsterScript(id); monsters[i].Init(); monsterSprites[i] = MonsterDatabase.createMonsterSprite(id); monsterSprites[i].name = "Monster" + i + "_Sprite"; monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0); BattleParticipantSprite bps = monsterSprites[i].AddComponent(); bps.Init(battlePlayerControls); BattleParticipant participant = monsters[i]; bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); monsterUIs[i].Init(monsterSprites[i], monsters[i]); } this.battlePlayerControls.OnCardUsed += this.OnCardUsed; this.battlePlayerControls.OnTurnPassed += this.OnTurnPassed; this.battlePlayerControls.SetHand(5); } // Update is called once per frame void Update() { } public void OnCardUsed(BaseCard card) { Debug.Log("OnCardClicked " + card); StartCoroutine(card.Use(battlePlayerControls)); } public void OnTurnPassed() { Debug.Log("OnTurnPassed"); } }