TooltipLastterController.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 bool WordFinish;
  71. public void UpdateLattersinInfo(string charater)
  72. {
  73. Active = true;
  74. foreach (var ch in AllLettersForWord)
  75. {
  76. if (!ch.Find)
  77. {
  78. if (charater == ch.Label.text)
  79. {
  80. ch.Find = true;
  81. ch.Label.color = Color.red;
  82. break;
  83. }
  84. }
  85. }
  86. bool couponeGet = true;
  87. for (int i = 0; i < AllLettersForWord.Count; i++)
  88. {
  89. if (!AllLettersForWord[i].Find)
  90. {
  91. couponeGet = false;
  92. }
  93. }
  94. if (couponeGet)
  95. {
  96. //PlayerPrefs.SetInt("GetCoupon", 1);
  97. WordDone = true;
  98. WordFinish = false;
  99. Active = true;
  100. //TODO :GetCoupone
  101. }
  102. }
  103. public UISprite spritesForClear;
  104. private void InitWord(string word)
  105. {
  106. ParentForLetters.localPosition = new Vector2(0, ParentForLetters.localPosition.y);
  107. char[] charArray = word.ToCharArray();
  108. var c = charArray.Count()/2;
  109. PrefabLeter.gameObject.SetActive(true);
  110. for (int i = 0; i < charArray.Count(); i++)
  111. {
  112. if (charArray[i].ToString() == "-")
  113. {
  114. var go = (GameObject)Instantiate(PrefabLeter);
  115. go.transform.SetParent(ParentForLetters);
  116. go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
  117. go.transform.localScale = PrefabLeter.transform.localScale;
  118. var scriptUISprite = go.GetComponent<UISprite>();
  119. spritesForClear = scriptUISprite;
  120. var scriptUILabel = go.GetComponentInChildren<UILabel>();
  121. scriptUILabel.text = charArray[i].ToString();
  122. //var leter = new Letter(scriptUISprite, scriptUILabel, false);
  123. //AllLettersForWord.Add(leter);
  124. }
  125. else
  126. {
  127. var go = (GameObject)Instantiate(PrefabLeter);
  128. go.transform.SetParent(ParentForLetters);
  129. go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
  130. go.transform.localScale = PrefabLeter.transform.localScale;
  131. var scriptUISprite = go.GetComponent<UISprite>();
  132. var scriptUILabel = go.GetComponentInChildren<UILabel>();
  133. scriptUILabel.text = charArray[i].ToString();
  134. var leter = new Letter(scriptUISprite, scriptUILabel, false);
  135. AllLettersForWord.Add(leter);
  136. }
  137. }
  138. ParentForLetters.localPosition = new Vector2(ParentForLetters.localPosition.x -c*25, ParentForLetters.localPosition.y);
  139. PrefabLeter.gameObject.SetActive(false);
  140. timerShow = defoultTimer;
  141. }
  142. private bool show;
  143. public float timerShow;
  144. private float defoultTimer = 5;
  145. public bool Active;
  146. void Update()
  147. {
  148. if (Active)
  149. {
  150. if (WordDone)
  151. {
  152. PontWords = PontWords + 1000;
  153. CompliteWordScreen.Show();
  154. }
  155. else
  156. {
  157. //Debug.Log("ActivateInfoScreen.Show()");
  158. ActivateInfoScreen.Show();
  159. }
  160. show = true;
  161. Active = false;
  162. }
  163. if (show)
  164. {
  165. timerShow -= Time.deltaTime;
  166. if (timerShow <= 0)
  167. {
  168. timerShow = defoultTimer;
  169. show = false;
  170. if (WordDone)
  171. {
  172. CompliteWordScreen.Hide();
  173. }
  174. else
  175. {
  176. ActivateInfoScreen.Hide();
  177. }
  178. }
  179. }
  180. }
  181. public string GetNextLetter()
  182. {
  183. for (int i = 0; i < AllLettersForWord.Count; i++)
  184. {
  185. if (!AllLettersForWord[i].Find)
  186. {
  187. return AllLettersForWord[i].Label.text;
  188. }
  189. }
  190. return "";
  191. }
  192. //public IEnumerator LevelNotificaion()
  193. //{
  194. // Debug.LogWarning("LevelNotificaion");
  195. // LevelInfoScreen.Show();
  196. // yield return new WaitForSeconds(5);
  197. // LevelInfoScreen.Hide();
  198. //}
  199. public void LevelNotificaion(int getInt)
  200. {
  201. if (getInt == 2)
  202. {
  203. Label.text = string.Format("Til hamingju!");
  204. //LabelTextCongratulations.text = "Grattis – du har klarat spelet!";
  205. }
  206. else
  207. {
  208. Label.text = string.Format("Þú hefur lokið fyrsta borði leiksins!", getInt);
  209. LabelTextCongratulations.text = "Til hamingju";
  210. }
  211. // InGameScriptCS.Instance.bGamePaused = true;
  212. ControllerScriptCS.Instance.LostLife = true;
  213. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone",true);
  214. //LoginManager.Instance.OnClickOkLevelDone();
  215. LevelInfoScreen.Show();
  216. }
  217. public void NotificaionHide()
  218. {
  219. LevelInfoScreen.Hide();
  220. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone", false);
  221. PlayerController.Instance.transform.GetComponent<Animator>().SetBool("Run", false);
  222. }
  223. }