FBDirectoryReceiveCallbackAndroid.cs 931 B

123456789101112131415161718192021222324252627282930313233343536
  1. #if !UNITY_EDITOR && UNITY_ANDROID
  2. using UnityEngine;
  3. namespace SimpleFileBrowser
  4. {
  5. public class FBDirectoryReceiveCallbackAndroid : AndroidJavaProxy
  6. {
  7. private readonly FileBrowser.DirectoryPickCallback callback;
  8. private readonly FBCallbackHelper callbackHelper;
  9. public FBDirectoryReceiveCallbackAndroid( FileBrowser.DirectoryPickCallback callback ) : base( "com.yasirkula.unity.FileBrowserDirectoryReceiver" )
  10. {
  11. this.callback = callback;
  12. callbackHelper = new GameObject( "FBCallbackHelper" ).AddComponent<FBCallbackHelper>();
  13. }
  14. public void OnDirectoryPicked( string rawUri, string name )
  15. {
  16. callbackHelper.CallOnMainThread( () => DirectoryPickedCallback( rawUri, name ) );
  17. }
  18. private void DirectoryPickedCallback( string rawUri, string name )
  19. {
  20. try
  21. {
  22. if( callback != null )
  23. callback( rawUri, name );
  24. }
  25. finally
  26. {
  27. Object.Destroy( callbackHelper );
  28. }
  29. }
  30. }
  31. }
  32. #endif