/// <summary> /// Mix together a relative and absolute pose. For inputs, which pose is which doesn't matter. /// </summary> /// <param name="player">The player character</param> /// <param name="poseA">The first pose</param> /// <param name="weightA">Interpolation weight for the first pose</param> /// <param name="poseB">The second pose</param> /// <param name="weightB">Interpolation weight for the second pose</param> private void MixAbsoluteRelative(PlayerCharacter player, PoseInfo poseA, float weightA, PoseInfo poseB, float weightB) { AbsolutePoseInfo absPose; RelativePoseInfo relPose; float absWeight; float relWeight; if (PoseTools.IsAbsolute(poseA)) { absPose = (AbsolutePoseInfo)poseA; relPose = (RelativePoseInfo)poseB; absWeight = weightA; relWeight = weightB; } else { absPose = (AbsolutePoseInfo)poseB; relPose = (RelativePoseInfo)poseA; absWeight = weightB; relWeight = weightA; } MixAbsolute(player, absPose, absWeight); VirtualSnapshot.RestoreTransform(player); MixRelative(player, relPose, relWeight); }
/// <summary> /// Apply the pose of an absolute clip. /// </summary> /// <param name="player">The player character</param> /// <param name="pose">The pose to apply</param> /// <param name="weight">(optional) The weighting on the pose, used to /// interpolate this pose with another if necessary. Default: 1.</param> /// <param name="updateVirtualSnapshot">(optional) Whether or not to update the mixer's virtual snapshot /// of the player character. When mixing multiple absolute poses, this /// action can be saved for the last pose applied. Default: true.</param> private void MixAbsolute(PlayerCharacter player, AbsolutePoseInfo pose, float weight = 1f, bool updateVirtualSnapshot = true) { PoseTools.MixAbsolute(player, VirtualSnapshot, pose, weight); if (updateVirtualSnapshot) { VirtualSnapshot = new PlayerSnapshot(player); } }
//------------------------------------------------------------------------- // Clip Mixing //------------------------------------------------------------------------- /// <summary> /// Mix a single clip. /// </summary> /// <param name="playable">The track's playable</param> /// <param name="player">The player character</param> /// <param name="clipIndex">The index of the clip to mix</param> private void MixSingle(Playable playable, PlayerCharacter player, int clipIndex) { PoseInfo pose = TimelineTools.GetClipInfo <PoseInfo>(playable, clipIndex); player.gameObject.SetActive(pose.Active); if (PoseTools.IsAbsolute(pose)) // Absolute { MixAbsolute(player, (AbsolutePoseInfo)pose); } else // Relative { VirtualSnapshot.RestoreTransform(player); MixRelative(player, (RelativePoseInfo)pose); } StateDriver driver = GetDriver(pose); UpdateFacing(player, pose); UpdateState(player, driver, playable, pose); }
/// <summary> /// Mix together two active clips based on what type of clips they are. /// </summary> /// <param name="playable">The track's playable</param> /// <param name="player">The player character</param> /// <param name="clipIndexA">The index of the first clip to mix</param> /// <param name="clipIndexB">The index of the second clip to mix</param> private void MixMultiple(Playable playable, PlayerCharacter player, int clipIndexA, int clipIndexB) { PoseInfo poseA = TimelineTools.GetClipInfo <PoseInfo>(playable, clipIndexA); float weightA = playable.GetInputWeight(clipIndexA); PoseInfo poseB = TimelineTools.GetClipInfo <PoseInfo>(playable, clipIndexB); float weightB = playable.GetInputWeight(clipIndexB); // Mix together clips based on their typing. if (PoseTools.IsAbsolute(poseA) && PoseTools.IsAbsolute(poseB)) { MixAbsolute(player, (AbsolutePoseInfo)poseA, weightA); MixAbsolute(player, (AbsolutePoseInfo)poseB, weightB); } else if (PoseTools.IsRelative(poseA) && PoseTools.IsRelative(poseB)) { VirtualSnapshot.RestoreTransform(player); RelativePoseInfo mixed = new RelativePoseInfo(); mixed.Position = poseA.Position * weightA + poseB.Position * weightB; mixed.Rotation = poseA.Rotation * weightA + poseB.Rotation * weightB; mixed.Scale = poseA.Scale * weightA + poseB.Scale * weightB; MixRelative(player, mixed); } else { MixAbsoluteRelative(player, poseA, weightA, poseB, weightB); } // Apply player facing and FSM state based on which pose is weighted heavier. PoseInfo dominantPose = weightA > weightB ? poseA : poseB; player.gameObject.SetActive(dominantPose.Active); StateDriver driver = GetDriver(dominantPose); UpdateFacing(player, dominantPose); UpdateState(player, driver, playable, dominantPose); }
/// <summary> /// Apply the pose of a relative clip. /// </summary> /// <param name="player">The player character</param> /// <param name="pose">The pose to apply</param> /// <param name="weight">(optional) The weighting on the pose, used to /// interpolate this pose with another if necessary. Default: 1.</param> private void MixRelative(PlayerCharacter player, RelativePoseInfo pose, float weight = 1f) { PoseTools.MixRelative(player, VirtualSnapshot, pose, weight); }