ChineseIMEManager.cs 945 B

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