diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 82047f6..286c51c 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -35,9 +35,8 @@ public class BattleController : MonoBehaviour 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);}; + bps.Init(battlePlayerControls, heroes[i]); + bps.OnSpriteClicked += battlePlayerControls.OnParticipantSpriteClicked; heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); heroUIs[i].Init(heroSprites[i], heroes[i]); @@ -56,9 +55,8 @@ public class BattleController : MonoBehaviour 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);}; + bps.Init(battlePlayerControls, monsters[i]); + bps.OnSpriteClicked += battlePlayerControls.OnParticipantSpriteClicked; monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); monsterUIs[i].Init(monsterSprites[i], monsters[i]); diff --git a/Assets/Battle/BattleParticipantSprite.cs b/Assets/Battle/BattleParticipantSprite.cs index f7bd72b..3dea462 100644 --- a/Assets/Battle/BattleParticipantSprite.cs +++ b/Assets/Battle/BattleParticipantSprite.cs @@ -4,13 +4,15 @@ using UnityEngine; public class BattleParticipantSprite : MonoBehaviour { - public delegate void SpriteClickedAction(); + public delegate void SpriteClickedAction(BattleParticipant participant); public event SpriteClickedAction OnSpriteClicked; private BattlePlayerControls playerControls; + private BattleParticipant participant; - public void Init(BattlePlayerControls playerControls) { + public void Init(BattlePlayerControls playerControls, BattleParticipant participant) { this.playerControls = playerControls; + this.participant = participant; } // Start is called before the first frame update @@ -27,7 +29,7 @@ public class BattleParticipantSprite : MonoBehaviour void OnMouseDown() { Debug.Log("Clicked " + this.name); - OnSpriteClicked(); + OnSpriteClicked(participant); } private Color savedColor;