using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameSystem : MonoBehaviour { public static GameSystem Instance { get; private set; } public List gameComponents { get; private set; } = new List(); public void AddGameComponent(IGameComponent component) { if(!gameComponents.Contains(component)) gameComponents.Add(component); } void Awake() { Instance = this; } void Start() { GameSystem[] gameSystems = FindObjectsOfType(); if(gameSystems.Length > 1) { Destroy(this.gameObject); return; } DontDestroyOnLoad(this); } void Update() { for(int i = 0; i < gameComponents.Count; i++) gameComponents[i].OnUpdate(); } void FixedUpdate() { for(int i = 0; i < gameComponents.Count; i++) gameComponents[i].OnFixedUpdate(); } void LateUpdate() { for(int i = 0; i < gameComponents.Count; i++) gameComponents[i].OnLateUpdate(); } public void RemoveGameComponent(IGameComponent component) { if(gameComponents.Contains(component)) gameComponents.Remove(component); } }