NGCallbackHelper.cs 529 B

12345678910111213141516171819202122232425262728293031
  1. #if UNITY_EDITOR || UNITY_ANDROID
  2. using UnityEngine;
  3. namespace NativeGalleryNamespace
  4. {
  5. public class NGCallbackHelper : MonoBehaviour
  6. {
  7. private System.Action mainThreadAction = null;
  8. private void Awake()
  9. {
  10. DontDestroyOnLoad( gameObject );
  11. }
  12. private void Update()
  13. {
  14. if( mainThreadAction != null )
  15. {
  16. System.Action temp = mainThreadAction;
  17. mainThreadAction = null;
  18. temp();
  19. }
  20. }
  21. public void CallOnMainThread( System.Action function )
  22. {
  23. mainThreadAction = function;
  24. }
  25. }
  26. }
  27. #endif