Refactor scene management, Enable wasd movement, Add level menu
This commit is contained in:
33
Assets/Scripts/Components/PlayerInputsCompoment.cs
Normal file
33
Assets/Scripts/Components/PlayerInputsCompoment.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using HurricaneVR.Framework.ControllerInput;
|
||||
using HurricaneVR.Framework.Shared;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInputsCompoment : HVRPlayerInputs
|
||||
{
|
||||
protected bool EnableMouseLook;
|
||||
|
||||
protected override void UpdateInput()
|
||||
{
|
||||
base.UpdateInput();
|
||||
|
||||
EnableMouseLook = !Input.GetKey(KeyCode.LeftAlt);
|
||||
}
|
||||
|
||||
protected override Vector2 GetMouse(out bool mouseDown)
|
||||
{
|
||||
mouseDown = EnableMouseLook;
|
||||
return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||
}
|
||||
|
||||
protected override bool GetIsJumpActivated()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/PlayerInputsCompoment.cs.meta
Normal file
11
Assets/Scripts/Components/PlayerInputsCompoment.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe887b5dbf490474eb38ab749b371efa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,6 +6,9 @@ using UnityEngine;
|
||||
[CreateAssetMenu(fileName = "Level", menuName = "Data/Level")]
|
||||
public class Level : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
public string levelName;
|
||||
|
||||
[SerializeField]
|
||||
public int health = 10;
|
||||
|
||||
@@ -17,4 +20,18 @@ public class Level : ScriptableObject
|
||||
|
||||
[SerializeField]
|
||||
public Wave[] waves = new Wave[0];
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
public string sceneName;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public UnityEditor.SceneAsset SceneAsset;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
sceneName = SceneAsset?.name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -10,32 +8,16 @@ using Zenject;
|
||||
|
||||
public class SceneManager : NetworkBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
public UnityEditor.SceneAsset LobbyScene;
|
||||
public UnityEditor.SceneAsset EntranceScene;
|
||||
public UnityEditor.SceneAsset ForgeScene;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
lobbySceneName = LobbyScene?.name;
|
||||
entranceSceneName = EntranceScene?.name;
|
||||
forgeSceneName = ForgeScene?.name;
|
||||
}
|
||||
|
||||
#endif
|
||||
[SerializeField]
|
||||
private Level lobbyLevel;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private string lobbySceneName;
|
||||
private Level entranceLevel;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private string entranceSceneName;
|
||||
private Level forgeLevel;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private string forgeSceneName;
|
||||
public Level[] Levels => new []{ entranceLevel, forgeLevel };
|
||||
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
@@ -52,7 +34,7 @@ public class SceneManager : NetworkBehaviour
|
||||
|
||||
public Scene LoadedScene => loadedScene;
|
||||
|
||||
public bool IsInLobby => loadedScene.name == lobbySceneName;
|
||||
public bool IsInLobby => loadedScene.name == lobbyLevel.sceneName;
|
||||
|
||||
public UnityEvent SceneLoaded;
|
||||
|
||||
@@ -145,19 +127,19 @@ public class SceneManager : NetworkBehaviour
|
||||
[Button]
|
||||
public void SwitchToLobbyLevel()
|
||||
{
|
||||
SwitchToScene(lobbySceneName);
|
||||
SwitchToScene(lobbyLevel.sceneName);
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void SwitchToEntranceLevel()
|
||||
{
|
||||
SwitchToScene(entranceSceneName);
|
||||
SwitchToScene(entranceLevel.sceneName);
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void SwitchToForgeLevel()
|
||||
{
|
||||
SwitchToScene(forgeSceneName);
|
||||
SwitchToScene(forgeLevel.sceneName);
|
||||
}
|
||||
|
||||
private void SwitchToScene(string sceneName)
|
||||
|
||||
@@ -28,10 +28,6 @@ public class HandMenuUI : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
private float smoothTime = 0.3F;
|
||||
private Vector3 velocity = Vector3.zero;
|
||||
private float forwardOffset = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI titleText;
|
||||
|
||||
@@ -70,6 +66,9 @@ public class HandMenuUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private GameObject settings;
|
||||
|
||||
private float forwardOffset = 0.7f;
|
||||
private float upOffset = -0.3f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (uiInput == null) return;
|
||||
@@ -92,14 +91,13 @@ public class HandMenuUI : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//UpdatePosition();
|
||||
CheckInput();
|
||||
}
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var targetPosition = lookAt.position + (lookAt.forward * forwardOffset);
|
||||
transform.position = new Vector3(targetPosition.x, lookAt.position.y, targetPosition.z);
|
||||
transform.position = new Vector3(targetPosition.x, lookAt.position.y + upOffset, targetPosition.z);
|
||||
|
||||
var lookAtPositon = new Vector3(lookAt.position.x, transform.position.y, lookAt.position.z);
|
||||
transform.rotation = Quaternion.LookRotation(transform.position - lookAtPositon);
|
||||
|
||||
38
Assets/Scripts/UI/LevelItemUI.cs
Normal file
38
Assets/Scripts/UI/LevelItemUI.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LevelItemUI : MonoBehaviour
|
||||
{
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private Level level;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private bool isLocked;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI difficultyText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI nameText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI descriptionText;
|
||||
|
||||
[SerializeField]
|
||||
private Image backgroundImage;
|
||||
|
||||
public void Setup(Level level, bool isLocked)
|
||||
{
|
||||
this.level = level;
|
||||
this.isLocked = isLocked;
|
||||
|
||||
nameText.text = level.levelName;
|
||||
difficultyText.text = "0";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/LevelItemUI.cs.meta
Normal file
11
Assets/Scripts/UI/LevelItemUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 206bb935443c1d243ad35d3a7e349de1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/UI/LevelMenuUI.cs
Normal file
57
Assets/Scripts/UI/LevelMenuUI.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using HurricaneVR.Framework.Core.UI;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
public class LevelMenuUI : MonoBehaviour
|
||||
{
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private SceneManager sceneManager;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject levelSelection;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject levelSelectionContent;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject levelItemPrefab;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (uiInput == null) return;
|
||||
|
||||
canvas = GetComponent<Canvas>();
|
||||
uiInput?.AddCanvas(canvas);
|
||||
|
||||
UpdateLevelSelection();
|
||||
}
|
||||
|
||||
private void UpdateLevelSelection()
|
||||
{
|
||||
foreach (Transform transform in levelSelectionContent.transform)
|
||||
{
|
||||
Destroy(transform.gameObject);
|
||||
}
|
||||
|
||||
foreach (var level in sceneManager.Levels)
|
||||
{
|
||||
var go = Instantiate(levelItemPrefab);
|
||||
go.name = level.name;
|
||||
go.transform.SetParent(levelSelectionContent.transform, false);
|
||||
go.GetComponent<LevelItemUI>().Setup(level, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/LevelMenuUI.cs.meta
Normal file
11
Assets/Scripts/UI/LevelMenuUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad9a6ec509c78a8498dcfad96bc9e8a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user