2023-08-27 02:58:19 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2023-10-04 16:50:27 +08:00
|
|
|
using BITKit;
|
2023-08-27 02:58:19 +08:00
|
|
|
using Lightbug.Utilities;
|
|
|
|
using UnityEngine;
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace BITFALL.Scenes
|
|
|
|
{
|
|
|
|
[ExecuteAlways]
|
|
|
|
public class AnimatorBasedPlatform : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private float mass;
|
|
|
|
[SerializeField] private Animator animator;
|
|
|
|
[SerializeField] private RigidbodyComponent rigidbodyComponent;
|
2023-10-04 16:50:27 +08:00
|
|
|
private readonly DoubleBuffer<Vector3> currentPosition=new();
|
|
|
|
private readonly DoubleBuffer<Quaternion> currentRotation=new();
|
2023-08-27 02:58:19 +08:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
if(EditorApplication.isPlaying is false)
|
|
|
|
return;
|
|
|
|
#endif
|
2023-10-04 16:50:27 +08:00
|
|
|
rigidbodyComponent = RigidbodyComponent.CreateInstance(gameObject);
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
|
|
{
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
if(EditorApplication.isPlaying is false)
|
|
|
|
return;
|
|
|
|
#endif
|
2023-10-04 16:50:27 +08:00
|
|
|
if(currentPosition.TryGetRelease(out var position))
|
|
|
|
rigidbodyComponent.Position = position;
|
|
|
|
if(currentRotation.TryGetRelease(out var rotation))
|
|
|
|
rigidbodyComponent.Rotation = rotation;
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
private void OnAnimatorMove()
|
|
|
|
{
|
2023-10-04 16:50:27 +08:00
|
|
|
animator.ApplyBuiltinRootMotion();
|
|
|
|
currentPosition.Release(animator.rootPosition);
|
|
|
|
currentRotation.Release(animator.rootRotation);
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|