protected virtual void Start()
        {
            if (TargetGroundFitter == null)
            {
                TargetGroundFitter = GetComponent <FGroundFitter_Base>();
            }

            if (TargetGroundFitter)
            {
                TargetGroundFitter.GlueToGround = false;
            }

            agent = GetComponent <NavMeshAgent>();

            agent.Warp(transform.position);
            agent.SetDestination(transform.position);
            moving             = false;
            lastAgentPosition  = transform.position;
            reachedDestination = true;

            animationClips = new FAnimationClips(GetComponentInChildren <Animator>());
            animationClips.AddClip("Idle");

            if (FAnimatorMethods.StateExists(animationClips.Animator, "Move") || FAnimatorMethods.StateExists(animationClips.Animator, "move"))
            {
                movementClip = "Move";
            }
            else
            {
                movementClip = "Walk";
            }

            animationClips.AddClip(movementClip);
        }
        /// <summary>
        /// Handling switching animation clips of Animator
        /// </summary>
        protected virtual void HandleAnimations()
        {
            if (ActiveSpeed > 0.15f)
            {
                if (Sprint)
                {
                    CrossfadeTo("Run", 0.25f);
                }
                else
                {
                    CrossfadeTo("Walk", 0.25f);
                }
            }
            else
            {
                CrossfadeTo("Idle", 0.25f);
            }

            // If object is in air we just slowing animation speed to zero
            if (animatorHaveAnimationSpeedProp)
            {
                if (inAir)
                {
                    FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", 0f);
                }
                else
                {
                    FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", MultiplySprintAnimation ? (ActiveSpeed / BaseSpeed) : Mathf.Min(1f, (ActiveSpeed / BaseSpeed)));
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Checking if inside animator clipName state exist and with 'exactClipName' false it will check all variants of clipName, uppercase / lowercase etc.
        /// </summary>
        public void AddClip(Animator animator, string clipName, bool exactClipName = false)
        {
            if (!animator)
            {
                Debug.LogError("No animator!");
                return;
            }

            string existing = "";

            if (!exactClipName) // Checking if animation state exists with different variants for clipName word
            {
                if (FAnimatorMethods.StateExists(animator, clipName))
                {
                    existing = clipName;
                }
                else
                if (FAnimatorMethods.StateExists(animator, FStringMethods.CapitalizeFirstLetter(clipName)))
                {
                    existing = FStringMethods.CapitalizeFirstLetter(clipName);
                }
                else
                if (FAnimatorMethods.StateExists(animator, clipName.ToLower()))
                {
                    existing = clipName.ToLower();
                }
                else
                if (FAnimatorMethods.StateExists(animator, clipName.ToUpper()))
                {
                    existing = clipName.ToUpper();
                }
            }
            else // Checking if state with provided exact name exists inside animator
            {
                if (FAnimatorMethods.StateExists(animator, clipName))
                {
                    existing = clipName;
                }
            }

            if (existing == "")
            {
                Debug.LogWarning("Clip with name " + clipName + " not exists in animator from game object " + animator.gameObject.name);
            }
            else // Adding clip hash to dictionary if it exists inside animator
            {
                if (!ContainsKey(clipName))
                {
                    Add(clipName, Animator.StringToHash(existing));
                }
            }
        }
        protected override void HandleAnimations()
        {
            if (Input.GetKey(KeyCode.A))
            {
                CrossfadeTo("RotateL", 0.25f);
                MoveVector = Vector3.zero;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                CrossfadeTo("RotateR", 0.25f);
                MoveVector = Vector3.zero;
            }
            else
            {
                if (ActiveSpeed > 0.15f)
                {
                    if (Sprint)
                    {
                        CrossfadeTo("Run", 0.25f);
                    }
                    else
                    {
                        CrossfadeTo("Walk", 0.25f);
                    }
                }
                else
                {
                    CrossfadeTo("Idle", 0.25f);
                }
            }

            // If object is in air we just slowing animation speed to zero
            if (animatorHaveAnimationSpeedProp)
            {
                if (inAir)
                {
                    FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", 0f);
                }
                else
                {
                    FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", MultiplySprintAnimation ? (ActiveSpeed / BaseSpeed) : Mathf.Min(1f, (ActiveSpeed / BaseSpeed)));
                }
            }
        }
 /// <summary>
 /// Smooth changing parameter value in animator
 /// </summary>
 private void LerpValue(string parameter, float value)
 {
     FAnimatorMethods.LerpFloatValue(animator, parameter, value, 5f);
 }