Simplify OnParticipantSpriteClicked setup
This commit is contained in:
parent
d8af43db53
commit
ee8d66610e
2 changed files with 9 additions and 9 deletions
|
|
@ -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<BattleParticipantSprite>();
|
||||
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<BattleParticipantSprite>();
|
||||
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]);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue