예제 #1
0
            public override void Destroy()
            {
                base.Destroy();

                _pointerEnterAnim?.Stop();
                _pointerExitAnim?.Stop();
                _pointerDownAnim?.Stop();
                _animateAwayAnim?.Stop();
                _animateSelectedAnim?.Stop();
            }
예제 #2
0
        private void Unit_OnTookDamage(object sender, Unit.DamageEventArgs e)
        {
            if (e.wasKilled)
            {
                _unit.OnTookDamage -= Unit_OnTookDamage;
            }

            if (!IsShowing)
            {
                Show();
            }

            _healthbarAnim?.Stop();

            float startFill = e.previousHealth / (float)e.targetUnit.MaxHealth;
            float endFill   = e.newHealth / (float)e.targetUnit.MaxHealth;

            _healthbarAnim = new TofuAnimation()
                             .Value01(HealthBarAnimTime, EEaseType.Linear, (float newValue) =>
            {
                _healthBar.Percent = Mathf.LerpUnclamped(startFill, endFill, newValue);
            })
                             .Then()
                             .Wait(2f)
                             .Then()
                             .Execute(() =>
            {
                Hide();
            })
                             .Play();
        }
예제 #3
0
        // --------------------------------------------------------------------------------------------
        private void SetVisible(bool visible)
        {
            _visible = visible;

            _fadeAnimation?.Stop();

            float startAlpha = _canvasGroup.alpha;
            float endAlpha   = visible ? 1f : 0f;
            float time       = visible ? _fadeAnimTime * (1f - startAlpha) : _fadeAnimTime * startAlpha;

            _fadeAnimation = new TofuAnimation()
                             .Value01(time, EEaseType.Linear, (float newValue) =>
            {
                if (this)
                {
                    // check that we haven't been destroyed
                    _canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, newValue);
                }
            })
                             .Then()
                             .Wait(_visible ? _lingerTime : 0f)
                             .Then()
                             .Execute(() =>
            {
                _fadeAnimation = null;
            })
                             .Play();
        }
예제 #4
0
파일: Actor.cs 프로젝트: njelly/GridRPG
        public void SetTile(Tile tile, bool teleport)
        {
            _moveAnim?.Stop();

            Vector3 targetPos = tile.LocalPosition;

            if (teleport)
            {
                _moveAnim     = null;
                LocalPosition = targetPos;
            }
            else
            {
                Vector3 startPos = LocalPosition;
                float   animTime = Mathf.Abs(_state.moveSpeed) > 0f ? _state.moveSpeed : float.MaxValue;
                _moveAnim = new TofuAnimation()
                            .Value01(animTime, EEaseType.Linear, (float newValue) =>
                {
                    LocalPosition = Vector3.LerpUnclamped(startPos, targetPos, newValue);
                })
                            .Then()
                            .Execute(() =>
                {
                    _moveAnim = null;
                })
                            .Play();
            }
        }
예제 #5
0
        // --------------------------------------------------------------------------------------------
        private void UpdateReticleMove()
        {
            if (_previousInteractOffset.IsApproximately(_actor.InteractOffset, 0.01f))
            {
                return;
            }

            _previousInteractOffset = _actor.InteractOffset;

            float fromAngle = Mathf.Atan2(_spriteRenderer.transform.localPosition.x, -_spriteRenderer.transform.localPosition.y) - Mathf.PI / 2f;
            float toAngle   = Mathf.Atan2(_actor.InteractOffset.x, -_actor.InteractOffset.y) - Mathf.PI / 2f;

            if (toAngle - fromAngle > Mathf.PI)
            {
                toAngle -= Mathf.PI * 2f;
            }
            if (fromAngle - toAngle > Mathf.PI)
            {
                fromAngle -= Mathf.PI * 2f;
            }

            _reticleMoveAnimation?.Stop();
            _reticleMoveAnimation = new TofuAnimation()
                                    .Value01(_moveAnimTime, EEaseType.Linear, (float newValue) =>
            {
                float angle = Mathf.LerpUnclamped(fromAngle, toAngle, newValue);
                _spriteRenderer.transform.localPosition = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0f);
            })
                                    .Then()
                                    .Execute(() =>
            {
                _reticleMoveAnimation = null;
            })
                                    .Play();
        }
예제 #6
0
        // --------------------------------------------------------------------------------------------
        private void UpdateReticleAlpha()
        {
            float alpha = _defaultColor.a;

            if (_actor.Input.space)
            {
                alpha = 1f;
            }

            if (!alpha.IsApproximately(_targetAlpha))
            {
                _targetAlpha = alpha;
                float startAlpha = _spriteRenderer.color.a;

                _reticleAlphaAnimation?.Stop();
                _reticleAlphaAnimation = new TofuAnimation()
                                         .Value01(_alphaAnimTime, EEaseType.Linear, (float newValue) =>
                {
                    _currentColor.a = Mathf.LerpUnclamped(startAlpha, _targetAlpha, newValue);
                })
                                         .Then()
                                         .Execute(() =>
                {
                    _reticleAlphaAnimation = null;
                })
                                         .Play();
            }
        }
예제 #7
0
        //private void AnimateCardToSide()
        //{
        //    _cardOffsetAnimation?.Stop();
        //    _cardOffsetAnimation = null;
        //
        //    Vector2 startOffset = _draggingCardAnchorPosOffset;
        //    Vector2 endOffset = CardOverPlayableTileOffset;
        //
        //    _cardOffsetAnimation = new TofuAnimation()
        //        .Value01(CardOverPlayableTileAnimTime, EEaseType.EaseOutExpo, (float newValue) =>
        //        {
        //            _draggingCardAnchorPosOffset = Vector2.LerpUnclamped(startOffset, endOffset, newValue);
        //        })
        //        .Then()
        //        .Execute(() =>
        //        {
        //            _cardOffsetAnimation = null;
        //        })
        //        .Play();
        //}
        //
        //// --------------------------------------------------------------------------------------------
        //private void CenterCardOnPointer()
        //{
        //    _cardOffsetAnimation?.Stop();
        //    _cardOffsetAnimation = null;
        //
        //    Vector2 startOffset = _draggingCardAnchorPosOffset;
        //
        //    _cardOffsetAnimation = new TofuAnimation()
        //        .Value01(CardOverPlayableTileAnimTime, EEaseType.EaseOutExpo, (float newValue) =>
        //        {
        //            _draggingCardAnchorPosOffset = Vector2.LerpUnclamped(startOffset, Vector2.zero, newValue);
        //        })
        //        .Then()
        //        .Execute(() =>
        //        {
        //            _cardOffsetAnimation = null;
        //        })
        //        .Play();
        //}

        // --------------------------------------------------------------------------------------------
        private void UICard_OnPointerUp(UICard uiCard, PointerEventData pointerEventData)
        {
            if (uiCard != _draggingCard)
            {
                return;
            }

            _listener.OnPlayerReleasedCard(_uiCardToCard[uiCard], pointerEventData);

            _cardCorrectRotAnim?.Stop();
            _cardCorrectRotAnim = null;

            _cardOffsetAnimation?.Stop();
            _cardOffsetAnimation = null;

            _draggingCard = null;
            _draggingCardAnchorPosOffset = Vector2.zero;

            PositionCards(true);
        }
예제 #8
0
        // --------------------------------------------------------------------------------------------
        private void SetMoveMode(EMoveMode moveMode)
        {
            if (moveMode == MoveMode)
            {
                return;
            }

            EMoveMode previousMode = MoveMode;

            MoveMode = moveMode;

            _playerHasTakenTacticalTurn = false;
            _tacticalTurnCooldownAnimation?.Stop();
            _tacticalTurnCooldownAnimation = null;

            _moveModeChanged?.Invoke(new MoveModeChangedInfo
            {
                previousMode = previousMode,
                currentMode  = MoveMode,
            });
        }
예제 #9
0
        // --------------------------------------------------------------------------------------------
        private void PositionCards(bool animate)
        {
            _cardFanAnim?.Stop();

            float[]   cardAngles  = GetCardFanAngles();
            Vector3[] cardOffsets = GetCardFanOffsets();

            _cardLayout.UpdateChildren();

            int index = 0;

            foreach (Card card in _cardToUICard.Keys)
            {
                UICard uiCard = _cardToUICard[card];

                Quaternion startRotation = uiCard.LocalRotation;
                Quaternion endRotation   = Quaternion.Euler(uiCard.LocalRotation.x, uiCard.LocalRotation.y, uiCard.LocalRotation.z - cardAngles[index]);

                Vector3 startPosition = uiCard.LocalPosition;
                Vector3 endPosition   = cardOffsets[index];

                index++;

                if (animate)
                {
                    _cardFanAnim = new TofuAnimation()
                                   .Value01(CardFanAnimTime, EEaseType.EaseOutExpo, (float newValue) =>
                    {
                        uiCard.LocalRotation = Quaternion.Slerp(startRotation, endRotation, newValue);
                        uiCard.LocalPosition = Vector3.LerpUnclamped(startPosition, endPosition, newValue);
                    })
                                   .Play();
                }
                else
                {
                    uiCard.LocalRotation = endRotation;
                    uiCard.LocalPosition = endPosition;
                }
            }
        }
예제 #10
0
        // --------------------------------------------------------------------------------------------
        private void UpdateReticleColor()
        {
            Color changeTo = _defaultColor;

            Destructible facingDestructible = null;

            Collider2D[] facingColliders = Physics2D.OverlapCircleAll(_actor.transform.position + _actor.InteractOffset, 0.4f);
            foreach (Collider2D collider in facingColliders)
            {
                if (!facingDestructible && collider.gameObject != _actor.gameObject)
                {
                    facingDestructible = collider.gameObject.GetComponent <Destructible>();
                }
            }

            if (facingDestructible && _actor.EquipedWeapon && _actor.EquipedWeapon.CanAttackDestructible(facingDestructible))
            {
                changeTo = _attackColor;
            }

            if (!((Vector4)changeTo).IsApproximately(_targetColor))
            {
                Color startColor = _spriteRenderer.color;
                _targetColor = changeTo;

                _reticleColorAnimation?.Stop();
                _reticleColorAnimation = new TofuAnimation()
                                         .Value01(_colorAnimTime, EEaseType.EaseOutExpo, (float newValue) =>
                {
                    _currentColor = Color.LerpUnclamped(startColor, _targetColor, newValue);
                })
                                         .Then()
                                         .Execute(() =>
                {
                    _reticleColorAnimation = null;
                })
                                         .Play();
            }
        }
예제 #11
0
파일: HUDMoveMode.cs 프로젝트: njelly/Deeep
        private void SetMoveModeText(PlayerActor.EMoveMode moveMode, bool flashCamera)
        {
            switch (moveMode)
            {
            case PlayerActor.EMoveMode.FreeMove:
                _moveModeLabel.text = "Free Move";
                break;

            case PlayerActor.EMoveMode.Tactical:
                _moveModeLabel.text = "Tactical";
                break;

            case PlayerActor.EMoveMode.Paused:
                _moveModeLabel.text = "Paused";
                break;
            }

            if (flashCamera)
            {
                _cameraBGColorAnim?.Stop();
                _cameraBGColorAnim = new TofuAnimation()
                                     .Value01(_cameraFlashTime / 2f, EEaseType.EaseOutExpo, (float newValue) =>
                {
                    Camera.main.backgroundColor = Color.LerpUnclamped(Color.black, _cameraFlashColor, newValue);
                })
                                     .Then()
                                     .Value01(_cameraFlashTime / 2f, EEaseType.EaseOutExpo, (float newValue) =>
                {
                    Camera.main.backgroundColor = Color.LerpUnclamped(_cameraFlashColor, Color.black, newValue);
                })
                                     .Then()
                                     .Execute(() =>
                {
                    _cameraBGColorAnim = null;
                })
                                     .Play();
            }
        }
예제 #12
0
        // --------------------------------------------------------------------------------------------
        private void OnDamaged(Destructible.DamageEventInfo info)
        {
            if (!_visible)
            {
                SetVisible(true);
            }

            float startAmount = _slider.value;
            float endAmount   = info.currentHealth / Destructible.MaxHealth;

            _sliderAnimation?.Stop();
            _sliderAnimation = new TofuAnimation()
                               .Value01(_sliderAnimTime, EEaseType.Linear, (float newValue) =>
            {
                _slider.value = Mathf.LerpUnclamped(startAmount, endAmount, newValue);
            })
                               .WaitUntil(() =>
            {
                return(_fadeAnimation == null);
            })
                               .Then()
                               .Execute(() =>
            {
                if (PlayerActor.MoveMode == PlayerActor.EMoveMode.FreeMove)
                {
                    if (this)    // check if we've been destroyed first
                    {
                        SetVisible(false);
                    }
                }
            })
                               .Then()
                               .Execute(() =>
            {
                _sliderAnimation = null;
            })
                               .Play();
        }
예제 #13
0
파일: Weapon.cs 프로젝트: njelly/Deeep
 // --------------------------------------------------------------------------------------------
 public void InterruptAttack()
 {
     _attackSequence?.Stop();
 }
예제 #14
0
        public override void Hide()
        {
            base.Hide();

            _anim?.Stop();
        }