MainThreadQueue.cs 764 B

12345678910111213141516171819202122232425262728
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using FfalconXR;
  5. //用于处理Native回调结果并非在主线程执行会引起的问题
  6. public class MainThreadQueue : MonoSingleton<MainThreadQueue>
  7. {
  8. public Queue<Action> ExecuteQueue = new Queue<Action>();
  9. private Action CurrentAction;
  10. private void Update()
  11. {
  12. try
  13. {
  14. while (ExecuteQueue.Count > 0)
  15. {
  16. //主线程队列执行
  17. CurrentAction = ExecuteQueue.Dequeue();
  18. CurrentAction.Invoke();
  19. }
  20. }
  21. catch (Exception e)
  22. {
  23. Debug.LogError("[MercuryX2]:MethodName:" + CurrentAction.Method.Name + "MainThreadQueue error:" + e);
  24. }
  25. }
  26. }