CommandInvoker.cs 649 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace KairoEngine.Core
  5. {
  6. public class CommandInvoker : MonoBehaviour
  7. {
  8. static Queue<ICommand> commandBuffer;
  9. private void Awake()
  10. {
  11. commandBuffer = new Queue<ICommand>();
  12. }
  13. public static void AddCommand(ICommand command)
  14. {
  15. commandBuffer.Enqueue(command);
  16. }
  17. void Update()
  18. {
  19. while(commandBuffer.Count > 0)
  20. {
  21. ICommand command = commandBuffer.Dequeue();
  22. command.Execute();
  23. }
  24. }
  25. }
  26. }