From 6b0200f518171f478d185151febfa921065cfb52 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Fri, 18 Sep 2020 00:23:38 -0400 Subject: [PATCH] Create cards and make them buttons --- Assets/Battle/BattleController.cs | 9 + Assets/Battle/BattlePlayerControls.cs | 51 ++ Assets/Battle/BattlePlayerControls.cs.meta | 11 + Assets/Battle/CardUI.cs | 25 + Assets/Battle/CardUI.cs.meta | 11 + Assets/Battle/CardUI.prefab | 529 +++++++++++++++++++++ Assets/Battle/CardUI.prefab.meta | 7 + 7 files changed, 643 insertions(+) create mode 100644 Assets/Battle/BattlePlayerControls.cs create mode 100644 Assets/Battle/BattlePlayerControls.cs.meta create mode 100644 Assets/Battle/CardUI.cs create mode 100644 Assets/Battle/CardUI.cs.meta create mode 100644 Assets/Battle/CardUI.prefab create mode 100644 Assets/Battle/CardUI.prefab.meta diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 17ff644..8a4252a 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -9,6 +9,7 @@ public class BattleController : MonoBehaviour public HeroInfoUI heroUIPrefab; public GameObject uiCanvas; + public BattlePlayerControls battlePlayerControls; public BattleHero[] heroes; private GameObject[] heroSprites; @@ -54,6 +55,9 @@ public class BattleController : MonoBehaviour monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); monsterUIs[i].Init(monsterSprites[i], monsters[i]); } + + this.battlePlayerControls.OnCardUsed += this.OnCardUsed; + this.battlePlayerControls.SetHand(5); } // Update is called once per frame @@ -69,4 +73,9 @@ public class BattleController : MonoBehaviour monsters[Random.Range(0, monsters.Length)].dealDamage(2); } } + + public void OnCardUsed(int index) { + Debug.Log("OnCardClicked " + index); + HitRandomParticipant(); + } } diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs new file mode 100644 index 0000000..8008e63 --- /dev/null +++ b/Assets/Battle/BattlePlayerControls.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class BattlePlayerControls : MonoBehaviour +{ + public GameObject uiCanvas; + public GameObject cardPrefab; + + public delegate void CardUsedAction(int i); + public event CardUsedAction OnCardUsed; + + private List cardsInHand; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + public void SetHand(int numberOfCards) { + this.cardsInHand = new List(); + for (int i = 0; i < numberOfCards; i++) { + GameObject newCard = Instantiate(this.cardPrefab, this.uiCanvas.transform); + this.cardsInHand.Add(newCard); + newCard.transform.position = CalculateCardPosition(i, numberOfCards); + Button button = newCard.GetComponent