- Jail phone now runs its callback as the GameManagerRound2 owner. - Actually updated the camera system repository this time. Finally.
151 lines
3.5 KiB
C#
151 lines
3.5 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common;
|
|
using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class PlayerPodiumRound2 : UdonSharpBehaviour
|
|
{
|
|
[UdonSynced] private string _PlayerName = "";
|
|
[UdonSynced] private bool _EnableOwnershipInteract = false;
|
|
|
|
[Header("Objects")]
|
|
[SerializeField] private PlayerPedestal _Pedestal;
|
|
[SerializeField] private GameObject _OwnershipTransferInteract;
|
|
|
|
[Space]
|
|
|
|
[Header("Miscellaneous")]
|
|
[SerializeField] private Transform _SpawnPoint;
|
|
|
|
|
|
public override void OnDeserialization(DeserializationResult Result)
|
|
{
|
|
_SetPlayer_Synced();
|
|
|
|
base.OnDeserialization(Result);
|
|
}
|
|
|
|
public override void OnPlayerLeft(VRCPlayerApi Player)
|
|
{
|
|
if (Player.displayName == _PlayerName)
|
|
{
|
|
ResetOwner(true);
|
|
}
|
|
|
|
base.OnPlayerLeft(Player);
|
|
}
|
|
|
|
public override void OnAvatarEyeHeightChanged(VRCPlayerApi Player, float PrevEyeHeightAsMeters)
|
|
{
|
|
if (Player.displayName == _PlayerName)
|
|
{
|
|
_Pedestal.AdjustHeight(Player);
|
|
|
|
if (Player == Networking.LocalPlayer)
|
|
{
|
|
Player.TeleportTo(_SpawnPoint.position, _SpawnPoint.rotation);
|
|
}
|
|
}
|
|
|
|
base.OnAvatarEyeHeightChanged(Player, PrevEyeHeightAsMeters);
|
|
}
|
|
|
|
|
|
public bool SetPlayer(string Player, bool EnableOwnershipInteract = false)
|
|
{
|
|
VRCPlayerApi[] Players = new VRCPlayerApi[VRCPlayerApi.GetPlayerCount()];
|
|
VRCPlayerApi.GetPlayers(Players);
|
|
for (int i = 0; i < Players.Length; i++)
|
|
{
|
|
VRCPlayerApi PlayerObject = Players[i];
|
|
if (PlayerObject != null && PlayerObject.displayName == Player)
|
|
{
|
|
Networking.SetOwner(PlayerObject, gameObject);
|
|
Networking.SetOwner(PlayerObject, _Pedestal.gameObject);
|
|
|
|
SendCustomNetworkEvent(NetworkEventTarget.Owner,
|
|
nameof(SetPlayer_NetworkCallable), EnableOwnershipInteract);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
_PlayerName = "";
|
|
_EnableOwnershipInteract = true;
|
|
ResetOwner();
|
|
|
|
return false;
|
|
}
|
|
|
|
public string GetPlayer()
|
|
{
|
|
return _PlayerName;
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void SetPlayer_NetworkCallable(bool EnableOwnershipInteract)
|
|
{
|
|
_PlayerName = Networking.LocalPlayer.displayName;
|
|
_EnableOwnershipInteract = EnableOwnershipInteract;
|
|
|
|
_Pedestal.EnableStandInteractLocally(true);
|
|
_Pedestal.AdjustHeight(Networking.LocalPlayer);
|
|
|
|
_SetPlayer_Synced();
|
|
RequestSerialization();
|
|
}
|
|
|
|
private void _SetPlayer_Synced()
|
|
{
|
|
_EnableOwnershipInteract_Synced();
|
|
}
|
|
|
|
public bool SetPlayerToLocal()
|
|
{
|
|
return SetPlayer(Networking.LocalPlayer.displayName);
|
|
}
|
|
|
|
|
|
public void EnableOwnershipInteract(bool Enable)
|
|
{
|
|
_EnableOwnershipInteract = Enable;
|
|
RequestSerialization();
|
|
}
|
|
private void _EnableOwnershipInteract_Synced()
|
|
{
|
|
_OwnershipTransferInteract.SetActive(_PlayerName == "" && _EnableOwnershipInteract);
|
|
}
|
|
|
|
|
|
public void ResetOwner(bool EnableOwnershipInteract = false)
|
|
{
|
|
SendCustomNetworkEvent(NetworkEventTarget.Owner, nameof(ResetOwner_NetworkCallable), EnableOwnershipInteract);
|
|
}
|
|
[NetworkCallable]
|
|
public void ResetOwner_NetworkCallable(bool EnableOwnershipInteract)
|
|
{
|
|
_PlayerName = "";
|
|
_EnableOwnershipInteract = EnableOwnershipInteract;
|
|
|
|
_Pedestal.EnableStandInteractLocally(false);
|
|
_OwnershipTransferInteract.SetActive(_EnableOwnershipInteract);
|
|
|
|
RequestSerialization();
|
|
}
|
|
|
|
public void ResetPodium(bool EnableOwnershipInteract = false)
|
|
{
|
|
SendCustomNetworkEvent(NetworkEventTarget.Owner, nameof(ResetPodium_NetworkCallable));
|
|
}
|
|
[NetworkCallable]
|
|
public void ResetPodium_NetworkCallable(bool EnableOwnershipInteract)
|
|
{
|
|
ResetOwner_NetworkCallable(EnableOwnershipInteract);
|
|
}
|
|
}
|