398 lines
12 KiB
C#
398 lines
12 KiB
C#
using UnityEngine;
|
||
using System.Collections;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
|
||
#if UNITY_ANDROID
|
||
namespace Thousandto.CoreSDK
|
||
{
|
||
public class FuncellSDKAndroid : FuncellSDK
|
||
{
|
||
private const string JAVA_CLASS = "com.unity3d.player.UnityPlayer";
|
||
private const string JAVA_CLASS_MAIN = "com.thousandto.tzj.UnityPlayerActivity";
|
||
private const string JAVA_CLASS_PLUGIN_UTILS_CAMERA = "com.thousandto.plugin.camera.ClipImg";
|
||
//刘海屏适配
|
||
private const string JAVA_CLASS_NOTCHIN_SCREEN = "com.qxkj.plugins.NotchInScreen";
|
||
//SDK相关的扩展函数
|
||
private const string JAVA_CLASS_SDKEXPAND = "com.qxkj.sdk.SDKExpand";
|
||
|
||
private AndroidJavaClass _javaClass = null;
|
||
private AndroidJavaObject _context;
|
||
//Android那边找不到的函数列表
|
||
private List<string> _notExistFuncList = new List<string>();
|
||
//已经调用过的函数
|
||
private List<string> _calledFuncList = new List<string>();
|
||
|
||
public FuncellSDKAndroid()
|
||
{
|
||
try
|
||
{
|
||
_javaClass = new AndroidJavaClass(JAVA_CLASS);
|
||
_context = _javaClass.GetStatic<AndroidJavaObject>("currentActivity");
|
||
UseSDK = _context.Call<bool>("UseSDK");
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
}
|
||
|
||
///有时候还没有加载SDK模块,android端的sdk就初始化完成了,这个时候需要主动获取
|
||
///SDK状态,避免每次进游戏不能正确判断,导致触发重新初始化sdk
|
||
try
|
||
{
|
||
SDKInitFinish = _context.Call<bool>("IsSDKInitFinish");
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前网络类型
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public override string GetNetworkType()
|
||
{
|
||
string netWorkType = "";
|
||
try
|
||
{
|
||
netWorkType = _context.Call<string>("GetNetworkType");
|
||
Debug.Log("当前网络类型:" + netWorkType);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
}
|
||
return netWorkType;
|
||
}
|
||
|
||
public override bool IsEmulator()
|
||
{
|
||
bool isEmulator = false;
|
||
try
|
||
{
|
||
isEmulator = _context.Call<bool>("IsEmulator");
|
||
Debug.Log("是否是模拟器:" + isEmulator);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
}
|
||
return isEmulator;
|
||
}
|
||
|
||
public override bool IsRealNameAuthorized()
|
||
{
|
||
bool isRealNameAuthorized = false;
|
||
try
|
||
{
|
||
isRealNameAuthorized = _context.Call<bool>("IsRealNameAuthorized");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
}
|
||
return isRealNameAuthorized;
|
||
}
|
||
|
||
public override void DoRealNameAuthority(string name, string idcard)
|
||
{
|
||
var funcName = "DoRealNameAuthority";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_MAIN))
|
||
{
|
||
javaClass.CallStatic(funcName, name, idcard);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
private void CallJni(string funcName, string type, params string[] args)
|
||
{
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
if (_calledFuncList.IndexOf(funcName) != -1)
|
||
{
|
||
_calledFuncList.Add(funcName);
|
||
UnityEngine.Debug.Log(string.Format("CallJni funcName = {0}, type = {1}, args length = {2}", funcName, type, args.Length));
|
||
}
|
||
_context.Call(funcName, type, args);
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
private void CallJni(string funcName)
|
||
{
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
if (_calledFuncList.IndexOf(funcName) != -1)
|
||
{
|
||
_calledFuncList.Add(funcName);
|
||
UnityEngine.Debug.Log(string.Format("CallJni funcName = {0}", funcName));
|
||
}
|
||
_context.Call(funcName);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
private void CallJniWithParam(string funcName, params string[] args)
|
||
{
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
_context.Call(funcName, args);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
private void CallJniWithParam(string className, string funcName, params object[] args)
|
||
{
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(className))
|
||
{
|
||
javaClass.CallStatic(funcName, args);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
protected override void CallFunc(RequestOptType funcType, params string[] args)
|
||
{
|
||
if (_javaClass == null)
|
||
return;
|
||
|
||
CallJni("ClientToSDK", funcType.ToString(), args);
|
||
}
|
||
|
||
public override void ReInitSDK()
|
||
{
|
||
if (_javaClass == null)
|
||
return;
|
||
CallJni("ReInitSDK");
|
||
}
|
||
|
||
//判断是否后台音乐在播放
|
||
public override bool IsMusicPlaying()
|
||
{
|
||
var funcName = "IsMusicPlaying";
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return false;
|
||
|
||
bool isPlaying = false;
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_MAIN))
|
||
{
|
||
isPlaying = javaClass.CallStatic<bool>(funcName, _context);
|
||
}
|
||
}
|
||
catch(Exception)
|
||
{
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
|
||
return isPlaying;
|
||
}
|
||
|
||
public override void CopyToClipboard(string text)
|
||
{
|
||
var funcName = "CopyToClipboard";
|
||
if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_MAIN))
|
||
{
|
||
javaClass.CallStatic(funcName, _context, text);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
public override void GetPhoto(int type, string path, int width, int height)
|
||
{
|
||
var funcName = "showChoiceDialog";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_PLUGIN_UTILS_CAMERA))
|
||
{
|
||
//showChoiceDialog(String dir, int x, int y, String aresType, int _compressQuality, boolean _showCamera)
|
||
javaClass.CallStatic(funcName, type, path, width, height, "", 100, true);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
//判断是否是全面屏手机
|
||
public override bool HasNotchInScreen()
|
||
{
|
||
var funcName = "HasNotchInScreen";
|
||
//if (!UseSDK || _notExistFuncList.IndexOf(funcName) != -1)
|
||
// return false;
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return false;
|
||
|
||
bool hasNotchInScreen = false;
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_NOTCHIN_SCREEN))
|
||
{
|
||
hasNotchInScreen = javaClass.CallStatic<bool>(funcName);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
|
||
return hasNotchInScreen;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重启游戏
|
||
/// </summary>
|
||
public override void ReStartGame()
|
||
{
|
||
var funcName = "RestartApp";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_MAIN))
|
||
{
|
||
javaClass.CallStatic(funcName);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 调用分享
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
public override void DoShare(string url)
|
||
{
|
||
var funcName = "DoFaceBookShare";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_SDKEXPAND))
|
||
{
|
||
javaClass.CallStatic(funcName, url);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 调用评分
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
public override void DoRate(string url)
|
||
{
|
||
var funcName = "DoRate";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_SDKEXPAND))
|
||
{
|
||
javaClass.CallStatic(funcName);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取广告ID
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public override string GetADID()
|
||
{
|
||
string gaid = "";
|
||
var funcName = "GetGAID";
|
||
if (_notExistFuncList.IndexOf(funcName) != -1)
|
||
return gaid;
|
||
|
||
try
|
||
{
|
||
using (var javaClass = new AndroidJavaClass(JAVA_CLASS_SDKEXPAND))
|
||
{
|
||
gaid = javaClass.CallStatic<string>(funcName);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
_notExistFuncList.Add(funcName);
|
||
}
|
||
return gaid;
|
||
}
|
||
}
|
||
}
|
||
#endif |