ChineseIMEManager.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using SC.XR.Unity;
  2. using UnityEngine;
  3. public class ChineseIMEManager : Singleton<ChineseIMEManager>
  4. {
  5. private AndroidJavaObject unityIME;
  6. public ChineseIMEManager()
  7. {
  8. #if UNITY_EDITOR
  9. #elif UNITY_ANDROID
  10. AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  11. AndroidJavaObject unityActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
  12. unityIME = new AndroidJavaObject("com.invision.pinyinime.UnityIME");
  13. unityIME.Call("OpenIME", unityActivity);
  14. #endif
  15. }
  16. ~ChineseIMEManager()
  17. {
  18. #if UNITY_EDITOR
  19. #elif UNITY_ANDROID
  20. unityIME.Call("CloseIME");
  21. #endif
  22. }
  23. public int GetWordCount(string englishWord)
  24. {
  25. #if UNITY_EDITOR
  26. return 8;
  27. #endif
  28. int wordCount = unityIME.Call<int>("SearchWord", englishWord);
  29. return wordCount;
  30. }
  31. public string GetWord(int i)
  32. {
  33. #if UNITY_EDITOR
  34. return "测试";
  35. #endif
  36. return unityIME.Call<string>("GetWord", i);
  37. }
  38. }