-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransformTracker.cs
84 lines (75 loc) · 2.64 KB
/
TransformTracker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using GameManagement;
using ModIO.UI;
using ReplayEditor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityModManagerNet;
namespace BetterReplay
{
/*
class TransformTrackerStruct
{
public List<float> time = new List<float>();
public List<Vector3> position = new List<Vector3>();
public List<Quaternion> rotation = new List<Quaternion>();
public void pushState(float time, Vector3 position, Quaternion rotation)
{
this.time.Add(time);
this.position.Add(position);
this.rotation.Add(rotation);
}
public void Shift()
{
this.time.RemoveAt(0);
this.position.RemoveAt(0);
this.rotation.RemoveAt(0);
}
}
class TransformTracker : MonoBehaviour
{
public TransformTrackerStruct tracker;
public int BufferFrameCount;
public Transform replay_object, tracked_object;
public void Start()
{
tracker = new TransformTrackerStruct();
BufferFrameCount = Mathf.RoundToInt(ReplaySettings.Instance.FPS * ReplaySettings.Instance.MaxRecordedTime);
}
public void Update()
{
if (GameStateMachine.Instance.CurrentState.GetType() == typeof(ReplayState))
{
int index = getFrame();
if (index >= 0 && tracker.rotation[index] != null && tracker.position[index] != null)
{
if (replay_object)
{
replay_object.rotation = Quaternion.Slerp(replay_object.rotation, tracker.rotation[index], Time.smoothDeltaTime * 16f);
//replay_object.position = tracker.position[index];
}
}
}
if (GameStateMachine.Instance.CurrentState.GetType() == typeof(PlayState))
{
tracker.pushState(PlayTime.time, tracked_object.position, tracked_object.rotation * ((tracked_object.gameObject.name == "Wheel2" || tracked_object.gameObject.name == "Wheel4") ? Quaternion.Euler(0, 180, 0) : Quaternion.identity));
if (tracker.time.Count >= BufferFrameCount)
{
tracker.Shift();
}
}
}
public int getFrame()
{
for (int i = 0; i < tracker.time.Count; i++)
{
if (tracker.time[i] >= ReplayEditorController.Instance.playbackController.CurrentTime) return i;
}
return -1;
}
}
*/
}