62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.Core.Pool;
|
|
using VRC.SDK3.Data;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class PermissionsPanel : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private RectTransform _ListContainer;
|
|
|
|
[SerializeField] private GameObject _PlayerItemTemplate;
|
|
|
|
private DataDictionary PlayerData = new DataDictionary();
|
|
|
|
|
|
public override void OnPlayerJoined(VRCPlayerApi Player)
|
|
{
|
|
GameObject NewListItem = Instantiate<GameObject>(_PlayerItemTemplate, _ListContainer, false);
|
|
NewListItem.SetActive(true);
|
|
PermissionsPanelPlayerEntry PlayerListItem = NewListItem.GetComponent<PermissionsPanelPlayerEntry>();
|
|
PlayerListItem.PlayerNameUI.text = Player.displayName;
|
|
|
|
PlayerData[Player.displayName] = new DataDictionary();
|
|
PlayerData[Player.displayName].DataDictionary["Admin"] = Player.isInstanceOwner;
|
|
PlayerData[Player.displayName].DataDictionary["Host"] = Player.isInstanceOwner;
|
|
PlayerData[Player.displayName].DataDictionary["Camera"] = Player.isInstanceOwner;
|
|
|
|
if (Networking.LocalPlayer.isInstanceOwner)
|
|
{
|
|
PlayerListItem.AdminToggle.interactable = true;
|
|
PlayerListItem.HostToggle.interactable = true;
|
|
PlayerListItem.CameraToggle.interactable = true;
|
|
|
|
PlayerListItem.AdminToggle.SetIsOnWithoutNotify(true);
|
|
PlayerListItem.HostToggle.SetIsOnWithoutNotify(true);
|
|
PlayerListItem.CameraToggle.SetIsOnWithoutNotify(true);
|
|
}
|
|
|
|
base.OnPlayerJoined(Player);
|
|
}
|
|
|
|
public override void OnPlayerLeft(VRCPlayerApi player)
|
|
{
|
|
for (int i = 0; i < _ListContainer.childCount; i++)
|
|
{
|
|
GameObject Entry = _ListContainer.GetChild(i).gameObject;
|
|
PermissionsPanelPlayerEntry PlayerEntry = Entry.GetComponent<PermissionsPanelPlayerEntry>();
|
|
if (PlayerEntry != null && PlayerEntry.PlayerNameUI.text == player.displayName)
|
|
{
|
|
Destroy(Entry);
|
|
break;
|
|
}
|
|
}
|
|
|
|
base.OnPlayerLeft(player);
|
|
}
|
|
}
|