Added player replaying

This commit is contained in:
2026-01-15 22:40:41 +00:00
parent 8584126ebe
commit 1a75fdd1d4
9 changed files with 6697 additions and 106 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.IO;
using UnityEngine;
namespace InterfaceOff.WorldScene
{
public class PlayerController : MonoBehaviour
{
private static PlayerController Instance;
private PlayerFrameInfo[] Frames;
private int FrameIndex = 0;
private float LerpValue;
private void Awake()
{
string json = File.ReadAllText(Application.dataPath + "/Resources/playerframe.json");
Frames = JsonUtility.FromJson<PlayerFrameInfoArray>(json).FrameInfo;
}
private void FixedUpdate()
{
FrameIndex = (FrameIndex + 1) % (Frames.Length - 1);
}
private void Update()
{
LerpValue = (LerpValue + Time.deltaTime * 20f) % 1f;
PlayerFrameInfo frameA = Frames[FrameIndex + 0];
PlayerFrameInfo frameB = Frames[FrameIndex + 1];
transform.position = Vector3.Lerp(frameA.Position, frameB.Position, LerpValue);
Vector2 rotation = Vector2.Lerp(frameA.Rotation, frameB.Rotation, LerpValue);
transform.rotation = Quaternion.Euler(rotation.x, rotation.y, 0);
}
}
}