123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 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<AndroidJavaObject>("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<AndroidJavaObject>("getApplicationContext");
- }
- }
- return mContext;
- }
- }
- public static T CurrentActivityFunctionCall<T>(string callName, params object[] args)
- {
- if (CurrentActivity != null)
- {
- try
- {
- return CurrentActivity.Call<T>(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);
- }
- }
|