private IKCommand GetLastActiveCommand() { if (ikCommands.Count == 0) { return(null); } IKCommand lastCommand = ikCommands[ikCommands.Count - 1]; if (lastCommand.IsActive) { return(lastCommand); } return(null); }
/** 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); }
/** 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; } }
/** * <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); } }