GameKey3Dboard.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GameKey3Dboard : MonoBehaviour {
  5. public GameObject keyboard_num;
  6. public GameObject keyboard_symbol;
  7. public GameObject keyboard_enUp;
  8. public GameObject keyboard_enLow;
  9. private Game3DInputField input;
  10. private List<string> str;
  11. // Use this for initialization
  12. void Awake()
  13. {
  14. str = new List<string>();
  15. InitTween();
  16. }
  17. public void show(Game3DInputField input, string value)
  18. {
  19. this.input = input;
  20. str = new List<string>();
  21. if (value != null)
  22. {
  23. for (int i = 0; i < value.Length; i++)
  24. {
  25. str.Add(value[i].ToString());
  26. }
  27. }
  28. gameObject.SetActive(true);
  29. showEnLow();
  30. Begin();
  31. }
  32. public void onClick(string value)
  33. {
  34. if(str.Count >= input.maxLength)
  35. {
  36. return;
  37. }
  38. str.Add(value);
  39. setTextString();
  40. }
  41. public void clear()
  42. {
  43. str = new List<string>();
  44. setTextString();
  45. }
  46. public void done()
  47. {
  48. str = new List<string>();
  49. gameObject.SetActive(false);
  50. }
  51. public void del()
  52. {
  53. if (str.Count > 0)
  54. {
  55. str.RemoveAt(str.Count - 1);
  56. setTextString();
  57. }
  58. }
  59. public void showNum()
  60. {
  61. keyboard_num.SetActive(true);
  62. keyboard_symbol.SetActive(false);
  63. keyboard_enUp.SetActive(false);
  64. keyboard_enLow.SetActive(false);
  65. }
  66. public void showSymbol()
  67. {
  68. keyboard_num.SetActive(false);
  69. keyboard_symbol.SetActive(true);
  70. keyboard_enUp.SetActive(false);
  71. keyboard_enLow.SetActive(false);
  72. }
  73. public void showEnUp()
  74. {
  75. keyboard_num.SetActive(false);
  76. keyboard_symbol.SetActive(false);
  77. keyboard_enUp.SetActive(true);
  78. keyboard_enLow.SetActive(false);
  79. }
  80. public void showEnLow()
  81. {
  82. keyboard_num.SetActive(false);
  83. keyboard_symbol.SetActive(false);
  84. keyboard_enUp.SetActive(false);
  85. keyboard_enLow.SetActive(true);
  86. }
  87. private void setTextString()
  88. {
  89. string text = "";
  90. for (int i = 0, l = str.Count; i < l; i++)
  91. {
  92. text += str[i];
  93. }
  94. input.text = text;
  95. }
  96. private void InitTween()
  97. {
  98. TweenBase[] tb = GetComponentsInChildren<TweenBase>();
  99. for (int i = 0; i < tb.Length; i++)
  100. {
  101. mlist.Add(tb[i]);
  102. }
  103. }
  104. private List<TweenBase> mlist = new List<TweenBase>();
  105. private void Begin()
  106. {
  107. if (!this.gameObject.activeInHierarchy)
  108. {
  109. return;
  110. }
  111. for (int i = 0; i < mlist.Count; i++)
  112. {
  113. mlist[i].Init();
  114. if (mlist[i].delaytime > 0)
  115. {
  116. StartCoroutine(DelayStart(mlist[i].delaytime, mlist[i]));
  117. }
  118. else
  119. {
  120. mlist[i].StartAction();
  121. }
  122. }
  123. }
  124. IEnumerator DelayStart(float time, TweenBase tb)
  125. {
  126. yield return new WaitForSeconds(time);
  127. tb.StartAction();
  128. }
  129. }