Implement player spawning in predefined location in lobby and levels

This commit is contained in:
2024-08-20 19:38:32 +02:00
parent 3f64f82464
commit 1a9e2a3ee8
23 changed files with 559 additions and 3 deletions

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5e732ef29fd8bdb4ba5e27e9279950a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93a175467b0ae0041ab4dcfc44565ae0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5997574b7f781c64e9966a9568bc9130
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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();

View File

@@ -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()

View File

@@ -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)

View File

@@ -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);
}
}