using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using static TestFile; public class UnityToJava { private static AndroidJavaClass _yiYanClass; private static AndroidJavaClass _jumpAPPClass; private static AndroidJavaClass _SpeekClass; private static AndroidJavaClass _DuerBaseClass; private static AndroidJavaObject mCurrentActivity = null; private static AndroidJavaClass mUnityPlayerClass = null; private static AndroidJavaObject mContext = null; public static AndroidJavaObject CurrentActivity { get { if (Application.platform == RuntimePlatform.Android) { if (mCurrentActivity == null && UnityPlayerClass != null) { mCurrentActivity = UnityPlayerClass.GetStatic("currentActivity"); } } return mCurrentActivity; } } public static AndroidJavaClass UnityPlayerClass { get { if (Application.platform == RuntimePlatform.Android) { if (mUnityPlayerClass == null) { mUnityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); } } return mUnityPlayerClass; } } public static AndroidJavaObject Context { get { if (Application.platform == RuntimePlatform.Android) { if (mContext == null) { mContext = CurrentActivityFunctionCall("getApplicationContext"); } } return mContext; } } public static T CurrentActivityFunctionCall(string callName, params object[] args) { if (CurrentActivity != null) { try { return CurrentActivity.Call(callName, args); } catch (Exception e) { Debug.LogError(e); } } return default(T); } private static AndroidJavaClass jumpAPPClass { get { if (_jumpAPPClass == null) { _jumpAPPClass = new AndroidJavaClass("com.tools.AppLock.AppLock"); } return _jumpAPPClass; } } public static AndroidJavaClass yiYanClass { get { if (_yiYanClass == null) { _yiYanClass = new AndroidJavaClass("com.xiaodu.dueros.magictool.demo.YiyanDemoActivity"); } return _yiYanClass; } } private static AndroidJavaClass SpeekClass { get { if (_SpeekClass == null) { _SpeekClass = new AndroidJavaClass("com.example.speekaar.SpeekManager"); } return _SpeekClass; } } public static void startSpeekText(string str) { Debug.Log("startSpeekText==>"); SpeekClass.CallStatic("startSpeekText",str); } public static void startWebSocketSpeek() { Debug.Log("startWebSocketSpeek==>"); SpeekClass.CallStatic("startWebSocketSpeek"); } public static void stopSpeek() { Debug.Log("stopSpeek==>"); SpeekClass.CallStatic("stopSpeek"); } public static void initSpeek(YiYanBack fh) { yiYanClass.CallStatic("init", Context); yiYanClass.CallStatic("SetUnityHandler", fh); } public static void SpeekOffString(string str) { yiYanClass.Call("SpeekOffString", str); } }