123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System;
- public class TooltipLastterController : MonoBehaviour
- {
- public static TooltipLastterController Instance;
- [System.Serializable]
- public class Letter
- {
- public UISprite Sprite;
- public UILabel Label;
- public bool Find;
- public Letter(UISprite sprite, UILabel label, bool find)
- {
- Sprite = sprite;
- Label = label;
- Find = find;
- }
- }
- [SerializeField]
- public List<Letter> AllLettersForWord;
- public GameObject PrefabLeter;
- public Transform ParentForLetters;
- public ScreenBase ActivateInfoScreen;
- public ScreenBase CouponeGetScreen;
- public ScreenBase CompliteWordScreen;
- public UILabel Label;
- public UILabel LabelTextCongratulations;
- public ScreenBase LevelInfoScreen;
- public string[] WordsGame = new []{"CRISTMAS", "GAME", "COLA"};
- public int PontWords;
- void Start()
- {
- PontWords = 0;
- Instance = this;
- //var r = UnityEngine.Random.Range(0, WordsGame.Count());
- //InitWord(WordsGame[1]);
- }
- public void InitLevelWord()
- {
- if (spritesForClear != null)
- {
- Destroy(spritesForClear.gameObject);
- }
-
- foreach (var let in AllLettersForWord)
- {
- Destroy(let.Sprite.gameObject);
- }
- AllLettersForWord.Clear();
- switch(PlayerPrefs.GetInt("Level"))
- {
- case 1:
- InitWord(WordsGame[0]);
- break;
- case 2:
- InitWord(WordsGame[1]);
- Active = true;
- break;
- case 3:
- InitWord(WordsGame[2]);
- Active = true;
- break;
- }
- WordDone = false;
-
- //Active = true;
- }
- public bool WordDone;
- public void UpdateLattersinInfo(string charater)
- {
- Active = true;
- foreach (var ch in AllLettersForWord)
- {
- if (!ch.Find)
- {
- if (charater == ch.Label.text)
- {
- ch.Find = true;
- ch.Label.color = Color.red;
-
- break;
- }
- }
- }
- bool couponeGet = true;
- for (int i = 0; i < AllLettersForWord.Count; i++)
- {
- if (!AllLettersForWord[i].Find)
- {
- couponeGet = false;
- }
- }
- if (couponeGet)
- {
- //PlayerPrefs.SetInt("GetCoupon", 1);
-
- WordDone = true;
- Active = true;
- //TODO :GetCoupone
- }
- }
- public UISprite spritesForClear;
- private void InitWord(string word)
- {
- ParentForLetters.localPosition = new Vector2(0, ParentForLetters.localPosition.y);
- char[] charArray = word.ToCharArray();
- var c = charArray.Count()/2;
- PrefabLeter.gameObject.SetActive(true);
- for (int i = 0; i < charArray.Count(); i++)
- {
- if (charArray[i].ToString() == "-")
- {
- var go = (GameObject)Instantiate(PrefabLeter);
- go.transform.SetParent(ParentForLetters);
- go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
- go.transform.localScale = PrefabLeter.transform.localScale;
- var scriptUISprite = go.GetComponent<UISprite>();
- spritesForClear = scriptUISprite;
- var scriptUILabel = go.GetComponentInChildren<UILabel>();
- scriptUILabel.text = charArray[i].ToString();
- //var leter = new Letter(scriptUISprite, scriptUILabel, false);
- //AllLettersForWord.Add(leter);
- }
- else
- {
- var go = (GameObject)Instantiate(PrefabLeter);
- go.transform.SetParent(ParentForLetters);
- go.transform.localPosition = new Vector3(PrefabLeter.transform.localPosition.x + i * 25, PrefabLeter.transform.localPosition.y, 0);
- go.transform.localScale = PrefabLeter.transform.localScale;
- var scriptUISprite = go.GetComponent<UISprite>();
- var scriptUILabel = go.GetComponentInChildren<UILabel>();
- scriptUILabel.text = charArray[i].ToString();
- var leter = new Letter(scriptUISprite, scriptUILabel, false);
- AllLettersForWord.Add(leter);
- }
-
- }
- ParentForLetters.localPosition = new Vector2(ParentForLetters.localPosition.x -c*25, ParentForLetters.localPosition.y);
- PrefabLeter.gameObject.SetActive(false);
- timerShow = defoultTimer;
- }
-
- private bool show;
- public float timerShow;
- private float defoultTimer = 5;
- public bool Active;
- void Update()
- {
- if (Active)
- {
- if (WordDone)
- {
- PontWords = PontWords + 1000;
- CompliteWordScreen.Show();
- }
- else
- {
- //Debug.Log("ActivateInfoScreen.Show()");
- ActivateInfoScreen.Show();
-
- }
- show = true;
- Active = false;
-
- }
-
- if (show)
- {
- timerShow -= Time.deltaTime;
- if (timerShow <= 0)
- {
- timerShow = defoultTimer;
- show = false;
- if (WordDone)
- {
- CompliteWordScreen.Hide();
- }
- else
- {
- ActivateInfoScreen.Hide();
- }
- }
- }
-
- }
- public string GetNextLetter()
- {
- for (int i = 0; i < AllLettersForWord.Count; i++)
- {
- if (!AllLettersForWord[i].Find)
- {
- return AllLettersForWord[i].Label.text;
- }
- }
- return "";
- }
- //public IEnumerator LevelNotificaion()
- //{
- // Debug.LogWarning("LevelNotificaion");
- // LevelInfoScreen.Show();
- // yield return new WaitForSeconds(5);
- // LevelInfoScreen.Hide();
- //}
- public void LevelNotificaion(int getInt)
- {
-
- if (getInt == 3)
- {
- Label.text = string.Format("Tillykke!\n Du har bestået spillet!");
- //LabelTextCongratulations.text = "Grattis – du har klarat spelet!";
-
- }
- else
- {
- Label.text = string.Format("Du har gennemført Level {0}.", getInt);
- LabelTextCongratulations.text = "Tillykke!";
- }
-
- InGameScriptCS.Instance.bGamePaused = true;
- PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone",true);
- //LoginManager.Instance.OnClickOkLevelDone();
- LevelInfoScreen.Show();
- }
- public void NotificaionHide()
- {
- LevelInfoScreen.Hide();
- PlayerController.Instance.transform.GetComponent<Animator>().SetBool("LevelDone", false);
- PlayerController.Instance.transform.GetComponent<Animator>().SetBool("Run", false);
- }
- }
|