Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How i can convert ScriptableUI to Canvas?

Discussion in 'UGUI & TextMesh Pro' started by RailAxmetol, Nov 28, 2020.

  1. RailAxmetol

    RailAxmetol

    Joined:
    Mar 4, 2019
    Posts:
    1
    I have scriptable menu and i want edit this menu in future, how i can convert ScriptableUI to Canvas?
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using Photon.Pun;
    4. using Photon.Realtime;
    5.  
    6. public class PUN2_GameLobby : MonoBehaviourPunCallbacks
    7. {
    8.  
    9.     //Our player name
    10.     string playerName = "No Name";
    11.     //Users are separated from each other by gameversion (which allows you to make breaking changes).
    12.     string gameVersion = "0.9";
    13.     //The list of created rooms
    14.     List<RoomInfo> createdRooms = new List<RoomInfo>();
    15.     //Use this name when creating a Room
    16.     string roomName = "GameRoom";
    17.     Vector2 roomListScroll = Vector2.zero;
    18.     bool joiningRoom = false;
    19.  
    20.     // Use this for initialization
    21.     void Start()
    22.     {
    23.         //This makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
    24.         PhotonNetwork.AutomaticallySyncScene = true;
    25.  
    26.         if (!PhotonNetwork.IsConnected)
    27.         {
    28.             //Set the App version before connecting
    29.             PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = gameVersion;
    30.             // Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
    31.             PhotonNetwork.ConnectUsingSettings();
    32.         }
    33.     }
    34.  
    35.     public override void OnDisconnected(DisconnectCause cause)
    36.     {
    37.         Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + cause.ToString() + " ServerAddress: " + PhotonNetwork.ServerAddress);
    38.     }
    39.  
    40.     public override void OnConnectedToMaster()
    41.     {
    42.         Debug.Log("OnConnectedToMaster");
    43.         //After we connected to Master server, join the Lobby
    44.         PhotonNetwork.JoinLobby(TypedLobby.Default);
    45.     }
    46.  
    47.     public override void OnRoomListUpdate(List<RoomInfo> roomList)
    48.     {
    49.         Debug.Log("We have received the Room list");
    50.         //After this callback, update the room list
    51.         createdRooms = roomList;
    52.     }
    53.  
    54.     void OnGUI()
    55.     {
    56.         GUI.Window(0, new Rect(Screen.width / 2 - 450, Screen.height / 2 - 200, 900, 400), LobbyWindow, "Lobby");
    57.     }
    58.  
    59.     void LobbyWindow(int index)
    60.     {
    61.         //Connection Status and Room creation Button
    62.         GUILayout.BeginHorizontal();
    63.  
    64.         GUILayout.Label("Status: " + PhotonNetwork.NetworkClientState);
    65.  
    66.         if (joiningRoom || !PhotonNetwork.IsConnected || PhotonNetwork.NetworkClientState != ClientState.JoinedLobby)
    67.         {
    68.             GUI.enabled = false;
    69.         }
    70.  
    71.         GUILayout.FlexibleSpace();
    72.  
    73.         //Room name text field
    74.         roomName = GUILayout.TextField(roomName, GUILayout.Width(250));
    75.  
    76.         if (GUILayout.Button("Create Room", GUILayout.Width(125)))
    77.         {
    78.             if (roomName != "")
    79.             {
    80.                 joiningRoom = true;
    81.  
    82.                 RoomOptions roomOptions = new RoomOptions();
    83.                 roomOptions.IsOpen = true;
    84.                 roomOptions.IsVisible = true;
    85.                 roomOptions.MaxPlayers = (byte)10; //Set any number
    86.  
    87.                 PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
    88.             }
    89.         }
    90.  
    91.         GUILayout.EndHorizontal();
    92.  
    93.         //Scroll through available rooms
    94.         roomListScroll = GUILayout.BeginScrollView(roomListScroll, true, true);
    95.  
    96.         if (createdRooms.Count == 0)
    97.         {
    98.             GUILayout.Label("No Rooms were created yet...");
    99.         }
    100.         else
    101.         {
    102.             for (int i = 0; i < createdRooms.Count; i++)
    103.             {
    104.                 GUILayout.BeginHorizontal("box");
    105.                 GUILayout.Label(createdRooms[i].Name, GUILayout.Width(400));
    106.                 GUILayout.Label(createdRooms[i].PlayerCount + "/" + createdRooms[i].MaxPlayers);
    107.  
    108.                 GUILayout.FlexibleSpace();
    109.  
    110.                 if (GUILayout.Button("Join Room"))
    111.                 {
    112.                     joiningRoom = true;
    113.  
    114.                     //Set our Player name
    115.                     PhotonNetwork.NickName = playerName;
    116.  
    117.                     //Join the Room
    118.                     PhotonNetwork.JoinRoom(createdRooms[i].Name);
    119.                 }
    120.                 GUILayout.EndHorizontal();
    121.             }
    122.         }
    123.  
    124.         GUILayout.EndScrollView();
    125.  
    126.         //Set player name and Refresh Room button
    127.         GUILayout.BeginHorizontal();
    128.  
    129.         GUILayout.Label("Player Name: ", GUILayout.Width(85));
    130.         //Player name text field
    131.         playerName = GUILayout.TextField(playerName, GUILayout.Width(250));
    132.  
    133.         GUILayout.FlexibleSpace();
    134.  
    135.         GUI.enabled = (PhotonNetwork.NetworkClientState == ClientState.JoinedLobby || PhotonNetwork.NetworkClientState == ClientState.Disconnected) && !joiningRoom;
    136.         if (GUILayout.Button("Refresh", GUILayout.Width(100)))
    137.         {
    138.             if (PhotonNetwork.IsConnected)
    139.             {
    140.                 //Re-join Lobby to get the latest Room list
    141.                 PhotonNetwork.JoinLobby(TypedLobby.Default);
    142.             }
    143.             else
    144.             {
    145.                 //We are not connected, estabilish a new connection
    146.                 PhotonNetwork.ConnectUsingSettings();
    147.             }
    148.         }
    149.  
    150.         GUILayout.EndHorizontal();
    151.  
    152.         if (joiningRoom)
    153.         {
    154.             GUI.enabled = true;
    155.             GUI.Label(new Rect(900 / 2 - 50, 400 / 2 - 10, 100, 20), "Connecting...");
    156.         }
    157.     }
    158.  
    159.     public override void OnCreateRoomFailed(short returnCode, string message)
    160.     {
    161.         Debug.Log("OnCreateRoomFailed got called. This can happen if the room exists (even if not visible). Try another room name.");
    162.         joiningRoom = false;
    163.     }
    164.  
    165.     public override void OnJoinRoomFailed(short returnCode, string message)
    166.     {
    167.         Debug.Log("OnJoinRoomFailed got called. This can happen if the room is not existing or full or closed.");
    168.         joiningRoom = false;
    169.     }
    170.  
    171.     public override void OnJoinRandomFailed(short returnCode, string message)
    172.     {
    173.         Debug.Log("OnJoinRandomFailed got called. This can happen if the room is not existing or full or closed.");
    174.         joiningRoom = false;
    175.     }
    176.  
    177.     public override void OnCreatedRoom()
    178.     {
    179.         Debug.Log("OnCreatedRoom");
    180.         //Set our player name
    181.         PhotonNetwork.NickName = playerName;
    182.         //Load the Scene called GameLevel (Make sure it's added to build settings)
    183.         PhotonNetwork.LoadLevel("Among Us 3D");
    184.     }
    185.  
    186.     public override void OnJoinedRoom()
    187.     {
    188.         Debug.Log("OnJoinedRoom");
    189.     }
    190. }
    191.