Пример #1
0
        /// <summary>
        /// Idle Animation when the item is selected
        /// </summary>
        protected virtual void AnimateIdle()
        {
            if (IndexSelected == -1)
            {
                return;                                         //Skip if the Selection is clear
            }
            if (!MoveIdle && !RotateIdle && !ScaleIdle)
            {
                return;                                         //Skip if there's no Idle Animation
            }
            if (CurrentItem == null)
            {
                return;
            }

            if (!IsChangingItem && !isAnimating && !IsSwapping) //
            {
                IdleTimeMove += Time.deltaTime;
                IsSelectTransformAnimation = true;
                if (MoveIdle && MoveIdleAnim)
                {
                    IdleTimeMove = IdleTimeMove % MoveIdleAnim.time;
                    CurrentItem.transform.localPosition =
                        Vector3.LerpUnclamped(LastTCurrentItem.LocalPosition,
                                              LastTCurrentItem.LocalPosition + transform.InverseTransformDirection(CurrentItem.transform.TransformDirection(MoveIdleAnim.Position)),
                                              MoveIdleAnim.PosCurve.Evaluate(IdleTimeMove / MoveIdleAnim.time));
                }

                if (RotateIdle)
                {
                    Renderer mesh = CurrentItem.GetComponentInChildren <Renderer>();

                    CurrentItem.transform.RotateAround
                        (mesh ? mesh.bounds.center : CurrentItem.transform.position, transform.TransformDirection(TurnTableVector), ItemRotationSpeed * Time.deltaTime * 10); //rotate by center
                }

                if (ScaleIdle && ScaleIdleAnim)
                {
                    IdleTimeScale += Time.deltaTime;
                    IdleTimeScale  = IdleTimeScale % ScaleIdleAnim.time;
                    Vector3 FinalScale = Vector3.Scale(LastTCurrentItem.LocalScale, ScaleIdleAnim.Scale);
                    CurrentItem.transform.localScale = Vector3.LerpUnclamped(LastTCurrentItem.LocalScale, FinalScale, ScaleIdleAnim.ScaleCurve.Evaluate(IdleTimeScale / ScaleIdleAnim.time));
                }
            }
        }
        /// <summary>
        /// Plays an animation
        /// </summary>
        /// <param name="anim">the name of the animation to play</param>
        public virtual void _PlayAnimation(string anim)
        {
            if (IndexSelected == -1)
            {
                return;                         //Skip if the Selection is clear
            }
            Animator itemAnimator = CurrentItem.GetComponentInChildren <Animator>();

            if (itemAnimator && !CurrentItem.Locked)
            {
                if (CurrentItem.CustomAnimation != string.Empty)// Check if the object has a custom animator
                {
                    itemAnimator.CrossFade(CurrentItem.CustomAnimation, 0.1f);
                }

                else
                {
                    itemAnimator.CrossFade(anim, 0.1f);
                }
            }
        }