mergemilitary/Assets/Scripts/Core/NativeTool.cs

77 lines
2.0 KiB
C#
Raw Normal View History

2022-05-23 13:39:59 +00:00
using System.Runtime.CompilerServices;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
using AOT;
public static class NativeTool
{
private static Action<bool> mShareResultDel;
public static void Shake(int pType, float pIntensity)//0 light,1 medium,2 heavy
{
#if UNITY_EDITOR
//Debug.Log($"Shake {pType} with intensity {pIntensity}");
#elif UNITY_IOS
mShake(pType, pIntensity);
#elif UNITY_ANDROID
2022-06-13 07:55:30 +00:00
//mShake(pType * pType * 20 + (int)(pIntensity * (pType + 1) * 10));
TKGSDKManager.Instance.Shake(pType, pIntensity);
2022-05-23 13:39:59 +00:00
#endif
}
public static void Share(string pTitle, string pUrl, Action<bool> pResultDel)
{
mShareResultDel = pResultDel;
#if UNITY_EDITOR
mShareResultDel?.Invoke(true);
#elif UNITY_IOS
mShare(pTitle, pUrl, onShareCallback);
#elif UNITY_ANDROID
2022-06-13 07:55:30 +00:00
//mShare(pTitle, pUrl);
2022-05-23 13:39:59 +00:00
#endif
}
#if UNITY_IOS
[DllImport("__Internal")]
private static extern void mShake(int pType, float pIntensity);
[DllImport("__Internal")]
private static extern void mShare(string pTitle, string pUrl, BoolResultDelegate pResultCallback);
internal delegate void BoolResultDelegate(bool pResult);
[MonoPInvokeCallback(typeof(BoolResultDelegate))]
private static void onShareCallback(bool pResult)
{
mShareResultDel?.Invoke(pResult);
}
#endif
#if UNITY_ANDROID
2022-06-13 07:55:30 +00:00
//private static AndroidJavaClass javaObj = new AndroidJavaClass("com.toukagames.NativeTool");
//private static AndroidJavaObject mInstance = null;
2022-05-23 13:39:59 +00:00
2022-06-13 07:55:30 +00:00
//private static void mShake(long mMilliSeconds)
//{
// if (mInstance == null)
// mInstance = javaObj.CallStatic<AndroidJavaObject>("GetInstance");
2022-05-23 13:39:59 +00:00
2022-06-13 07:55:30 +00:00
// mInstance.Call("Shake", mMilliSeconds);
//}
2022-05-23 13:39:59 +00:00
2022-06-13 07:55:30 +00:00
//private static void mShare(string pTitle, string pUrl)
//{
// if (mInstance == null)
// mInstance = javaObj.CallStatic<AndroidJavaObject>("GetInstance");
2022-05-23 13:39:59 +00:00
2022-06-13 07:55:30 +00:00
// mInstance.Call("Share", pUrl);
// mShareResultDel?.Invoke(true);
//}
2022-05-23 13:39:59 +00:00
#endif
}