Added player replaying
This commit is contained in:
6615
Assets/Resources/playerframe.json
Normal file
6615
Assets/Resources/playerframe.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: df8306483d8e4d94e8c0548fd23da7fd
|
guid: 9fdaf51f33b85cc4eb9e54f6b3c12f6c
|
||||||
folderAsset: yes
|
TextScriptImporter:
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
@@ -1,7 +1,19 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace InterfaceOff.WorldScene
|
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
|
public class DevPlayerController : MonoBehaviour
|
||||||
{
|
{
|
||||||
private CharacterController Controller;
|
private CharacterController Controller;
|
||||||
@@ -10,6 +22,9 @@ namespace InterfaceOff.WorldScene
|
|||||||
public Transform CameraPivot;
|
public Transform CameraPivot;
|
||||||
|
|
||||||
private float MousePitch;
|
private float MousePitch;
|
||||||
|
private float MouseYaw = 90;
|
||||||
|
|
||||||
|
private List<PlayerFrameInfo> FrameInfo = new();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -19,13 +34,38 @@ namespace InterfaceOff.WorldScene
|
|||||||
Cursor.visible = false;
|
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()
|
private void Update()
|
||||||
{
|
{
|
||||||
/* Player movement */
|
/* Player movement */
|
||||||
float mouseX = Input.GetAxisRaw("Mouse X") * CamSens * 100f * Time.deltaTime;
|
float mouseX = Input.GetAxisRaw("Mouse X") * CamSens * 100f * Time.deltaTime;
|
||||||
float mouseY = Input.GetAxisRaw("Mouse Y") * 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 -= mouseY;
|
||||||
MousePitch = Mathf.Clamp(MousePitch, -85f, 85f);
|
MousePitch = Mathf.Clamp(MousePitch, -85f, 85f);
|
||||||
|
|||||||
39
Assets/Scripts/PlayerController.cs
Normal file
39
Assets/Scripts/PlayerController.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
Shader "Unlit/ScreenCutoutShader"
|
|
||||||
{
|
|
||||||
Properties
|
|
||||||
{
|
|
||||||
_MainTex ("Texture", 2D) = "white" {}
|
|
||||||
}
|
|
||||||
SubShader
|
|
||||||
{
|
|
||||||
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
|
|
||||||
Lighting Off
|
|
||||||
Cull Back
|
|
||||||
ZWrite On
|
|
||||||
ZTest Less
|
|
||||||
|
|
||||||
Fog{ Mode Off }
|
|
||||||
|
|
||||||
Pass
|
|
||||||
{
|
|
||||||
CGPROGRAM
|
|
||||||
#pragma vertex vert
|
|
||||||
#pragma fragment frag
|
|
||||||
|
|
||||||
#include "UnityCG.cginc"
|
|
||||||
|
|
||||||
struct appdata
|
|
||||||
{
|
|
||||||
float4 vertex : POSITION;
|
|
||||||
float2 uv : TEXCOORD0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct v2f
|
|
||||||
{
|
|
||||||
//float2 uv : TEXCOORD0;
|
|
||||||
float4 vertex : SV_POSITION;
|
|
||||||
float4 screenPos : TEXCOORD1;
|
|
||||||
};
|
|
||||||
|
|
||||||
v2f vert (appdata v)
|
|
||||||
{
|
|
||||||
v2f o;
|
|
||||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
||||||
o.screenPos = ComputeScreenPos(o.vertex);
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
sampler2D _MainTex;
|
|
||||||
|
|
||||||
fixed4 frag (v2f i) : SV_Target
|
|
||||||
{
|
|
||||||
i.screenPos /= i.screenPos.w;
|
|
||||||
fixed4 col = tex2D(_MainTex, float2(i.screenPos.x, i.screenPos.y));
|
|
||||||
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
ENDCG
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 0a42b0980bf770241920f919faeb44e3
|
|
||||||
ShaderImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
defaultTextures: []
|
|
||||||
nonModifiableTextures: []
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 57d3d2a9ac7b9104d91c175bc98946c7
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace InterfaceOff.WorldScene
|
|
||||||
{
|
|
||||||
public class PlayerController : MonoBehaviour
|
|
||||||
{
|
|
||||||
private static PlayerController Instance;
|
|
||||||
|
|
||||||
[field: SerializeField] private float PlayerSpeed { get; set; }
|
|
||||||
[field: SerializeField] private Transform[] LerpPositions;
|
|
||||||
private float LerpValue;
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
int section = Mathf.FloorToInt(LerpValue);
|
|
||||||
Vector3 a = LerpPositions[section + 0].position;
|
|
||||||
Vector3 b = LerpPositions[section + 1].position;
|
|
||||||
|
|
||||||
LerpValue += PlayerSpeed / Vector3.Distance(a, b) * Time.deltaTime;
|
|
||||||
LerpValue %= LerpPositions.Length - 1; // Makes lerp value wrap around
|
|
||||||
|
|
||||||
float sectionLerp = Math.Clamp(LerpValue, section, section + 1) - section;
|
|
||||||
transform.position = Vector3.Lerp(a, b, sectionLerp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user