Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UdonSharp;
- using UnityEngine;
- using UnityEngine.UI;
- using VRC.SDKBase;
- using VRC.Udon;
- public class TeleportationSettings : UdonSharpBehaviour
- {
- VRCPlayerApi _player;
- string _playerName;
- [UdonSynced] bool[] isEnabled = new bool[3];
- public string toggleType;
- public UdonSharpBehaviour menuSettings;
- public GameObject userAllowedSettings;
- /*
- * bool 0 = Users Allowed To Change Settings
- * bool 1 = Allow Player Teleportation
- * bool 2 = Allow Destination Teleportation
- *
- * Objects Using Script:
- * Change Set Toggle
- * Player Tele Toggle
- * Destination Tele Toggle
- */
- private void Start()
- {
- _player = Networking.LocalPlayer;
- _playerName = _player.displayName;
- isEnabled[0] = (bool) menuSettings.GetProgramVariable("UsersAllowedToChangeSettings");
- isEnabled[1] = (bool) menuSettings.GetProgramVariable("AllowPlayerTeleportation");
- isEnabled[2] = (bool) menuSettings.GetProgramVariable("AllowDestinationTeleportation");
- if (toggleType == "UATCS")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
- else if (toggleType == "APT")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
- else if (toggleType == "ADT")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
- }
- /*
- * Gameobject: Change Set Toggle
- * Set new object owner. Match string types of instance player aand world creator
- * Request a serialization sync
- */
- public void ClickUserAllowedChangeSettings()
- {
- if (!_player.IsOwner(gameObject))
- Networking.SetOwner(_player, gameObject);
- if ((string)menuSettings.GetProgramVariable("worldCreatorName") != _playerName)
- {
- gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
- return;
- }
- Debug.Log(isEnabled[0] + " = " + !isEnabled[0]);
- isEnabled[0] = !isEnabled[0];
- gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
- RequestSerialization();
- }
- /*
- * Gameobject: Player Tele Toggle && Destination Tele Toggle (Method AllowDestinationTeleportation)
- * Set new object owner. Match string types of instance player and world master
- * Request a serialization sync
- */
- public void AllowPlayerTeleportation()
- {
- if (!_player.IsOwner(gameObject))
- Networking.SetOwner(_player, gameObject);
- Debug.Log(!userAllowedSettings.GetComponent<Toggle>().isOn);
- if (!_player.isMaster || !userAllowedSettings.GetComponent<Toggle>().isOn)
- {
- gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
- return;
- }
- isEnabled[1] = !isEnabled[1];
- gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
- RequestSerialization();
- }
- public void AllowDestinationTeleportation()
- {
- if (!_player.IsOwner(gameObject))
- Networking.SetOwner(_player, gameObject);
- Debug.Log(!userAllowedSettings.GetComponent<Toggle>().isOn);
- if (!_player.isMaster || !userAllowedSettings.GetComponent<Toggle>().isOn)
- {
- gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
- return;
- }
- isEnabled[2] = !isEnabled[2];
- gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
- RequestSerialization();
- }
- public override void OnDeserialization()
- {
- if (toggleType == "UATCS")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
- else if (toggleType == "APT")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
- else if (toggleType == "ADT")
- gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement