Partially implement lobby ui, fix ui pointers on network rig
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using HurricaneVR.Framework.Components;
|
||||
using HurricaneVR.Framework.ControllerInput;
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using HurricaneVR.Framework.Core.UI;
|
||||
using Meta.XR.MultiplayerBlocks.NGO;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
@@ -40,7 +42,7 @@ public class PlayerComponent : NetworkBehaviour
|
||||
|
||||
public Vector3 Position => controller.transform.position;
|
||||
|
||||
public Vector3 Rotation => controller.transform.eulerAngles;
|
||||
public Vector3 Rotation => controller.Camera.forward;
|
||||
|
||||
private bool isSoloRig => !networkObject.IsPlayerObject;
|
||||
private bool isMultiplayerLocalRig => networkObject.IsLocalPlayer;
|
||||
@@ -67,6 +69,14 @@ public class PlayerComponent : NetworkBehaviour
|
||||
{
|
||||
StartCoroutine(AddDontDestroyToDependencies());
|
||||
|
||||
if (isSoloRig || isMultiplayerLocalRig)
|
||||
{
|
||||
foreach (var pointer in GetComponentsInChildren<HVRUIPointer>())
|
||||
{
|
||||
HVRInputModule.Instance.AddPointer(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSoloRig) return;
|
||||
|
||||
audioListener.enabled = true;
|
||||
|
||||
@@ -6,19 +6,28 @@ using UnityEngine;
|
||||
|
||||
public class PlayerInputsCompoment : HVRPlayerInputs
|
||||
{
|
||||
protected bool EnableMouseLook;
|
||||
protected bool EnableMouseLook = false;
|
||||
|
||||
protected override void UpdateInput()
|
||||
{
|
||||
base.UpdateInput();
|
||||
|
||||
EnableMouseLook = !Input.GetKey(KeyCode.LeftAlt);
|
||||
if (Input.GetKey(KeyCode.LeftAlt))
|
||||
{
|
||||
EnableMouseLook = !EnableMouseLook;
|
||||
}
|
||||
}
|
||||
|
||||
protected override Vector2 GetMouse(out bool mouseDown)
|
||||
{
|
||||
mouseDown = EnableMouseLook;
|
||||
return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||
|
||||
if (EnableMouseLook)
|
||||
{
|
||||
return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||
}
|
||||
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
protected override bool GetIsJumpActivated()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LevelItemUI : MonoBehaviour
|
||||
@@ -27,6 +28,8 @@ public class LevelItemUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Image backgroundImage;
|
||||
|
||||
public UnityEvent<Level> OnClicked;
|
||||
|
||||
public void Setup(Level level, bool isLocked)
|
||||
{
|
||||
this.level = level;
|
||||
@@ -35,4 +38,10 @@ public class LevelItemUI : MonoBehaviour
|
||||
nameText.text = level.levelName;
|
||||
difficultyText.text = "0";
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void OnButtonClicked()
|
||||
{
|
||||
OnClicked?.Invoke(level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Zenject;
|
||||
|
||||
public class LevelMenuUI : MonoBehaviour
|
||||
{
|
||||
[Title("Debug")]
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
@@ -16,6 +18,11 @@ public class LevelMenuUI : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private SceneManager sceneManager;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
[Title("Selection")]
|
||||
[SerializeField]
|
||||
private GameObject levelSelection;
|
||||
|
||||
@@ -23,11 +30,26 @@ public class LevelMenuUI : MonoBehaviour
|
||||
private GameObject levelSelectionContent;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
private GameObject levelItemPrefab;
|
||||
|
||||
[Title("Detail")]
|
||||
[SerializeField]
|
||||
private GameObject levelDetail;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject levelItemPrefab;
|
||||
private LevelItemUI levelDetailUI;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Level selectedLevel;
|
||||
|
||||
[SerializeField]
|
||||
private Button backButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button startButton;
|
||||
|
||||
private bool isDetailVisible => selectedLevel != null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -36,13 +58,26 @@ public class LevelMenuUI : MonoBehaviour
|
||||
canvas = GetComponent<Canvas>();
|
||||
uiInput?.AddCanvas(canvas);
|
||||
|
||||
backButton.onClick.AddListener(() => BackClicked());
|
||||
startButton.onClick.AddListener(() => StartClicked());
|
||||
|
||||
UpdateLevelSelection();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
levelSelection.SetActive(!isDetailVisible);
|
||||
levelDetail.SetActive(isDetailVisible);
|
||||
backButton.gameObject.SetActive(isDetailVisible);
|
||||
}
|
||||
|
||||
private void UpdateLevelSelection()
|
||||
{
|
||||
foreach (Transform transform in levelSelectionContent.transform)
|
||||
{
|
||||
var item = transform.gameObject.GetComponent<LevelItemUI>();
|
||||
item.OnClicked.RemoveAllListeners();
|
||||
Destroy(transform.gameObject);
|
||||
}
|
||||
|
||||
@@ -51,7 +86,27 @@ public class LevelMenuUI : MonoBehaviour
|
||||
var go = Instantiate(levelItemPrefab);
|
||||
go.name = level.name;
|
||||
go.transform.SetParent(levelSelectionContent.transform, false);
|
||||
go.GetComponent<LevelItemUI>().Setup(level, false);
|
||||
var item = go.GetComponent<LevelItemUI>();
|
||||
item.Setup(level, false);
|
||||
item.OnClicked.AddListener(OnLevelSelected);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLevelSelected(Level level)
|
||||
{
|
||||
selectedLevel = level;
|
||||
levelDetailUI.Setup(level, false);
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void BackClicked()
|
||||
{
|
||||
selectedLevel = null;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void StartClicked()
|
||||
{
|
||||
sceneManager.SwitchToLevel(selectedLevel);
|
||||
}
|
||||
}
|
||||
|
||||
81
Assets/Scripts/UI/LobbyMenuUI.cs
Normal file
81
Assets/Scripts/UI/LobbyMenuUI.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using HurricaneVR.Framework.Core.UI;
|
||||
using Sirenix.OdinInspector;
|
||||
using TMPro;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Zenject;
|
||||
|
||||
public class LobbyMenuUI : MonoBehaviour
|
||||
{
|
||||
[Title("Debug")]
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private SceneManager sceneManager;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
[Inject]
|
||||
private GameManager gameManager;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
[Title("Join or Host")]
|
||||
[SerializeField]
|
||||
private GameObject joinOrHost;
|
||||
|
||||
[SerializeField]
|
||||
private TMP_InputField roomCodeInput;
|
||||
|
||||
[SerializeField]
|
||||
private Button joinButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button hostButton;
|
||||
|
||||
private bool isConnected => gameManager.IsMultiplayer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (uiInput == null) return;
|
||||
|
||||
canvas = GetComponent<Canvas>();
|
||||
uiInput?.AddCanvas(canvas);
|
||||
|
||||
joinButton.onClick.AddListener(() => JoinClicked());
|
||||
hostButton.onClick.AddListener(() => HostClicked());
|
||||
gameManager.OnConnected.AddListener(() => UpdateUI());
|
||||
gameManager.OnDisconnected.AddListener(() => UpdateUI());
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
joinOrHost.SetActive(!isConnected);
|
||||
joinButton.interactable = true;
|
||||
hostButton.interactable = true;
|
||||
Debug.Log(isConnected);
|
||||
}
|
||||
|
||||
private void JoinClicked()
|
||||
{
|
||||
gameManager.JoinGame(roomCodeInput.text);
|
||||
joinButton.interactable = false;
|
||||
hostButton.interactable = false;
|
||||
}
|
||||
|
||||
private void HostClicked()
|
||||
{
|
||||
gameManager.HostGame();
|
||||
joinButton.interactable = false;
|
||||
hostButton.interactable = false;
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/LobbyMenuUI.cs.meta
Normal file
11
Assets/Scripts/UI/LobbyMenuUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da8a5c9d23b43d4f8c87bc076080da6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user