Init
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using Mirror;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class MyRoomManager : NetworkRoomManager
|
||||
{
|
||||
|
||||
public static new MyRoomManager singleton => NetworkManager.singleton as MyRoomManager;
|
||||
public override void OnRoomClientSceneChanged()
|
||||
{
|
||||
base.OnRoomClientSceneChanged();
|
||||
if (networkSceneName == GameplayScene)
|
||||
{
|
||||
foreach (MyRoomPlayer player in roomSlots.ToList())
|
||||
{
|
||||
player.model.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if (networkSceneName == RoomScene)
|
||||
{
|
||||
foreach (MyRoomPlayer player in roomSlots.ToList())
|
||||
{
|
||||
player.model.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void OnRoomStopClient()
|
||||
{
|
||||
base.OnRoomStopClient();
|
||||
}
|
||||
|
||||
public override void OnRoomStopServer()
|
||||
{
|
||||
base.OnRoomStopServer();
|
||||
}
|
||||
|
||||
/*
|
||||
This code below is to demonstrate how to do a Start button that only appears for the Host player
|
||||
showStartButton is a local bool that's needed because OnRoomServerPlayersReady is only fired when
|
||||
all players are ready, but if a player cancels their ready state there's no callback to set it back to false
|
||||
Therefore, allPlayersReady is used in combination with showStartButton to show/hide the Start button correctly.
|
||||
Setting showStartButton false when the button is pressed hides it in the game scene since NetworkRoomManager
|
||||
is set as DontDestroyOnLoad = true.
|
||||
*/
|
||||
|
||||
#if !UNITY_SERVER
|
||||
bool showStartButton;
|
||||
#endif
|
||||
|
||||
public override void OnRoomServerPlayersReady()
|
||||
{
|
||||
// calling the base method calls ServerChangeScene as soon as all players are in Ready state.
|
||||
if (Utils.IsHeadless())
|
||||
base.OnRoomServerPlayersReady();
|
||||
#if !UNITY_SERVER
|
||||
else
|
||||
showStartButton = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !UNITY_SERVER
|
||||
public override void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
|
||||
if (allPlayersReady && showStartButton && GUI.Button(new Rect(150, 300, 120, 20), "START GAME"))
|
||||
{
|
||||
// set to false to hide it in the game scene
|
||||
showStartButton = false;
|
||||
|
||||
ServerChangeScene(GameplayScene);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bf7a40ab294c80448b22b82ca91c15d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/HotUpdate/Main/MirrorRoomTest/MyRoomPlayer.cs
Normal file
57
Assets/Scripts/HotUpdate/Main/MirrorRoomTest/MyRoomPlayer.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Cinemachine;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
|
||||
public class MyRoomPlayer : NetworkRoomPlayer
|
||||
{
|
||||
public CinemachineVirtualCamera vCam;
|
||||
public GameObject model;
|
||||
public override void OnStartClient()
|
||||
{
|
||||
//Debug.Log($"OnStartClient {gameObject}");
|
||||
}
|
||||
|
||||
public override void OnClientEnterRoom()
|
||||
{
|
||||
//Debug.Log($"OnClientEnterRoom {SceneManager.GetActiveScene().path}");
|
||||
}
|
||||
[Command]
|
||||
public override void CmdChangeReadyState(bool readyState)
|
||||
{
|
||||
Debug.Log($"CmdChangeReadyState called (Host={isServer}, Local={isLocalPlayer})");
|
||||
SetReadyToBegin(readyState);
|
||||
MyRoomManager room = MyRoomManager.singleton as MyRoomManager;
|
||||
if (room != null)
|
||||
{
|
||||
room.ReadyStatusChanged();
|
||||
}
|
||||
//base.CmdChangeReadyState(readyState);
|
||||
}
|
||||
public override void OnClientExitRoom()
|
||||
{
|
||||
//Debug.Log($"OnClientExitRoom {SceneManager.GetActiveScene().path}");
|
||||
}
|
||||
|
||||
public override void IndexChanged(int oldIndex, int newIndex)
|
||||
{
|
||||
//Debug.Log($"IndexChanged {newIndex}");
|
||||
transform.position += new Vector3(2 * newIndex, 0, 0);
|
||||
}
|
||||
|
||||
public override void ReadyStateChanged(bool oldReadyState, bool newReadyState)
|
||||
{
|
||||
//Debug.Log($"ReadyStateChanged {newReadyState}");
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartLocalPlayer();
|
||||
vCam.Priority = 12;
|
||||
}
|
||||
|
||||
#if !UNITY_SERVER
|
||||
public override void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f3d79682e31e6478b25d85b6ff3f2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user