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

38 lines
604 B
C#
Raw Normal View History

2024-12-13 09:59:41 +08:00
#if UNITY_EDITOR || UNITY_ANDROID
using UnityEngine;
namespace NativeGalleryNamespace
{
public class NGCallbackHelper : MonoBehaviour
{
private System.Action mainThreadAction = null;
private void Awake()
{
DontDestroyOnLoad( gameObject );
}
private void Update()
{
if( mainThreadAction != null )
{
try
{
System.Action temp = mainThreadAction;
mainThreadAction = null;
temp();
}
finally
{
Destroy( gameObject );
}
}
}
public void CallOnMainThread( System.Action function )
{
mainThreadAction = function;
}
}
}
#endif