Create SingleTargeting
This commit is contained in:
parent
05fee309c3
commit
611601934d
6 changed files with 57 additions and 27 deletions
|
|
@ -43,7 +43,7 @@ public class BattleController : MonoBehaviour
|
|||
heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0);
|
||||
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, heroes[i]);
|
||||
bps.OnSpriteClicked += battlePlayerControls.OnParticipantSpriteClicked;
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
|
||||
heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
heroUIs[i].Init(heroSprites[i], heroes[i]);
|
||||
|
|
@ -63,7 +63,7 @@ public class BattleController : MonoBehaviour
|
|||
monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0);
|
||||
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, monsters[i]);
|
||||
bps.OnSpriteClicked += battlePlayerControls.OnParticipantSpriteClicked;
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
|
||||
monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
||||
|
|
|
|||
|
|
@ -61,41 +61,35 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
}
|
||||
|
||||
private void OnCardClicked(BaseCard card) {
|
||||
if (!this.waitingForTarget) {
|
||||
if (this.singleTargeting == null) {
|
||||
if (this.battleController.CanUseCard(card)) {
|
||||
OnCardUsed(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool waitingForTarget = false;
|
||||
private BattleParticipant participantClicked = null;
|
||||
private SingleTargeting singleTargeting;
|
||||
|
||||
public IEnumerator ChooseTarget(System.Action<BattleParticipant> targetCallback) {
|
||||
this.waitingForTarget = true;
|
||||
while (this.participantClicked == null) {
|
||||
yield return null;
|
||||
}
|
||||
this.waitingForTarget = false;
|
||||
targetCallback(participantClicked);
|
||||
this.participantClicked = null;
|
||||
yield break;
|
||||
public IEnumerator ChooseTarget(SingleTargeting targeting) {
|
||||
this.singleTargeting = targeting;
|
||||
yield return this.singleTargeting.ChooseTarget();
|
||||
this.singleTargeting = null;
|
||||
}
|
||||
|
||||
public void OnParticipantSpriteClicked(BattleParticipant paticipant) {
|
||||
if (this.waitingForTarget) {
|
||||
this.participantClicked = paticipant;
|
||||
public void NotifyParticipantSpriteClicked(BattleParticipant participant) {
|
||||
if (this.singleTargeting != null) {
|
||||
this.singleTargeting.NotifyParticipantSpriteClicked(participant);
|
||||
}
|
||||
}
|
||||
|
||||
public void PassTurnButtonClicked() {
|
||||
if (!this.waitingForTarget) {
|
||||
if (this.singleTargeting == null) {
|
||||
OnTurnPassed();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTargeting() {
|
||||
return this.waitingForTarget;
|
||||
return this.singleTargeting != null;
|
||||
}
|
||||
|
||||
public void NotifyHandPileChanged() {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ public class CardCover : BaseCard
|
|||
}
|
||||
|
||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||
List<BattleParticipant> target = new List<BattleParticipant>();
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget((t) => {target.Add(t);}));
|
||||
Debug.Log("Covering " + target[0]);
|
||||
target[0].AddBlock(3);
|
||||
SingleTargeting singleTargeting = new SingleTargeting();
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||
BattleParticipant target = singleTargeting.GetTarget();
|
||||
Debug.Log("Covering " + target);
|
||||
target.AddBlock(3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ public class CardCrashingPunch : BaseCard
|
|||
}
|
||||
|
||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||
List<BattleParticipant> target = new List<BattleParticipant>();
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget((t) => {target.Add(t);}));
|
||||
Debug.Log("Punching " + target[0]);
|
||||
target[0].DealDamage(3);
|
||||
SingleTargeting singleTargeting = new SingleTargeting();
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||
BattleParticipant target = singleTargeting.GetTarget();
|
||||
Debug.Log("Punching " + target);
|
||||
target.DealDamage(3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
Assets/Battle/SingleTargeting.cs
Normal file
23
Assets/Battle/SingleTargeting.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SingleTargeting
|
||||
{
|
||||
private BattleParticipant participantClicked;
|
||||
|
||||
public IEnumerator ChooseTarget() {
|
||||
while (this.participantClicked == null) {
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyParticipantSpriteClicked(BattleParticipant paticipant) {
|
||||
this.participantClicked = paticipant;
|
||||
}
|
||||
|
||||
public BattleParticipant GetTarget() {
|
||||
return this.participantClicked;
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/SingleTargeting.cs.meta
Normal file
11
Assets/Battle/SingleTargeting.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e3ab2e9de8e9054ca09847226a7c1a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue