Partially implement lobby ui, fix ui pointers on network rig
This commit is contained in:
@@ -4,6 +4,7 @@ using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
using ParrelSync;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class GameManager : NetworkBehaviour
|
||||
{
|
||||
@@ -28,8 +29,13 @@ public class GameManager : NetworkBehaviour
|
||||
|
||||
public bool IsMultiplayer => networkManager.IsHost || networkManager.IsClient;
|
||||
|
||||
public UnityEvent OnConnected;
|
||||
public UnityEvent OnDisconnected;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
networkManager.OnClientStarted += OnClientStarted;
|
||||
networkManager.OnClientStopped += OnClientStopped;
|
||||
networkManager.OnClientConnectedCallback += OnClientConnectedCallback;
|
||||
networkManager.OnClientDisconnectCallback += OnClientDisconnectCallback;
|
||||
|
||||
@@ -37,15 +43,35 @@ public class GameManager : NetworkBehaviour
|
||||
{
|
||||
if (ClonesManager.IsClone())
|
||||
{
|
||||
networkManager.StartClient();
|
||||
JoinGame("");
|
||||
}
|
||||
else
|
||||
{
|
||||
networkManager.StartHost();
|
||||
HostGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinGame(string code)
|
||||
{
|
||||
networkManager.StartClient();
|
||||
}
|
||||
|
||||
public void HostGame()
|
||||
{
|
||||
networkManager.StartHost();
|
||||
}
|
||||
|
||||
private void OnClientStarted()
|
||||
{
|
||||
OnConnected?.Invoke();
|
||||
}
|
||||
|
||||
private void OnClientStopped(bool wasHost)
|
||||
{
|
||||
OnDisconnected?.Invoke();
|
||||
}
|
||||
|
||||
private void OnClientConnectedCallback(ulong clientId)
|
||||
{
|
||||
Debug.Log($"Client-{clientId} is connected and can spawn {nameof(NetworkObject)}s.");
|
||||
@@ -63,7 +89,7 @@ public class GameManager : NetworkBehaviour
|
||||
if (toSolo)
|
||||
{
|
||||
soloRig.Toggle(toSolo);
|
||||
soloRig.Teleport(multiplayerRig.Position, multiplayerRig.Position);
|
||||
soloRig.Teleport(multiplayerRig.Position, multiplayerRig.Rotation);
|
||||
multiplayerRig.DestroyDependencies();
|
||||
multiplayerRig = null;
|
||||
}
|
||||
@@ -73,7 +99,7 @@ public class GameManager : NetworkBehaviour
|
||||
|
||||
var playerObject = networkManager.LocalClient.PlayerObject;
|
||||
multiplayerRig = playerObject.GetComponent<PlayerComponent>();
|
||||
multiplayerRig.Teleport(soloRig.Position, soloRig.Position);
|
||||
multiplayerRig.Teleport(soloRig.Position, soloRig.Rotation);
|
||||
multiplayerRig.ToggleAudioListener(true);
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ public class SceneManager : NetworkBehaviour
|
||||
{
|
||||
NetworkManager.SceneManager.OnSceneEvent += OnSceneEvent;
|
||||
|
||||
Debug.Log("network spawn");
|
||||
|
||||
base.OnNetworkSpawn();
|
||||
}
|
||||
|
||||
@@ -142,6 +140,11 @@ public class SceneManager : NetworkBehaviour
|
||||
SwitchToScene(forgeLevel.sceneName);
|
||||
}
|
||||
|
||||
public void SwitchToLevel(Level level)
|
||||
{
|
||||
SwitchToScene(level.sceneName);
|
||||
}
|
||||
|
||||
private void SwitchToScene(string sceneName)
|
||||
{
|
||||
if (isMultiplayer)
|
||||
|
||||
Reference in New Issue
Block a user