Added player replaying
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace InterfaceOff.WorldScene
|
||||
{
|
||||
[System.Serializable] public struct PlayerFrameInfo
|
||||
{
|
||||
public Vector3 Position;
|
||||
public Vector2 Rotation;
|
||||
}
|
||||
|
||||
[System.Serializable] public struct PlayerFrameInfoArray
|
||||
{
|
||||
public PlayerFrameInfo[] FrameInfo;
|
||||
}
|
||||
|
||||
public class DevPlayerController : MonoBehaviour
|
||||
{
|
||||
private CharacterController Controller;
|
||||
@@ -10,6 +22,9 @@ namespace InterfaceOff.WorldScene
|
||||
public Transform CameraPivot;
|
||||
|
||||
private float MousePitch;
|
||||
private float MouseYaw = 90;
|
||||
|
||||
private List<PlayerFrameInfo> FrameInfo = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -19,13 +34,38 @@ namespace InterfaceOff.WorldScene
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
PlayerFrameInfoArray arr = new()
|
||||
{
|
||||
FrameInfo = FrameInfo.ToArray()
|
||||
};
|
||||
|
||||
string json = JsonUtility.ToJson(arr, prettyPrint: true);
|
||||
System.IO.File.WriteAllText(Application.persistentDataPath + "/playerframe.json", json);
|
||||
|
||||
Debug.Log("Dumped");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
PlayerFrameInfo current = new()
|
||||
{
|
||||
Position = transform.position,
|
||||
Rotation = new Vector2(MousePitch, MouseYaw)
|
||||
};
|
||||
|
||||
FrameInfo.Add(current);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
/* Player movement */
|
||||
float mouseX = Input.GetAxisRaw("Mouse X") * CamSens * 100f * Time.deltaTime;
|
||||
float mouseY = Input.GetAxisRaw("Mouse Y") * CamSens * 100f * Time.deltaTime;
|
||||
|
||||
transform.Rotate(Vector3.up * mouseX);
|
||||
MouseYaw += mouseX;
|
||||
transform.rotation = Quaternion.Euler(0f, MouseYaw, 0f);
|
||||
|
||||
MousePitch -= mouseY;
|
||||
MousePitch = Mathf.Clamp(MousePitch, -85f, 85f);
|
||||
|
||||
Reference in New Issue
Block a user