using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; //Define the system managing the events. (Singleton) public sealed class EventManager : MonoBehaviour { //Singleton private static EventManager _instance=null; public static EventManager Instance { get { if(_instance is null) Debug.LogError("Missing EventManager instance"); return _instance; } } [HideInInspector] public bool ready = false; //Wether the ClientManager is initialized [SerializeField] float SpawnRange = 1.0f; [SerializeField] int nbMaxEvents = 1; //Maximum active clients [SerializeField] float eventSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) [SerializeField] float maxTimeNewEvents = 2.0f; //Longest waiting time for new clients bool eventSpawnReady = false; [SerializeField] string EventRessourceFolder = "Events"; private Object[] events; GameObject EventContainer=null; List eventIDs = new List(); //Try to find a random point on NavMesh inside a range circle. A result would at a maximum distance of 2*range. bool RandomPoint(Vector3 center, float range, out Vector3 result) { for (int i = 0; i < 50; i++) { Vector3 randomPoint = center + (Vector3)Random.insideUnitCircle * range; NavMeshHit hit; if (NavMesh.SamplePosition(randomPoint, out hit, range, NavMesh.AllAreas)) { result = hit.position; return true; } } result = Vector3.zero; return false; } public void spawnEvent(Vector3 position) { Vector3 spawnPoint; if (eventSpawnReady && eventIDs.Count