Pro_Unit

UpdatebleManager

Mar 7th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using GameCore;
  4. using UnityEngine;
  5.  
  6. public class UpdatebleManager : MonoBehaviour
  7. {
  8.  
  9.  
  10.     private static UpdatebleManager _instance = null;
  11.     public static UpdatebleManager Instance => _instance ?? (_instance = FindObjectOfType<UpdatebleManager>());
  12.     private IUpdateble[] _updatables = new IUpdateble[0];
  13.  
  14.     public void Add(IUpdateble updatable)
  15.     {
  16.         if (!_updatables.Contains(updatable))
  17.         {
  18.             _updatables = _updatables.Append(updatable).ToArray();
  19.         }
  20.  
  21.     }
  22.     public void Remove(IUpdateble updatable)
  23.     {
  24.         if (_updatables.Contains(updatable))
  25.         {
  26.             List<IUpdateble> list = _updatables.ToList();
  27.             list.Remove(updatable);
  28.             _updatables = list.ToArray();
  29.         }
  30.     }
  31.  
  32.     private void Update()
  33.     {
  34.         int length = _updatables.Length;
  35.         for (int i = 0; i < length; i++)
  36.             _updatables[i].OnUpdate();
  37.     }
  38.  
  39.     [ContextMenu("LogUpdatebles")]
  40.     void LogUpdatebles()
  41.     {
  42.         _updatables.Log();
  43.     }
  44. }
Add Comment
Please, Sign In to add comment