Add CrashingPunch and making it work
This commit is contained in:
parent
1c3056778e
commit
d7c19e2572
15 changed files with 204 additions and 27 deletions
|
|
@ -5,13 +5,15 @@ using UnityEngine.UI;
|
|||
|
||||
public class BattlePlayerControls : MonoBehaviour
|
||||
{
|
||||
public BattleController battleController;
|
||||
public GameObject uiCanvas;
|
||||
public GameObject cardPrefab;
|
||||
|
||||
public delegate void CardUsedAction(int i);
|
||||
public delegate void CardUsedAction(BaseCard card);
|
||||
public event CardUsedAction OnCardUsed;
|
||||
|
||||
private List<GameObject> cardsInHand;
|
||||
private List<BaseCard> cardsInHand;
|
||||
private List<GameObject> cardsInHandUIs;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
|
@ -26,14 +28,19 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
}
|
||||
|
||||
public void SetHand(int numberOfCards) {
|
||||
this.cardsInHand = new List<GameObject>();
|
||||
this.cardsInHand = new List<BaseCard>();
|
||||
this.cardsInHandUIs = new List<GameObject>();
|
||||
for (int i = 0; i < numberOfCards; i++) {
|
||||
GameObject newCard = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
||||
// TODO
|
||||
BaseCard newCard = new CardCrashingPunch();
|
||||
this.cardsInHand.Add(newCard);
|
||||
newCard.transform.position = CalculateCardPosition(i, numberOfCards);
|
||||
Button button = newCard.GetComponent<Button>();
|
||||
|
||||
GameObject newCardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
||||
this.cardsInHandUIs.Add(newCardUI);
|
||||
newCardUI.transform.position = CalculateCardPosition(i, numberOfCards);
|
||||
newCardUI.GetComponent<CardUI>().Init(newCard);
|
||||
int cardIndex = i;
|
||||
button.onClick.AddListener(delegate {OnCardClicked(cardIndex);});
|
||||
newCardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(newCard);});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +52,27 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
return new Vector3(Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index, 160, 0);
|
||||
}
|
||||
|
||||
private void OnCardClicked(int index) {
|
||||
OnCardUsed(index);
|
||||
private void OnCardClicked(BaseCard card) {
|
||||
OnCardUsed(card);
|
||||
}
|
||||
|
||||
private bool waitingForTarget = false;
|
||||
private BattleParticipant participantClicked = null;
|
||||
|
||||
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 void OnParticipantSpriteClicked(BattleParticipant paticipant) {
|
||||
if (this.waitingForTarget) {
|
||||
this.participantClicked = paticipant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue