SCKeyboard2DPrompt.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using LitJson;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SC.XR.Unity.Module_Keyboard
  5. {
  6. public class SCKeyboard2DPrompt : SCKeyboardBasePrompt
  7. {
  8. public int PROMPT_PER_PAGE = 15;
  9. public RectTransform promptInput;
  10. public RectTransform open;
  11. public RectTransform close;
  12. public RectTransform maskRect;
  13. private List<string> m_URLWords;
  14. public List<string> URLWords
  15. {
  16. get
  17. {
  18. if (m_URLWords == null)
  19. {
  20. m_URLWords = new List<string>();
  21. m_URLWords.Add("https://");
  22. m_URLWords.Add("http://");
  23. m_URLWords.Add("www.");
  24. m_URLWords.Add(".cn");
  25. }
  26. return m_URLWords;
  27. }
  28. }
  29. public bool isOpen
  30. {
  31. get
  32. {
  33. return close.gameObject.activeSelf;
  34. }
  35. set
  36. {
  37. open.gameObject.SetActive(!value);
  38. close.gameObject.SetActive(value);
  39. }
  40. }
  41. public override int GetChinese(string englishWords)
  42. {
  43. wordCount = ChineseIMEManager.Instance.GetWordCount(englishWords);
  44. return wordCount;
  45. }
  46. public override string GetChinese(int index)
  47. {
  48. return ChineseIMEManager.Instance.GetWord(index);
  49. }
  50. public override void SetEnteredText(string textStr)
  51. {
  52. maskRect.gameObject.SetActive(textStr == "" ? false : true);
  53. alreadyInput.alignment = TextAnchor.MiddleCenter;
  54. alreadyInput.text = textStr;
  55. if ((KeyboardUtils.CaculateTextLength(textStr, alreadyInput) * 0.1) > maskRect.sizeDelta.x) { alreadyInput.alignment = TextAnchor.MiddleRight; }
  56. }
  57. }
  58. }