Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3.  
  4. namespace Mirror.Examples.NetworkRoom
  5. {
  6.     [AddComponentMenu("")]
  7.     public class NetworkRoomManagerExt : NetworkRoomManager
  8.     {
  9.         /// <summary>
  10.         /// Called just after GamePlayer object is instantiated and just before it replaces RoomPlayer object.
  11.         /// This is the ideal point to pass any data like player name, credentials, tokens, colors, etc.
  12.         /// into the GamePlayer object as it is about to enter the Online scene.
  13.         /// </summary>
  14.         /// <param name="roomPlayer"></param>
  15.         /// <param name="gamePlayer"></param>
  16.         /// <returns>true unless some code in here decides it needs to abort the replacement</returns>
  17.         public override bool OnRoomServerSceneLoadedForPlayer(GameObject roomPlayer, GameObject gamePlayer)
  18.         {
  19.             /*PlayerScore playerScore = gamePlayer.GetComponent<PlayerScore>();
  20.             playerScore.index = roomPlayer.GetComponent<NetworkRoomPlayer>().index;*/
  21.             return true;
  22.         }
  23.  
  24.         /*
  25.             This code below is to demonstrate how to do a Start button that only appears for the Host player
  26.             showStartButton is a local bool that's needed because OnRoomServerPlayersReady is only fired when
  27.             all players are ready, but if a player cancels their ready state there's no callback to set it back to false
  28.             Therefore, allPlayersReady is used in combination with showStartButton to show/hide the Start button correctly.
  29.             Setting showStartButton false when the button is pressed hides it in the game scene since NetworkRoomManager
  30.             is set as DontDestroyOnLoad = true.
  31.         */
  32.  
  33.         bool showStartButton;
  34.  
  35.         public override void OnRoomServerPlayersReady()
  36.         {
  37.             // calling the base method calls ServerChangeScene as soon as all players are in Ready state.
  38.             if (isHeadless)
  39.                 base.OnRoomServerPlayersReady();
  40.             else
  41.                 showStartButton = true;
  42.         }
  43.  
  44.         public override void OnGUI()
  45.         {
  46.             base.OnGUI();
  47.  
  48.             if (allPlayersReady && showStartButton && GUI.Button(new Rect(150, 300, 120, 20), "START GAME"))
  49.             {
  50.                 // set to false to hide it in the game scene
  51.                 showStartButton = false;
  52.  
  53.                 ServerChangeScene(GameplayScene);
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement