-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MasterOnly.cs
103 lines (95 loc) · 3.14 KB
/
MasterOnly.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using UnityEngine;
using UdonSharp;
using UnityEngine.UI;
using VRC.SDK3.Components;
using VRC.SDKBase;
using UdonVR.Takato.VideoPlayer;
namespace UdonVR.Takato
{
public class MasterOnly : UdonSharpBehaviour
{
public VRCUrlInputField videoURLInputField;
public UdonSyncVideoPlayer videoPlayer;
public Toggle masterToggle;
public Button playButton;
public Button pauseButton;
public Button stopButton;
public Slider timeBar;
[UdonSynced] public bool syncedMasterOnly = true;
private bool _masterOnly;
private bool _isCurrentMaster;
private void Start()
{
if (Networking.IsMaster && syncedMasterOnly)
{
masterToggle.isOn = syncedMasterOnly;
//MasterTogle();
}
_isCurrentMaster = Networking.IsMaster;
}
public override bool OnOwnershipRequest(VRCPlayerApi requestingPlayer, VRCPlayerApi requestedOwner)
{
if (syncedMasterOnly)
{
if (requestedOwner.isMaster) return false;
if (requestingPlayer.isMaster) return true;
}
else
{
return true;
}
return false;
}
public void MasterToggleButton() //Call RunProgram on this method
{
Debug.Log("[UdonVR] MasterToggle!");
if (Networking.IsMaster)
{
syncedMasterOnly = masterToggle.isOn;
videoPlayer.TakeOwner();
}
else
masterToggle.isOn = syncedMasterOnly;
}
private void MasterTogle()
{
_masterOnly = syncedMasterOnly;
masterToggle.isOn = _masterOnly;
playButton.interactable = !_masterOnly;
pauseButton.interactable = !_masterOnly;
stopButton.interactable = !_masterOnly;
videoURLInputField.interactable = !_masterOnly;
if (videoPlayer.EnableTimeBar())
timeBar.interactable = !_masterOnly;
}
public override void OnOwnershipTransferred(VRCPlayerApi _player)
{
if (Networking.IsMaster)
{
playButton.interactable = true;
pauseButton.interactable = true;
stopButton.interactable = true;
videoURLInputField.interactable = true;
timeBar.interactable = videoPlayer.EnableTimeBar();
}
}
public override void OnPlayerLeft(VRCPlayerApi _player)
{
if (!_isCurrentMaster && Networking.IsMaster)
{
_isCurrentMaster = true;
OnOwnershipTransferred(_player);
}
}
public override void OnDeserialization()
{
if (!Networking.IsMaster)
{
if (_masterOnly != syncedMasterOnly)
{
MasterTogle();
}
}
}
}
}