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);
|
heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0);
|
||||||
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
||||||
bps.Init(battlePlayerControls, heroes[i]);
|
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] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||||
heroUIs[i].Init(heroSprites[i], heroes[i]);
|
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);
|
monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0);
|
||||||
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
||||||
bps.Init(battlePlayerControls, monsters[i]);
|
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] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||||
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
||||||
|
|
|
||||||
|
|
@ -61,41 +61,35 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCardClicked(BaseCard card) {
|
private void OnCardClicked(BaseCard card) {
|
||||||
if (!this.waitingForTarget) {
|
if (this.singleTargeting == null) {
|
||||||
if (this.battleController.CanUseCard(card)) {
|
if (this.battleController.CanUseCard(card)) {
|
||||||
OnCardUsed(card);
|
OnCardUsed(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool waitingForTarget = false;
|
private SingleTargeting singleTargeting;
|
||||||
private BattleParticipant participantClicked = null;
|
|
||||||
|
|
||||||
public IEnumerator ChooseTarget(System.Action<BattleParticipant> targetCallback) {
|
public IEnumerator ChooseTarget(SingleTargeting targeting) {
|
||||||
this.waitingForTarget = true;
|
this.singleTargeting = targeting;
|
||||||
while (this.participantClicked == null) {
|
yield return this.singleTargeting.ChooseTarget();
|
||||||
yield return null;
|
this.singleTargeting = null;
|
||||||
}
|
|
||||||
this.waitingForTarget = false;
|
|
||||||
targetCallback(participantClicked);
|
|
||||||
this.participantClicked = null;
|
|
||||||
yield break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnParticipantSpriteClicked(BattleParticipant paticipant) {
|
public void NotifyParticipantSpriteClicked(BattleParticipant participant) {
|
||||||
if (this.waitingForTarget) {
|
if (this.singleTargeting != null) {
|
||||||
this.participantClicked = paticipant;
|
this.singleTargeting.NotifyParticipantSpriteClicked(participant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PassTurnButtonClicked() {
|
public void PassTurnButtonClicked() {
|
||||||
if (!this.waitingForTarget) {
|
if (this.singleTargeting == null) {
|
||||||
OnTurnPassed();
|
OnTurnPassed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTargeting() {
|
public bool IsTargeting() {
|
||||||
return this.waitingForTarget;
|
return this.singleTargeting != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyHandPileChanged() {
|
public void NotifyHandPileChanged() {
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ public class CardCover : BaseCard
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||||
List<BattleParticipant> target = new List<BattleParticipant>();
|
SingleTargeting singleTargeting = new SingleTargeting();
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget((t) => {target.Add(t);}));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
Debug.Log("Covering " + target[0]);
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
target[0].AddBlock(3);
|
Debug.Log("Covering " + target);
|
||||||
|
target.AddBlock(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ public class CardCrashingPunch : BaseCard
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||||
List<BattleParticipant> target = new List<BattleParticipant>();
|
SingleTargeting singleTargeting = new SingleTargeting();
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget((t) => {target.Add(t);}));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
Debug.Log("Punching " + target[0]);
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
target[0].DealDamage(3);
|
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