Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using GameCore;
- using UnityEngine;
- public class UpdatebleManager : MonoBehaviour
- {
- private static UpdatebleManager _instance = null;
- public static UpdatebleManager Instance => _instance ?? (_instance = FindObjectOfType<UpdatebleManager>());
- private IUpdateble[] _updatables = new IUpdateble[0];
- public void Add(IUpdateble updatable)
- {
- if (!_updatables.Contains(updatable))
- {
- _updatables = _updatables.Append(updatable).ToArray();
- }
- }
- public void Remove(IUpdateble updatable)
- {
- if (_updatables.Contains(updatable))
- {
- List<IUpdateble> list = _updatables.ToList();
- list.Remove(updatable);
- _updatables = list.ToArray();
- }
- }
- private void Update()
- {
- int length = _updatables.Length;
- for (int i = 0; i < length; i++)
- _updatables[i].OnUpdate();
- }
- [ContextMenu("LogUpdatebles")]
- void LogUpdatebles()
- {
- _updatables.Log();
- }
- }
Add Comment
Please, Sign In to add comment