_TheStrongestSnail/TheStrongestSnail/Assets/Plugins/NativeGallery/Android/NGPermissionCallbackAndroid.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2024-12-13 09:59:41 +08:00
#if UNITY_EDITOR || UNITY_ANDROID
using System.Threading;
using UnityEngine;
namespace NativeGalleryNamespace
{
public class NGPermissionCallbackAndroid : AndroidJavaProxy
{
private object threadLock;
public int Result { get; private set; }
public NGPermissionCallbackAndroid( object threadLock ) : base( "com.yasirkula.unity.NativeGalleryPermissionReceiver" )
{
Result = -1;
this.threadLock = threadLock;
}
[UnityEngine.Scripting.Preserve]
public void OnPermissionResult( int result )
{
Result = result;
lock( threadLock )
{
Monitor.Pulse( threadLock );
}
}
}
public class NGPermissionCallbackAsyncAndroid : AndroidJavaProxy
{
private readonly NativeGallery.PermissionCallback callback;
private readonly NGCallbackHelper callbackHelper;
public NGPermissionCallbackAsyncAndroid( NativeGallery.PermissionCallback callback ) : base( "com.yasirkula.unity.NativeGalleryPermissionReceiver" )
{
this.callback = callback;
callbackHelper = new GameObject( "NGCallbackHelper" ).AddComponent<NGCallbackHelper>();
}
[UnityEngine.Scripting.Preserve]
public void OnPermissionResult( int result )
{
callbackHelper.CallOnMainThread( () => callback( (NativeGallery.Permission) result ) );
}
}
}
#endif