53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using KinematicCharacterController;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.Playables;
|
|
|
|
namespace KinematicCharacterController.Examples
|
|
{
|
|
public class PlayableMover : MonoBehaviour, IMoverController
|
|
{
|
|
public PhysicsMover Mover;
|
|
|
|
public float Speed = 1f;
|
|
public PlayableDirector Director;
|
|
|
|
private Transform _transform;
|
|
|
|
private void Start()
|
|
{
|
|
_transform = this.transform;
|
|
Director.timeUpdateMode = DirectorUpdateMode.Manual;
|
|
|
|
Mover.MoverController = this;
|
|
}
|
|
|
|
// This is called every FixedUpdate by our PhysicsMover in order to tell it what pose it should go to
|
|
public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime)
|
|
{
|
|
// Remember pose before animation
|
|
Vector3 _positionBeforeAnim = _transform.position;
|
|
Quaternion _rotationBeforeAnim = _transform.rotation;
|
|
|
|
// Update animation
|
|
EvaluateAtTime(Time.time * Speed);
|
|
|
|
// Set our platform's goal pose to the animation's
|
|
goalPosition = _transform.position;
|
|
goalRotation = _transform.rotation;
|
|
|
|
// Reset the actual transform pose to where it was before evaluating.
|
|
// This is so that the real movement can be handled by the physics mover; not the animation
|
|
_transform.position = _positionBeforeAnim;
|
|
_transform.rotation = _rotationBeforeAnim;
|
|
}
|
|
|
|
public void EvaluateAtTime(double time)
|
|
{
|
|
Director.time = time % Director.duration;
|
|
Director.Evaluate();
|
|
}
|
|
}
|
|
} |