-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StutterDetector.cs
76 lines (67 loc) · 1.96 KB
/
StutterDetector.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
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using UnityEngine.UI;
using UdonVR.Takato.VideoPlayer;
namespace UdonVR
{
public class StutterDetector : UdonSharpBehaviour
{
public UdonSyncVideoPlayer VideoPlayer;
public float Target = 2f;
public GameObject TargetObj;
public InputField Inputfeild;
public GameObject ParentDebug;
private bool isDebug = false;
private Text[] DebugChildren;
private int ChildCount = 0;
private int CurrentChild = 0;
private float OldTime = 10f;
private float CurTime = 0;
void Start()
{
if (ParentDebug != null)
{
DebugChildren = ParentDebug.transform.GetComponentsInChildren<Text>();
ChildCount = DebugChildren.Length - 1;
reset();
isDebug = true;
}
}
private void Update()
{
if (VideoPlayer.autoResync)
{
CurTime = Time.deltaTime;
if (CurTime > OldTime * Target)
{
VideoPlayer.ForceSyncVideo();
}
if (isDebug) DebugOut();
OldTime = Time.deltaTime;
}
}
public void reset()
{
if (TargetObj != null)
TargetObj.SetActive(false);
}
public void SetTarget()
{
Target = float.Parse(Inputfeild.text);
}
private void DebugOut()
{
if (CurTime > OldTime * Target)
{
if (TargetObj != null)
TargetObj.SetActive(true);
}
DebugChildren[CurrentChild].text = CurTime.ToString();
CurrentChild++;
if (CurrentChild > ChildCount) CurrentChild = 0;
}
}
}