Draw monster hand
This commit is contained in:
parent
fb453702ba
commit
c7d2302326
3 changed files with 31 additions and 12 deletions
|
|
@ -4,6 +4,11 @@ using System.Linq;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public enum HandControlsPosition {
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
||||
{
|
||||
public delegate void CardClickedAction(BaseCardT card);
|
||||
|
|
@ -11,15 +16,17 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
|||
|
||||
private GameObject uiCanvas;
|
||||
private GameObject cardPrefab;
|
||||
private HandControlsPosition position;
|
||||
|
||||
private List<GameObject> cardsInHandUIs;
|
||||
|
||||
public HandControls(GameObject uiCanvas, GameObject cardPrefab) {
|
||||
public HandControls(GameObject uiCanvas, GameObject cardPrefab, HandControlsPosition position) {
|
||||
this.uiCanvas = uiCanvas;
|
||||
this.cardPrefab = cardPrefab;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void SetHeroHand(List<BaseCardT> hand) {
|
||||
public void SetHand(List<BaseCardT> hand) {
|
||||
if (this.cardsInHandUIs != null) {
|
||||
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
|
||||
GameObject.Destroy(cardInHandUI);
|
||||
|
|
@ -42,8 +49,11 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
|||
const int SPACING = 8;
|
||||
const int DELTA = BattleCardPrefabConstants.CARD_WIDTH + SPACING;
|
||||
|
||||
return new Vector3(Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index,
|
||||
SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2,
|
||||
0);
|
||||
float x = Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index;
|
||||
float y = (this.position == HandControlsPosition.Bottom
|
||||
? SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2
|
||||
: Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT / 2);
|
||||
|
||||
return new Vector3(x, y, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue