Implement player spawning in predefined location in lobby and levels
This commit is contained in:
35
Assets/Scripts/Components/DrawGizmoComponent.cs
Normal file
35
Assets/Scripts/Components/DrawGizmoComponent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DrawGizmoComponent : MonoBehaviour
|
||||
{
|
||||
enum Gizmo
|
||||
{
|
||||
WireCube,
|
||||
WireSphere
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Gizmo gizmo = Gizmo.WireCube;
|
||||
|
||||
[SerializeField]
|
||||
private Color color = Color.yellow;
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = color;
|
||||
|
||||
switch (gizmo)
|
||||
{
|
||||
case Gizmo.WireCube:
|
||||
Gizmos.DrawWireCube(transform.position, new Vector3(1, 1, 1));
|
||||
break;
|
||||
|
||||
case Gizmo.WireSphere:
|
||||
Gizmos.DrawWireSphere(transform.position, 0.5f);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/DrawGizmoComponent.cs.meta
Normal file
11
Assets/Scripts/Components/DrawGizmoComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e732ef29fd8bdb4ba5e27e9279950a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Features.meta
Normal file
8
Assets/Scripts/Features.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93a175467b0ae0041ab4dcfc44565ae0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Scripts/Features/PlayerSpawner.cs
Normal file
26
Assets/Scripts/Features/PlayerSpawner.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerSpawner : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Transform[] spawns = new Transform[0];
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
spawns = GetComponentsInChildren<Transform>()
|
||||
.Where((x) => x != transform)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public void Spawn(GameObject player)
|
||||
{
|
||||
player.GetComponent<HVRTeleporter>().Teleport(spawns.First().position);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Features/PlayerSpawner.cs.meta
Normal file
11
Assets/Scripts/Features/PlayerSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5997574b7f781c64e9966a9568bc9130
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,8 +6,14 @@ public class LevelInstaller : MonoInstaller
|
||||
[SerializeField]
|
||||
private Level level;
|
||||
|
||||
[SerializeField]
|
||||
private PlayerSpawner playerSpawner;
|
||||
|
||||
public override void InstallBindings()
|
||||
{
|
||||
Container.BindInstance(playerSpawner)
|
||||
.AsSingle();
|
||||
|
||||
Container.Bind<Level>()
|
||||
.FromInstance(level)
|
||||
.AsSingle();
|
||||
|
||||
@@ -3,8 +3,14 @@ using Zenject;
|
||||
|
||||
public class LobbyInstaller : MonoInstaller
|
||||
{
|
||||
[SerializeField]
|
||||
private PlayerSpawner playerSpawner;
|
||||
|
||||
public override void InstallBindings()
|
||||
{
|
||||
Container.BindInstance(playerSpawner)
|
||||
.AsSingle();
|
||||
|
||||
Container.Bind<LobbyManager>()
|
||||
.FromComponentsInNewPrefabResource("Managers/LobbyManager")
|
||||
.AsSingle()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -24,6 +25,16 @@ public class LevelManager : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private MusicManager musicManager;
|
||||
|
||||
[Inject]
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private PlayerSpawner playerSpawner;
|
||||
|
||||
[Inject]
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private HVRPlayerController playerController;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
health = level.health;
|
||||
@@ -32,6 +43,8 @@ public class LevelManager : MonoBehaviour
|
||||
{
|
||||
musicManager.Play(level.pauseClip);
|
||||
}
|
||||
|
||||
playerSpawner.Spawn(playerController.gameObject);
|
||||
}
|
||||
|
||||
public void OnEnemyReachedFinish(EnemyComponent enemy)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,11 +12,23 @@ public class LobbyManager : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private MusicManager musicManager;
|
||||
|
||||
[Inject]
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private PlayerSpawner playerSpawner;
|
||||
|
||||
[Inject]
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private HVRPlayerController playerController;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip backgroundMusicClip;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
musicManager.Play(backgroundMusicClip);
|
||||
|
||||
playerSpawner.Spawn(playerController.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user