change multiple scene system to dynamic indoor scene

This commit is contained in:
Vova
2024-05-27 08:23:54 +03:00
parent e071a29c90
commit 4a59cee5e6
109 changed files with 3740 additions and 83901 deletions
@@ -0,0 +1,46 @@
using Unity.AI.Navigation;
using UnityEngine;
public class IndoorController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
var indoor = GameManager.Instance.BuildingSystem.Indoor;
Instantiate(indoor.Prefab, Vector3.zero, Quaternion.identity);
Player.Instance.NavAgent.Warp(SpawnPlayer(indoor));
// If the NavMeshSurface is not assigned in the Inspector, try to find it
var navMeshSurface = indoor.Prefab.GetComponentInChildren<NavMeshSurface>();
Player.Instance.NavAgent.enabled = true;
// Build the NavMesh
if (navMeshSurface != null)
{
navMeshSurface.BuildNavMesh();
}
else
{
Debug.LogError("NavMeshSurface is not assigned and not found on the GameObject.");
}
}
private Vector3 SpawnPlayer(IndoorSO indoor)
{
var spawnPoints = GameObject.FindGameObjectsWithTag("Respawn");
BaseInteractableObject interactable = null;
if (spawnPoints != null)
{
foreach (var spawn in spawnPoints)
{
if (spawn.name.ToLower() == indoor.SpawnPointInSceneName.ToLower())
{
interactable = spawn.GetComponent<BaseInteractableObject>();
Player.Instance.SetPosition(interactable._interactionPoint);
}
}
}
GameManager.Instance.Camera.ResetToPlayerPosition();
return (interactable == null) ? Vector3.zero : interactable._interactionPoint.position;
}
}