Beispiel #1
0
        private void SetupTest()
        {
            player = TestingTools.ConstructPlayer();

            player.transform.position    = Vector3.zero;
            player.transform.eulerAngles = Vector3.one * 10;
            player.transform.localScale  = Vector3.zero;
            player.SetFacing(Facing.Left);
            player.gameObject.SetActive(true);

            snapshot = new PlayerSnapshot(player);
            player.transform.position    = Vector3.one;
            player.transform.eulerAngles = Vector3.one;
            player.transform.localScale  = Vector3.one;
            player.SetFacing(Facing.Left);
            player.gameObject.SetActive(true);

            absA          = new AbsolutePoseInfo();
            absA.Position = new Vector3(-10, -10, -10);
            absA.Rotation = Vector3.zero;
            absA.Scale    = new Vector3(-10, -10, -10);
            absA.State    = typeof(SingleJumpFall);
            absA.Flipped  = true;
            absA.Active   = true;

            absB          = new AbsolutePoseInfo();
            absB.Position = new Vector3(10, 10, 10);
            absB.Rotation = new Vector3(20, 20, 20);
            absB.Scale    = new Vector3(10, 10, 10);
            absB.State    = typeof(Running);
            absB.Flipped  = false;
            absB.Active   = false;

            relA          = new RelativePoseInfo();
            relA.Position = new Vector3(-10, -10, -10);
            relA.Rotation = Vector3.zero;
            relA.Scale    = new Vector3(-10, -10, -10);
            relA.State    = typeof(SingleJumpFall);
            relA.Flipped  = true;
            relA.Active   = true;

            relB          = new RelativePoseInfo();
            relB.Position = new Vector3(10, 10, 10);
            relB.Rotation = new Vector3(20, 20, 20);
            relB.Scale    = new Vector3(10, 10, 10);
            relB.State    = typeof(Running);
            relB.Flipped  = false;
            relB.Active   = false;
        }
        /// <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);
        }
Beispiel #3
0
 /// <summary>
 /// Apply the pose of a relative clip.
 /// </summary>
 /// <param name="player">The player character</param>
 /// <param name="snapshot">A snapshot of player character information. This
 /// gets mixed into the player's pose as well.</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>
 public static void MixRelative(PlayerCharacter player, PlayerSnapshot snapshot, RelativePoseInfo pose, float weight = 1f)
 {
     player.transform.position    += pose.Position * weight;
     player.transform.eulerAngles += pose.Rotation * weight;
     player.transform.localScale   = (pose.Scale - snapshot.Scale) * weight + snapshot.Scale;
 }
 /// <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);
 }