добавил немного функционала
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameSystem : MonoBehaviour
|
||||
{
|
||||
public static GameSystem Instance { get; private set; }
|
||||
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
|
||||
|
||||
public void AddGameComponent(IGameComponent component)
|
||||
{
|
||||
if(!gameComponents.Contains(component))
|
||||
gameComponents.Add(component);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
GameSystem[] gameSystems = FindObjectsOfType<GameSystem>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user