136 lines
3.9 KiB
C#
136 lines
3.9 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Data;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class PermissionsPanel : UdonSharpBehaviour
|
|
{
|
|
[UdonSynced] private string[] PlayerData_Name = new string[MAX_PLAYERS_IN_LIST];
|
|
[UdonSynced] private int[] PlayerData_ID = new int[MAX_PLAYERS_IN_LIST];
|
|
[UdonSynced] private bool[] PlayerData_Admin = new bool[MAX_PLAYERS_IN_LIST];
|
|
[UdonSynced] private bool[] PlayerData_Host = new bool[MAX_PLAYERS_IN_LIST];
|
|
[UdonSynced] private bool[] PlayerData_Camera = new bool[MAX_PLAYERS_IN_LIST];
|
|
|
|
[SerializeField] private RectTransform _ListContainer;
|
|
[SerializeField] private GameObject _PlayerItemTemplate;
|
|
|
|
private const int MAX_PLAYERS_IN_LIST = 85;
|
|
|
|
|
|
public override void OnPlayerJoined(VRCPlayerApi Player)
|
|
{
|
|
for (int i = 0; i < MAX_PLAYERS_IN_LIST; i++)
|
|
{
|
|
if (PlayerData_Name[i] == null)
|
|
{
|
|
PlayerData_Name[i] = Player.displayName;
|
|
PlayerData_ID[i] = Player.playerId;
|
|
|
|
PlayerData_Admin[i] = (Player.isInstanceOwner || Player.isMaster);
|
|
PlayerData_Host[i] = (Player.isInstanceOwner || Player.isMaster);
|
|
PlayerData_Camera[i] = (Player.isInstanceOwner || Player.isMaster);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
RequestSerialization();
|
|
|
|
base.OnPlayerJoined(Player);
|
|
}
|
|
|
|
public override void OnPlayerLeft(VRCPlayerApi Player)
|
|
{
|
|
for (int i = 0; i < MAX_PLAYERS_IN_LIST; i++)
|
|
{
|
|
if (PlayerData_Name[i] == Player.displayName)
|
|
{
|
|
PlayerData_Name[i] = null;
|
|
break;
|
|
}
|
|
}
|
|
|
|
string[] NewPlayerData_Name = new string[MAX_PLAYERS_IN_LIST];
|
|
int[] NewPlayerData_ID = new int[MAX_PLAYERS_IN_LIST];
|
|
bool[] NewPlayerData_Admin = new bool[MAX_PLAYERS_IN_LIST];
|
|
bool[] NewPlayerData_Host = new bool[MAX_PLAYERS_IN_LIST];
|
|
bool[] NewPlayerData_Camera = new bool[MAX_PLAYERS_IN_LIST];
|
|
|
|
for (int i = 0; i < MAX_PLAYERS_IN_LIST; i++)
|
|
{
|
|
for (int j = i; j < MAX_PLAYERS_IN_LIST; j++)
|
|
{
|
|
if (PlayerData_Name[j] != null)
|
|
{
|
|
NewPlayerData_Name[i] = PlayerData_Name[j];
|
|
NewPlayerData_ID[i] = PlayerData_ID[j];
|
|
NewPlayerData_Admin[i] = PlayerData_Admin[j];
|
|
NewPlayerData_Host[i] = PlayerData_Host[j];
|
|
NewPlayerData_Camera[i] = PlayerData_Camera[j];
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
PlayerData_Name = NewPlayerData_Name;
|
|
PlayerData_ID = NewPlayerData_ID;
|
|
PlayerData_Admin = NewPlayerData_Admin;
|
|
PlayerData_Host = NewPlayerData_Host;
|
|
PlayerData_Camera = NewPlayerData_Camera;
|
|
|
|
RequestSerialization();
|
|
|
|
base.OnPlayerLeft(Player);
|
|
}
|
|
|
|
public override void OnDeserialization(DeserializationResult Result)
|
|
{
|
|
base.OnDeserialization(Result);
|
|
}
|
|
|
|
|
|
public void PermissionsChanged()
|
|
{
|
|
for (int i = 0; i < _ListContainer.childCount; i++)
|
|
{
|
|
GameObject Entry = _ListContainer.GetChild(i).gameObject;
|
|
PermissionsPanelPlayerEntry PlayerEntry = Entry.GetComponent<PermissionsPanelPlayerEntry>();
|
|
|
|
PlayerData_Admin[i] = PlayerEntry.AdminToggle.isOn;
|
|
PlayerData_Host[i] = PlayerEntry.HostToggle.isOn;
|
|
PlayerData_Camera[i] = PlayerEntry.CameraToggle.isOn;
|
|
}
|
|
}
|
|
|
|
|
|
private void RebuildPlayerList()
|
|
{
|
|
int CurrentListCount = _ListContainer.childCount;
|
|
for (int i = 0; i < CurrentListCount; i++)
|
|
{
|
|
Destroy(_ListContainer.GetChild(CurrentListCount - i - 1).gameObject);
|
|
}
|
|
|
|
for (int i = 0; i < VRCPlayerApi.GetPlayerCount(); i++)
|
|
{
|
|
GameObject NewListItem = Instantiate<GameObject>(_PlayerItemTemplate, _ListContainer, false);
|
|
NewListItem.SetActive(true);
|
|
PermissionsPanelPlayerEntry PlayerListItem = NewListItem.GetComponent<PermissionsPanelPlayerEntry>();
|
|
PlayerListItem.PlayerNameUI.text = PlayerData_Name[i];
|
|
|
|
PlayerListItem.AdminToggle.SetIsOnWithoutNotify(PlayerData_Admin[i]);
|
|
PlayerListItem.HostToggle.SetIsOnWithoutNotify(PlayerData_Host[i]);
|
|
PlayerListItem.CameraToggle.SetIsOnWithoutNotify(PlayerData_Camera[i]);
|
|
|
|
PlayerListItem.AdminToggle.interactable = false;
|
|
PlayerListItem.HostToggle.interactable = false;
|
|
PlayerListItem.CameraToggle.interactable = false;
|
|
}
|
|
}
|
|
}
|