Advertisement
reymark11

Untitled

Nov 29th, 2021
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 KB | None | 0 0
  1. using UdonSharp;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using VRC.SDKBase;
  5. using VRC.Udon;
  6.  
  7. public class TeleportationSettings : UdonSharpBehaviour
  8. {
  9.     VRCPlayerApi _player;
  10.     string _playerName;
  11.     [UdonSynced] bool[] isEnabled = new bool[3];
  12.     public string toggleType;
  13.     public UdonSharpBehaviour menuSettings;
  14.     public GameObject userAllowedSettings;
  15.  
  16.     /*
  17.      * bool 0 = Users Allowed To Change Settings
  18.      * bool 1 = Allow Player Teleportation
  19.      * bool 2 = Allow Destination Teleportation
  20.      *
  21.      * Objects Using Script:
  22.      *  Change Set Toggle
  23.      *  Player Tele Toggle
  24.      *  Destination Tele Toggle
  25.      */
  26.  
  27.  
  28.     private void Start()
  29.     {
  30.         _player = Networking.LocalPlayer;
  31.         _playerName = _player.displayName;
  32.         isEnabled[0] = (bool) menuSettings.GetProgramVariable("UsersAllowedToChangeSettings");
  33.         isEnabled[1] = (bool) menuSettings.GetProgramVariable("AllowPlayerTeleportation");
  34.         isEnabled[2] = (bool) menuSettings.GetProgramVariable("AllowDestinationTeleportation");
  35.  
  36.         if (toggleType == "UATCS")
  37.             gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
  38.         else if (toggleType == "APT")
  39.             gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
  40.         else if (toggleType == "ADT")
  41.             gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
  42.     }
  43.  
  44.     /*
  45.      * Gameobject: Change Set Toggle
  46.      * Set new object owner. Match string types of instance player aand world creator
  47.      * Request a serialization sync
  48.      */
  49.  
  50.     public void ClickUserAllowedChangeSettings()
  51.     {
  52.         if (!_player.IsOwner(gameObject))
  53.             Networking.SetOwner(_player, gameObject);
  54.        
  55.         if ((string)menuSettings.GetProgramVariable("worldCreatorName") != _playerName)
  56.         {
  57.             gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
  58.             return;
  59.         }
  60.         Debug.Log(isEnabled[0] + " = " + !isEnabled[0]);
  61.         isEnabled[0] = !isEnabled[0];
  62.         gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
  63.         RequestSerialization();
  64.     }
  65.  
  66.     /*
  67.     * Gameobject: Player Tele Toggle && Destination Tele Toggle (Method AllowDestinationTeleportation)
  68.     * Set new object owner. Match string types of instance player and world master
  69.     * Request a serialization sync
  70.     */
  71.  
  72.     public void AllowPlayerTeleportation()
  73.     {
  74.         if (!_player.IsOwner(gameObject))
  75.             Networking.SetOwner(_player, gameObject);
  76.  
  77.         Debug.Log(!userAllowedSettings.GetComponent<Toggle>().isOn);
  78.         if (!_player.isMaster || !userAllowedSettings.GetComponent<Toggle>().isOn)
  79.         {
  80.             gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
  81.             return;
  82.         }
  83.  
  84.         isEnabled[1] = !isEnabled[1];
  85.         gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
  86.         RequestSerialization();
  87.  
  88.     }
  89.  
  90.     public void AllowDestinationTeleportation()
  91.     {
  92.         if (!_player.IsOwner(gameObject))
  93.             Networking.SetOwner(_player, gameObject);
  94.  
  95.         Debug.Log(!userAllowedSettings.GetComponent<Toggle>().isOn);
  96.         if (!_player.isMaster || !userAllowedSettings.GetComponent<Toggle>().isOn)
  97.         {
  98.             gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
  99.             return;
  100.         }
  101.  
  102.         isEnabled[2] = !isEnabled[2];
  103.         gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
  104.         RequestSerialization();
  105.  
  106.     }
  107.  
  108.     public override void OnDeserialization()
  109.     {
  110.         if (toggleType == "UATCS")
  111.             gameObject.GetComponent<Toggle>().isOn = isEnabled[0];
  112.         else if (toggleType == "APT")
  113.             gameObject.GetComponent<Toggle>().isOn = isEnabled[1];
  114.         else if (toggleType == "ADT")
  115.             gameObject.GetComponent<Toggle>().isOn = isEnabled[2];
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement