using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Android;
using XRTool.Util;
namespace XRTool.Util
{
///
/// 安卓与Unity接口类交互
///
public class AndroidLib : UnitySingleton
{
private static AndroidJavaObject currentActivity;
///
/// 安卓的Activity
///
public static AndroidJavaObject MainActivity
{
get
{
#if UNITY_ANDROID
if (currentActivity == null)
{
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
currentActivity = up.GetStatic("currentActivity");
}
#endif
return currentActivity;
}
}
protected override void Awake()
{
name = typeof(AndroidLib).Name;
base.Awake();
DontDestroyOnLoad(gameObject);
}
///
/// 安卓回调接口,安卓调用Unity
/// 统一接口?
///
///
public void AndroidCallBack(string funName)
{
}
///
/// 调用安卓代码
///
public static T CallAndLibMethod(AndroidJavaObject andObj, bool isStatic, string meshod, params object[] args)
{
if (andObj != null)
{
if (isStatic)
{
return andObj.CallStatic(meshod, args);
}
return andObj.Call(meshod, args);
}
return default(T);
}
///
/// 调用安卓代码
///
public static T CallAndLibMethod(AndroidJavaObject andObj, bool isStatic, string meshod)
{
if (andObj != null)
{
if (isStatic)
{
return andObj.CallStatic(meshod);
}
return andObj.Call(meshod);
}
return default(T);
}
///
/// 调用安卓代码
///
public static void CallAndLibMethod(AndroidJavaObject andObj, bool isStatic, string meshod, params object[] args)
{
if (andObj != null)
{
if (isStatic)
{
andObj.CallStatic(meshod, args);
}
else
{
andObj.Call(meshod, args);
}
}
}
public static bool CheckCamera()
{
if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
{
Permission.RequestUserPermission(Permission.Camera);
return false;
}
return true;
}
///
/// 调用安卓代码
///
public static void CallAndLibMethod(AndroidJavaObject andObj, bool isStatic, string meshod)
{
if (andObj != null)
{
if (isStatic)
{
andObj.CallStatic(meshod);
}
else
{
andObj.Call(meshod);
}
}
}
///
/// 调用安卓代码
///
public static T CallAndLibMethod(bool isStatic, string meshod, params object[] args)
{
return CallAndLibMethod(MainActivity,isStatic, meshod, args);
}
///
/// 调用安卓代码
///
public static T CallAndLibMethod( bool isStatic, string meshod)
{
return CallAndLibMethod(MainActivity, isStatic, meshod);
}
///
/// 调用安卓代码
///
public static void CallAndLibMethod(bool isStatic, string meshod, params object[] args)
{
CallAndLibMethod(MainActivity, isStatic, meshod, args);
}
///
/// 调用安卓代码
///
public static void CallAndLibMethod(bool isStatic, string meshod)
{
CallAndLibMethod(MainActivity, isStatic, meshod);
}
}
}