// method to add a card to the table public void AddCard(CardAsset cardAsset, Vector3 handPosition, int monsterIndex) { // create a new card from prefab GameObject card; card = GameObject.Instantiate(GameStateSync.Instance.SkillCardPrefab, handPosition, Quaternion.Euler(new Vector3(0f, -179f, 0f))) as GameObject; // apply the look of the card based on the info from CardAsset SkillCardManager manager = card.GetComponent <SkillCardManager>(); manager.cardAsset = cardAsset; manager.ReadCardFromAsset(); // parent this card to our open slot Transform openSlot = FindOpenSlot(monsterIndex); card.transform.SetParent(openSlot); // Bring card to front while it travels from draw spot to hand WhereIsTheCardOrMonster w = card.GetComponent <WhereIsTheCardOrMonster>(); w.SendToBack(); w.Slot = monsterIndex; // move card to the hand; Sequence s = DOTween.Sequence(); s.Insert(0f, card.transform.DORotate(Vector3.zero, GameStateSync.Instance.CardTransitionTime)); s.Append(card.transform.DOMove(openSlot.position, GameStateSync.Instance.CardTransitionTime)); s.OnComplete(() => Command.CommandExecutionComplete()); }
public override void OnEndDrag() { // determine if over a valid target GameObject target = DragTarget(); // turn off user monster highlights PlayerArea area = GameStateSync.Instance.playerArea; MonsterVisual monsterVisual = area.monsterVisual; monsterVisual.turnOffAllHighlights(); if (target != null) { // turn off hand highlights HandVisual handVisual = GameStateSync.Instance.playerArea.handVisual; handVisual.turnOffAllHighlights(GameStateSync.Instance.playerArea); // target monster index MonsterManager monsterManager = target.GetComponent <MonsterManager>(); AvatarManager avatarManager = target.GetComponentInChildren <AvatarManager>(); int targetIndex = monsterManager == null ? 3 : monsterManager.index; // find first open skill slot Transform openSkillSlot = monsterVisual.FindOpenSlot(targetIndex); transform.SetParent(openSkillSlot); whereIsCard.SetHandSortingOrder(); whereIsCard.VisualState = tempState; transform.DOMove(openSkillSlot.position, 1f); whereIsCard.SendToBack(); GameStateSync.Instance.playableRequest.playedCardIndexes.Add(savedHandSlot); if (GameStateSync.Instance.gameView.phase == GameStateSync.GUTS_PHASE) { // increment guts avatarManager.gutsText.text = (Int32.Parse(avatarManager.gutsText.text) + 1).ToString(); // make this invisible Canvas canvas = GetComponentInChildren <Canvas>(); canvas.gameObject.SetActive(false); BoxCollider collider = GetComponentInChildren <BoxCollider>(); collider.enabled = false; } if (GameStateSync.Instance.gameView.phase == GameStateSync.ATTACK_PHASE) { // add to cards played GameStateSync.Instance.attackRequest.user = monsterManager.index; GameStateSync.Instance.attackRequest.cardsPlayed.Add(savedHandSlot); GameStateSync.Instance.playableRequest.user = monsterManager.index; // highlight user to attack area.monsterVisual.HighlightMonster(area.highlightColor, monsterManager.index, true); } if (GameStateSync.Instance.gameView.phase == GameStateSync.DEFEND_PHASE) { // add to defend request DefendTarget defendTarget = new DefendTarget(); defendTarget.card = savedHandSlot; defendTarget.user = monsterManager.index; GameStateSync.Instance.defendRequest.cardAndTargets.Add(defendTarget); } // highlight other playable cards StartCoroutine(GameStateSync.Instance.HighlightPlayableCards()); } else { // Set old sorting order whereIsCard.SetHandSortingOrder(); whereIsCard.VisualState = tempState; // Move this card back to its slot position HandVisual PlayerHand = GameStateSync.Instance.playerArea.handVisual; Vector3 oldCardPos = PlayerHand.slots.Children[savedHandSlot].transform.position; transform.DOMove(oldCardPos, 1f); } }