Beispiel #1
0
        private IKCommand GetLastActiveCommand()
        {
            if (ikCommands.Count == 0)
            {
                return(null);
            }

            IKCommand lastCommand = ikCommands[ikCommands.Count - 1];

            if (lastCommand.IsActive)
            {
                return(lastCommand);
            }
            return(null);
        }
Beispiel #2
0
        /** Serializes the current state into a single string */
        public string CreateSaveData()
        {
            if (!isControlling)
            {
                return(string.Empty);
            }

            IKCommand commandToSave = GetLastActiveCommand();

            if (commandToSave != null)
            {
                return(commandToSave.GetSaveData());
            }

            return(string.Empty);
        }
Beispiel #3
0
        /** Restores a state from a serialized string */
        public void LoadData(string data)
        {
            Clear(true);

            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            IKCommand newCommand = IKCommand.LoadData(data);

            if (newCommand != null)
            {
                ikCommands.Add(newCommand);
                isControlling = true;
            }
        }
Beispiel #4
0
        /**
         * <summary>Applies the command's effect on an Animator</summary>
         * <param name = "animator">The Animator to control</param>
         * <param name = "avatarIKGoal">The AvatarIKGoal to control</param>
         * <param name = "otherCommand">If set, the combined effects will be weight-blended together</param>
         */
        public void OnAnimatorIK(Animator animator, AvatarIKGoal avatarIKGoal, IKCommand otherCommand = null)
        {
            if (otherCommand != null)
            {
                float      totalWeight     = otherCommand.actualWeight + actualWeight;
                Vector3    averagePosition = Vector3.Lerp(otherCommand.Position, Position, ProportionAlong);
                Quaternion averageRotation = Quaternion.Lerp(otherCommand.Rotation, Rotation, ProportionAlong);

                animator.SetIKPositionWeight(avatarIKGoal, totalWeight);
                animator.SetIKRotationWeight(avatarIKGoal, totalWeight);
                animator.SetIKPosition(avatarIKGoal, averagePosition);
                animator.SetIKRotation(avatarIKGoal, averageRotation);
            }
            else
            {
                animator.SetIKPositionWeight(avatarIKGoal, actualWeight);
                animator.SetIKRotationWeight(avatarIKGoal, actualWeight);
                animator.SetIKPosition(avatarIKGoal, targetTransform.position);
                animator.SetIKRotation(avatarIKGoal, targetTransform.rotation);
            }
        }