Skip to content

Commit

Permalink
updated to v1.8.5dev
Browse files Browse the repository at this point in the history
Added support for Unity player
added resync button
added reload button
added auto resync button
added auto resync on stutter (if auto resync is on)
  • Loading branch information
ChildoftheBeast authored Jun 30, 2021
1 parent b62f3f9 commit 4c4349f
Show file tree
Hide file tree
Showing 7 changed files with 579 additions and 73 deletions.
20 changes: 10 additions & 10 deletions LoopToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using VRC.SDKBase;
using VRC.SDK3.Video.Components.Base;

namespace UdonVR.Takato
namespace UdonVR.Takato.VideoPlayer
{
public class LoopToggle : UdonSharpBehaviour
{
public BaseVRCVideoPlayer videoPlayer;
public UdonSyncVideoPlayer videoPlayer;


[UdonSynced] bool _loopSynced;
Expand All @@ -23,14 +23,12 @@ private void ToggleValue(bool value)
loopToggle.isOn = value;
loopToggle.enabled = true;
}
private void Start()

public void Init()
{
if (Networking.IsMaster)
{
_loopSynced = videoPlayer.Loop;
_loop = _loopSynced;
ToggleValue(_loopSynced);
}
_loopSynced = videoPlayer.videoPlayer.Loop;
_loop = _loopSynced;
ToggleValue(_loopSynced);
}

public void ToggleButton() //Call RunProgram on this method
Expand All @@ -48,7 +46,9 @@ public void ToggleButton() //Call RunProgram on this method
private void DoToggle()
{
_loop = _loopSynced;
videoPlayer.Loop = _loopSynced;
videoPlayer.avProVideoPlayer.Loop = _loopSynced;
videoPlayer.unityVideoPlayer.Loop = _loopSynced;
//videoPlayer.Loop = _loopSynced;
if (!Networking.IsMaster)
{
ToggleValue(_loopSynced);
Expand Down
16 changes: 13 additions & 3 deletions MasterOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine.UI;
using VRC.SDK3.Components;
using VRC.SDKBase;
using UdonVR.Takato.VideoPlayer;

namespace UdonVR.Takato
{
Expand All @@ -15,9 +16,9 @@ public class MasterOnly : UdonSharpBehaviour
public Button pauseButton;
public Button stopButton;
public Slider timeBar;
[UdonSynced] public bool syncedMasterOnly;
[UdonSynced] public bool syncedMasterOnly = true;
private bool _masterOnly;

private bool _isCurrentMaster;

private void Start()
{
Expand All @@ -26,6 +27,8 @@ private void Start()
masterToggle.isOn = syncedMasterOnly;
//MasterTogle();
}
_isCurrentMaster = Networking.IsMaster;

}

public void MasterToggleButton() //Call RunProgram on this method
Expand Down Expand Up @@ -64,7 +67,14 @@ public override void OnOwnershipTransferred()
timeBar.interactable = videoPlayer.EnableTimeBar();
}
}

public override void OnPlayerLeft(VRCPlayerApi player)
{
if (!_isCurrentMaster && Networking.IsMaster)
{
_isCurrentMaster = true;
OnOwnershipTransferred();
}
}
public override void OnDeserialization()
{
if (!Networking.IsMaster)
Expand Down
73 changes: 73 additions & 0 deletions PanelController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

using System;
using UdonSharp;
using UnityEngine;
using VRC.SDK3.Components;
using VRC.SDKBase;
using VRC.Udon;

namespace UdonVR.Takato.VideoPlayer
{
/// <summary>
///
/// </summary>
public class PanelController : UdonSharpBehaviour
{
public PanelUI[] panels;

public void AutoResyncToggle(bool value)
{
foreach (PanelUI Panel in panels)
{
Panel.AutoResyncToggle(value);
}
}
public void AutoResyncRateInput(int value)
{
foreach (PanelUI Panel in panels)
{
Panel.AutoResyncRateInput(value);
}
}

public void SetOwnerText(string displayName)
{
foreach (PanelUI Panel in panels)
{
Panel.SetOwnerText(displayName);
}
}

public void SetVideoTimeBarMaxValue(float value)
{
foreach (PanelUI Panel in panels)
{
Panel.SetVideoTimeBarMaxValue(value);
}
}

public void SetVideoTimeBarValue(int value)
{
foreach (PanelUI Panel in panels)
{
Panel.SetVideoTimeBarValue(value);
}
}

public void VideoTimeBarInteractable(bool value)
{
foreach (PanelUI Panel in panels)
{
Panel.VideoTimeBarInteractable(value);
}
}

public void SetResyncText(string value)
{
foreach (PanelUI Panel in panels)
{
Panel.SetResyncText(value);
}
}
}
}
96 changes: 96 additions & 0 deletions PanelUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using TMPro;
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDK3.Components;
using VRC.SDKBase;
using VRC.Udon;

namespace UdonVR.Takato.VideoPlayer
{
/// <summary>
///
/// </summary>
public class PanelUI : UdonSharpBehaviour
{
public UdonSyncVideoPlayer UdonSyncVideoPlayer;
public GameObject autoResyncFilled;
public TextMeshProUGUI resyncText;
public InputField autoResyncRateInput;
public Text ownerText;
public Slider videoTimeBar;
public Text videoTimeBarText;

public void AutoResyncToggle(bool value)
{
if (Utilities.IsValid(autoResyncFilled))
{
autoResyncFilled.SetActive(value);
}
}

public void AutoResyncSet()
{
if (Utilities.IsValid(autoResyncRateInput))
{
if (!string.IsNullOrEmpty(autoResyncRateInput.text.Trim()))
return;

int temp;
int.TryParse(autoResyncRateInput.text, out temp);
UdonSyncVideoPlayer.AutoResyncSet(temp);
autoResyncRateInput.text = string.Empty;

}
}
public void AutoResyncRateInput(int value)
{
if (Utilities.IsValid(autoResyncRateInput))
{
((Text)autoResyncRateInput.placeholder).text= value.ToString();

}
}

public void SetOwnerText(string displayName)
{
if (Utilities.IsValid(ownerText))
{
ownerText.text = displayName;
}
}

public void SetVideoTimeBarValue(int value)
{
if (Utilities.IsValid(videoTimeBar))
{
videoTimeBar.value = value;
}
}

public void SetVideoTimeBarMaxValue(float value)
{
if (Utilities.IsValid(videoTimeBar))
{
videoTimeBar.maxValue = value;
}
}

public void VideoTimeBarInteractable(bool value)
{
if (Utilities.IsValid(videoTimeBar))
{
videoTimeBar.interactable = value;
}
}

public void SetResyncText(string value)
{
if (Utilities.IsValid(resyncText))
{
resyncText.text = value;
}
}
}
}
76 changes: 76 additions & 0 deletions StutterDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}
}
Loading

0 comments on commit 4c4349f

Please sign in to comment.