using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; namespace KairoEngine.CharacterSystem { public class CharacterManager : MonoBehaviour { public static CharacterManager instance; public List sceneCharacters = new List(); public List worldCharacterNames = new List(); public List spawnerIds = new List(); void OnEnable() { RegisterEvents.OnRegisterCharacter += RegisterCharacter; } void OnDisable() { RegisterEvents.OnRegisterCharacter += RegisterCharacter; } void Awake() { if(instance == null) instance = this; else Destroy(this.gameObject); } void Update() { for (int i = 0; i < sceneCharacters.Count; i++) { if(sceneCharacters[i] == null) { sceneCharacters.RemoveAt(i); i -= 1; } } } private void RegisterCharacter(CharacterController character) { sceneCharacters.Add(character); if(nameIsRegistered(character.unique_name)) return; worldCharacterNames.Add(character.unique_name); } public static void RegisterSpawner(string id) => instance.spawnerIds.Add(id); public static bool nameIsRegistered(string characterName) { for (int i = 0; i < instance.worldCharacterNames.Count; i++) { if(instance.worldCharacterNames[i] == characterName) return true; } return false; } public static bool spawnerIsRegistered(string id) { for (int i = 0; i < instance.spawnerIds.Count; i++) { if(instance.spawnerIds[i] == id) return true; } return false; } public static void Reset() { instance.sceneCharacters.Clear(); instance.worldCharacterNames.Clear(); instance.spawnerIds.Clear(); } public static CharacterController GetCharacter(string name) { for (int i = 0; i < instance.sceneCharacters.Count; i++) { if(instance.sceneCharacters[i].unique_name == name) return instance.sceneCharacters[i]; } return null; } } }