TooltipLastterController.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6. public class TooltipLastterController : MonoBehaviour
  7. {
  8. public static TooltipLastterController Instance;
  9. [System.Serializable]
  10. public class Letter
  11. {
  12. public UISprite Sprite;
  13. public UILabel Label;
  14. public bool Find;
  15. public Letter(UISprite sprite, UILabel label, bool find)
  16. {
  17. Sprite = sprite;
  18. Label = label;
  19. Find = find;
  20. }
  21. }
  22. [SerializeField]
  23. public List<Letter> AllLettersForWord;
  24. public GameObject PrefabLeter;
  25. public Transform ParentForLetters;
  26. public ScreenBase ActivateInfoScreen;
  27. public ScreenBase CouponeGetScreen;
  28. public ScreenBase CompliteWordScreen;
  29. public UILabel Label;
  30. public UILabel LabelTextCongratulations;
  31. public ScreenBase LevelInfoScreen;
  32. public string[] WordsGame = new []{"CRISTMAS", "GAME", "COLA"};
  33. public int PontWords;
  34. void Start()
  35. {
  36. PontWords = 0;
  37. Instance = this;
  38. //var r = UnityEngine.Random.Range(0, WordsGame.Count());
  39. //InitWord(WordsGame[1]);
  40. }
  41. public void InitLevelWord()
  42. {
  43. if (spritesForClear != null)
  44. {
  45. Destroy(spritesForClear.gameObject);
  46. }
  47. foreach (var let in AllLettersForWord)
  48. {
  49. Destroy(let.Sprite.gameObject);
  50. }
  51. AllLettersForWord.Clear();
  52. switch(PlayerPrefs.GetInt("Level"))
  53. {
  54. case 1:
  55. InitWord(WordsGame[0]);
  56. break;
  57. case 2:
  58. InitWord(WordsGame[1]);
  59. Active = true;
  60. break;
  61. case 3:
  62. InitWord(WordsGame[2]);
  63. Active = true;
  64. break;
  65. }
  66. WordDone = false;
  67. //Active = true;
  68. }
  69. public bool WordDone;
  70. public void UpdateLattersinInfo(string charater)
  71. {
  72. Active = true;
  73. foreach (var ch in AllLettersForWord)
  74. {
  75. if (!ch.Find)
  76. {
  77. if (charater == ch.Label.text)
  78. {
  79. ch.Find = true;
  80. ch.Label.color = Color.red;
  81. break;
  82. }
  83. }
  84. }
  85. bool couponeGet = true;
  86. for (int i = 0; i < AllLettersForWord.Count; i++)
  87. {
  88. if (!AllLettersForWord[i].Find)
  89. {
  90. couponeGet = false;
  91. }
  92. }
  93. if (couponeGet)
  94. {
  95. //PlayerPrefs.SetInt("GetCoupon", 1);
  96. WordDone = true;
  97. Active = true;
  98. //TODO :GetCoupone
  99. }
  100. }
  101. public UISprite spritesForClear;
  102. private void InitWord(string word)
  103. {
  104. ParentForLetters.localPosition = new Vector2(0, ParentForLetters.localPosition.y);
  105. char[] charArray = word.ToCharArray();
  106. var c = charArray.Count()/2;
  107. PrefabLeter.gameObject.SetActive(true);
  108. for (int i = 0; i < charArray.Count(); i++)
  109. {
  110. if (charArray[i].ToString() == "-")
  111. {
  112. var go = (GameObject)Instantiate(PrefabLeter);
  113. go.transform.SetParent(ParentForLetters);
  114. go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
  115. go.transform.localScale = PrefabLeter.transform.localScale;
  116. var scriptUISprite = go.GetComponent<UISprite>();
  117. spritesForClear = scriptUISprite;
  118. var scriptUILabel = go.GetComponentInChildren<UILabel>();
  119. scriptUILabel.text = charArray[i].ToString();
  120. //var leter = new Letter(scriptUISprite, scriptUILabel, false);
  121. //AllLettersForWord.Add(leter);
  122. }
  123. else
  124. {
  125. var go = (GameObject)Instantiate(PrefabLeter);
  126. go.transform.SetParent(ParentForLetters);
  127. go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
  128. go.transform.localScale = PrefabLeter.transform.localScale;
  129. var scriptUISprite = go.GetComponent<UISprite>();
  130. var scriptUILabel = go.GetComponentInChildren<UILabel>();
  131. scriptUILabel.text = charArray[i].ToString();
  132. var leter = new Letter(scriptUISprite, scriptUILabel, false);
  133. AllLettersForWord.Add(leter);
  134. }
  135. }
  136. ParentForLetters.localPosition = new Vector2(ParentForLetters.localPosition.x -c*25, ParentForLetters.localPosition.y);
  137. PrefabLeter.gameObject.SetActive(false);
  138. timerShow = defoultTimer;
  139. }
  140. private bool show;
  141. public float timerShow;
  142. private float defoultTimer = 5;
  143. public bool Active;
  144. void Update()
  145. {
  146. if (Active)
  147. {
  148. if (WordDone)
  149. {
  150. PontWords = PontWords + 1000;
  151. CompliteWordScreen.Show();
  152. }
  153. else
  154. {
  155. //Debug.Log("ActivateInfoScreen.Show()");
  156. ActivateInfoScreen.Show();
  157. }
  158. show = true;
  159. Active = false;
  160. }
  161. if (show)
  162. {
  163. timerShow -= Time.deltaTime;
  164. if (timerShow <= 0)
  165. {
  166. timerShow = defoultTimer;
  167. show = false;
  168. if (WordDone)
  169. {
  170. CompliteWordScreen.Hide();
  171. }
  172. else
  173. {
  174. ActivateInfoScreen.Hide();
  175. }
  176. }
  177. }
  178. }
  179. public string GetNextLetter()
  180. {
  181. for (int i = 0; i < AllLettersForWord.Count; i++)
  182. {
  183. if (!AllLettersForWord[i].Find)
  184. {
  185. return AllLettersForWord[i].Label.text;
  186. }
  187. }
  188. return "";
  189. }
  190. //public IEnumerator LevelNotificaion()
  191. //{
  192. // Debug.LogWarning("LevelNotificaion");
  193. // LevelInfoScreen.Show();
  194. // yield return new WaitForSeconds(5);
  195. // LevelInfoScreen.Hide();
  196. //}
  197. public void LevelNotificaion(int getInt)
  198. {
  199. if (getInt == 3)
  200. {
  201. Label.text = string.Format("Tillykke!\n Du har bestået spillet!");
  202. //LabelTextCongratulations.text = "Grattis – du har klarat spelet!";
  203. }
  204. else
  205. {
  206. Label.text = string.Format("Du har gennemført Level {0}.", getInt);
  207. LabelTextCongratulations.text = "Tillykke!";
  208. }
  209. InGameScriptCS.Instance.bGamePaused = true;
  210. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone",true);
  211. //LoginManager.Instance.OnClickOkLevelDone();
  212. LevelInfoScreen.Show();
  213. }
  214. public void NotificaionHide()
  215. {
  216. LevelInfoScreen.Hide();
  217. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone", false);
  218. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("Run", false);
  219. }
  220. }