/// <summary> /// Makes this visualizer invisible to the user over a time period. /// </summary> public void HideVisualizer(CardGrabber grabber) { StartCoroutine(ScaleDownCoroutine(grabber, _zoomSpeed, () => { Destroy(gameObject); })); }
/// <summary> /// Removes played card grabber from the game. /// </summary> public void ResolveCardPlay(MatchMessageCardPlayed message) { CardGrabber grabber = _cardsInHand[message.CardSlotIndex]; grabber.Resolve(message); _cardsInHand.RemoveAt(message.CardSlotIndex); Destroy(grabber.gameObject); }
/// <summary> /// Makes this visualizer visible to the user over a time period. /// </summary> public void ShowVisualizer(CardGrabber grabber, bool isHost) { if (isHost) { transform.Rotate(Vector3.up, 180); } StartCoroutine(ScaleUpCoroutine(grabber, _zoomSpeed)); }
/// <summary> /// Prevents given card from being played. /// Returns it to user's hand. /// </summary> private void CancelPlay(MatchMessageCardCanceled message) { CardGrabber grabber = _cardsInHand[message.CardSlotIndex]; grabber.OnDragStarted += StartCardDrag; grabber.OnCardReturned += ReturnCard; grabber.OnCardPlayed += PlayCard; grabber.CancelPlay(); }
/// <summary> /// Scales this visualizer up over time. /// Scales <see cref="CardGrabber"/> held by the user down over the same time period. /// Invokes <paramref name="onEnded"/> when finished. /// </summary> private IEnumerator ScaleUpCoroutine(CardGrabber grabber, float speed, Action onEnded = null) { float scale = _minScale; while (scale < _maxScale) { scale = Mathf.Min(scale + speed * Time.deltaTime, _maxScale); transform.localScale = Vector3.one * scale; grabber.transform.localScale = Vector3.one * (1 - scale); yield return(null); } onEnded?.Invoke(); }
/// <summary> /// Invoked on card played. /// Sends <see cref="MatchMessageCardPlayRequest"/> to host. /// </summary> private void PlayCard(CardGrabber grabber, Vector3 dropPosition) { grabber.OnDragStarted -= StartCardDrag; grabber.OnCardReturned -= ReturnCard; grabber.OnCardPlayed -= PlayCard; string id = _connection.Session.UserId; int index = _cardsInHand.IndexOf(grabber); //_cardsInHand.RemoveAt(index); MatchMessageCardPlayRequest message = new MatchMessageCardPlayRequest( id, grabber.Card, index, dropPosition.x, dropPosition.y, dropPosition.z); OnCardPlayed?.Invoke(message); CurrentlyGrabbedCard = null; //Destroy(grabber.gameObject); }
/// <summary> /// Creates <see cref="CardGrabber"/> instance and initializes it. /// </summary> public CardGrabber DrawCard(Card card, int slotId) { Transform slot = _cardSlots[slotId]; RectTransform region = SelectRegion(card); CardGrabber cardGrabber = Instantiate(_inGameCardPrefab, slot, false); cardGrabber.Init(_stateManager, _connection.BattleConnection.HostId == _connection.Session.UserId); cardGrabber.transform.position = _drawPosition.position; cardGrabber.Initialize(card, slot, _handRegion, region, _canvasScaler); cardGrabber.OnCardPlayed += PlayCard; cardGrabber.OnDragStarted += StartCardDrag; cardGrabber.OnCardReturned += ReturnCard; _cardsInHand.Insert(slotId, cardGrabber); return(cardGrabber); }
/// <summary> /// Invoked on card returning to hand. /// </summary> private void ReturnCard(CardGrabber grabber) { grabber.transform.SetParent(grabber.Slot); OnCardReturned?.Invoke(grabber); CurrentlyGrabbedCard = null; }
/// <summary> /// Invoked on card grab. /// </summary> private void StartCardDrag(CardGrabber grabber) { grabber.transform.SetParent(_dragParent); CurrentlyGrabbedCard = grabber; OnCardGrabbed?.Invoke(grabber); }