From 57dbe84b3d1da53c344b7a3c53e43e0187ab5b64 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Sun, 20 Sep 2020 14:12:04 -0400 Subject: [PATCH] Refactor HeroHandControls out of BattlePlayerControls --- Assets/Battle/BattleCardPrefabConstants.cs | 11 ++++ .../Battle/BattleCardPrefabConstants.cs.meta | 11 ++++ Assets/Battle/BattlePlayerControls.cs | 44 +++------------- Assets/Battle/HeroHandControls.cs | 51 +++++++++++++++++++ Assets/Battle/HeroHandControls.cs.meta | 11 ++++ 5 files changed, 92 insertions(+), 36 deletions(-) create mode 100644 Assets/Battle/BattleCardPrefabConstants.cs create mode 100644 Assets/Battle/BattleCardPrefabConstants.cs.meta create mode 100644 Assets/Battle/HeroHandControls.cs create mode 100644 Assets/Battle/HeroHandControls.cs.meta diff --git a/Assets/Battle/BattleCardPrefabConstants.cs b/Assets/Battle/BattleCardPrefabConstants.cs new file mode 100644 index 0000000..010f769 --- /dev/null +++ b/Assets/Battle/BattleCardPrefabConstants.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.UI; + +public class BattleCardPrefabConstants +{ + public const int CARD_WIDTH = 122; + public const int CARD_HEIGHT = 155; +} diff --git a/Assets/Battle/BattleCardPrefabConstants.cs.meta b/Assets/Battle/BattleCardPrefabConstants.cs.meta new file mode 100644 index 0000000..9c8f705 --- /dev/null +++ b/Assets/Battle/BattleCardPrefabConstants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27a83f780e888aa4e936b6400b5b4eab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 738ee96..d53f310 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -19,8 +19,9 @@ public class BattlePlayerControls : MonoBehaviour private BattleDeck heroDeck; private BattleDeck monsterDeck; - private List cardsInHandUIs; private PlayArea playArea; + + private HeroHandControls heroHandControls; private Dictionary cardsInPlayUIs; public void Init( @@ -29,6 +30,8 @@ public class BattlePlayerControls : MonoBehaviour this.monsterDeck = monsterDeck; this.playArea = playArea; + this.heroHandControls = new HeroHandControls(this, this.uiCanvas, this.cardPrefab); + this.heroHandControls.OnCardClicked += OnCardClicked; this.cardsInPlayUIs = new Dictionary(); } @@ -45,41 +48,10 @@ public class BattlePlayerControls : MonoBehaviour } - private void SetHeroHand(List hand) { - if (this.cardsInHandUIs != null) { - foreach (GameObject cardInHandUI in this.cardsInHandUIs) { - Destroy(cardInHandUI); - } - } - - this.cardsInHandUIs = new List(); - for (int i = 0; i < hand.Count; i++) { - HeroCard card = hand[i]; - GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform); - this.cardsInHandUIs.Add(cardUI); - cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); - cardUI.GetComponent().Init(card); - int cardIndex = i; - cardUI.GetComponent