SceneCloudSpellingChallenge.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. using SimpleJSON;
  7. using System.Collections.Generic;
  8. using System;
  9. //================================================================================
  10. //
  11. //================================================================================
  12. namespace ReaderRabbit
  13. {
  14. //================================================================================
  15. //
  16. //================================================================================
  17. public class SceneCloudSpellingChallenge : SceneCommon
  18. {
  19. //================================================================================
  20. //
  21. //================================================================================
  22. private enum Characters
  23. {
  24. Reader = CharactersCommon.Reader,
  25. Sam = CharactersCommon.Sam,
  26. Paige = CharactersCommon.Paige,
  27. Chester = CharactersCommon.Chester,
  28. WallyOnLadder = CharactersCommon.StartSceneSpecific,
  29. WallyStanding
  30. }
  31. //================================================================================
  32. //
  33. //================================================================================
  34. private const int WORD_LIST_1_SIZE = 16;
  35. private const int WORD_LIST_2_SIZE = 20;
  36. private const int WORD_LIST_3_SIZE = 42;
  37. private const int WORD_LIST_NON_PRACTICE_SIZE = 3;
  38. private const int NUMBER_OF_MINIGAME_LEVELS = 3;
  39. //================================================================================
  40. //
  41. //================================================================================
  42. [SerializeField]
  43. private CollectableMarble m_Marble;
  44. [SerializeField]
  45. private CloudSpellingPhonemesArea m_PhonemesArea;
  46. [SerializeField]
  47. private CloudSpellingTreadmillController m_TreadmillController;
  48. [SerializeField]
  49. private List<CloudSpellingChallengeObjectsCloud> m_ObjectsClouds;
  50. [SerializeField]
  51. private List<CloudSpellingPhonemesRecipient> m_Recipients;
  52. [SerializeField]
  53. private Animator m_CloudGuyOnLadder;
  54. [SerializeField]
  55. private PrizeLadder m_PrizeLadder;
  56. [SerializeField]
  57. private List<GameObject> m_DeliveredClouds;
  58. private int m_CurrentMinigameLevel;
  59. private int m_CurrentWordList;
  60. private int m_WinsCount;
  61. private Treadmill m_CurrentTreadmill;
  62. private List<CloudSpellingWordDescription> m_CurrentWordDescriptions;
  63. private CloudSpellingPhonemesRecipient m_CurrentRecipient;
  64. private List<CloudSpellingPhonemeBox> m_FreeBoxes;
  65. private int m_CurrentReaderSamInteractionSpeech = 0;
  66. private int m_CurrentPaigeInteractionSpeech = 0;
  67. private int m_CurrentWallyOnLadderInteractionSpeech = 0;
  68. private Dictionary<string, string> m_PhonemeToSoundMap;
  69. private Characters m_CurrentActiveWally;
  70. private int lang;
  71. public GameObject WallyGOStanding; //mycode --rafael
  72. //================================================================================
  73. //
  74. //================================================================================
  75. protected override void Start()
  76. {
  77. base.Start();
  78. //============================================================================
  79. //
  80. //============================================================================
  81. lang = PlayerPrefs.GetInt("language");
  82. if (lang == 0)
  83. m_SpeechFolder = "Resources_DA/Audio/CloudSpellingChallenge_Speech";
  84. else if (lang == 1)
  85. m_SpeechFolder = "Resources_EN/Audio/CloudSpellingChallenge_Speech";
  86. else if (lang == 2)
  87. m_SpeechFolder = "Resources_NO/Audio/CloudSpellingChallenge_Speech";
  88. else if (lang == 3)
  89. m_SpeechFolder = "Resources_SP/Audio/CloudSpellingChallenge_Speech";
  90. else if (lang == 4)
  91. m_SpeechFolder = "Resources_SW/Audio/CloudSpellingChallenge_Speech";
  92. //============================================================================
  93. //
  94. //============================================================================
  95. InitPhonemeSoundMap();
  96. PlayerData.Instance().SetVisitedCloudSpellingChallenge(true);
  97. PlayerData.Instance().SetCurrentLocation(Location.CloudSpellingChallenge);
  98. PlayerData.Instance().UnlockActivity(Activity.CloudSpellingChallenge);
  99. AudioManager.Instance().PlayBGM("BGM_CloudSpellingChallenge");
  100. this.m_CurrentMinigameLevel = PlayerData.Instance().GetActivityLevel(Activity.CloudSpellingChallenge) - 1;
  101. m_Marble.SetParentScene(this);
  102. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_Marble.gameObject, false);
  103. //KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_PrizeLadder.gameObject);
  104. m_FreeBoxes = new List<CloudSpellingPhonemeBox>();
  105. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(m_CloudGuyOnLadder.gameObject);
  106. if (PlayerData.Instance().IsPracticeMode() || PlayerData.Instance().GetLadder() != ItemState.None)
  107. {
  108. m_PrizeLadder.gameObject.SetActive(false);
  109. }
  110. //m_WinsCount = 0;
  111. CheckAmountOfWins ();
  112. Invoke("UpdateSizesAndPositions", 0.005f);
  113. //m_PrizeLadder.DisableClick();
  114. m_PrizeLadder.SetParentScene(this);
  115. m_CurrentTreadmill = Treadmill.INVALID_TREADMILL;
  116. }
  117. void CheckAmountOfWins (){
  118. if (PlayerData.Instance ().CSC_WinsCount != 0 && !PlayerData.Instance().IsPracticeMode()) { //mycode --rafael -->original above commented.
  119. m_WinsCount = PlayerData.Instance ().CSC_WinsCount;
  120. } else {
  121. m_WinsCount = 0;
  122. }
  123. if (m_WinsCount >= 3) {
  124. m_PrizeLadder.EnableClick ();
  125. } else {
  126. m_PrizeLadder.DisableClick();
  127. }
  128. }
  129. //================================================================================
  130. //
  131. //================================================================================
  132. protected override void PlayFirstEvent()
  133. {
  134. if (!PlayerData.Instance().IsPracticeMode())
  135. {
  136. if (m_IsFirstTime)
  137. {
  138. PlayFirstDialogueFlow();
  139. }
  140. else
  141. {
  142. PlayWallyRandomWelcomeBackPhrase();
  143. }
  144. }
  145. else
  146. {
  147. NewSequence();
  148. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, "10182");
  149. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, "10185");
  150. SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, "10356");
  151. SetSequence(3, EventSequenceItem.EventSequenceType.Callback, InvokeLoadNextLevelDelayed);
  152. SetSequence(4, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  153. StartSequence(5);
  154. }
  155. }
  156. //================================================================================
  157. //
  158. //================================================================================
  159. private void UpdateSizesAndPositions()
  160. {
  161. foreach (GameObject go in m_DeliveredClouds)
  162. {
  163. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(go);
  164. }
  165. if (m_WinsCount < 3 && !PlayerData.Instance().IsPracticeMode()) //mycode --rafael --> original --> if (PlayerData.Instance().GetLadder() == ItemState.None && !PlayerData.Instance().IsPracticeMode())
  166. {
  167. m_CharacterAnimations[(int)Characters.WallyOnLadder].gameObject.SetActive(true);
  168. m_CharacterAnimations[(int)Characters.WallyStanding].gameObject.SetActive(false);
  169. m_OtherCharacterRectangles[0].gameObject.SetActive(true);
  170. m_OtherCharacterRectangles[1].gameObject.SetActive(false);
  171. m_CurrentActiveWally = Characters.WallyOnLadder;
  172. }
  173. else if (m_WinsCount >= 3 || PlayerData.Instance().IsPracticeMode()) //mycode --rafael --> original --> else if (PlayerData.Instance().IsPracticeMode() || PlayerData.Instance().GetLadder() != ItemState.None)
  174. {
  175. m_CharacterAnimations[(int)Characters.WallyOnLadder].gameObject.SetActive(false);
  176. m_CharacterAnimations[(int)Characters.WallyStanding].gameObject.SetActive(true);
  177. m_OtherCharacterRectangles[0].gameObject.SetActive(false);
  178. m_OtherCharacterRectangles[1].gameObject.SetActive(true);
  179. m_CurrentActiveWally = Characters.WallyStanding;
  180. }
  181. }
  182. //================================================================================
  183. //
  184. //================================================================================
  185. public void LoadNextLevel()
  186. {
  187. //Updates mini-game's next level
  188. if (!PlayerData.Instance().IsActivityLocked(Activity.CloudSpellingChallenge))
  189. {
  190. m_CurrentMinigameLevel++;
  191. if (m_CurrentMinigameLevel > NUMBER_OF_MINIGAME_LEVELS)
  192. {
  193. m_CurrentMinigameLevel = NUMBER_OF_MINIGAME_LEVELS;
  194. }
  195. PlayerData.Instance().SetActivityLevel(Activity.CloudSpellingChallenge, m_CurrentMinigameLevel);
  196. }
  197. //Get a random word list set
  198. List<JSONNode> words = GetWords();
  199. m_CurrentWordDescriptions = new List<CloudSpellingWordDescription>();
  200. m_CurrentWordDescriptions.Add(new CloudSpellingWordDescription(words[0].Value));
  201. m_CurrentWordDescriptions.Add(new CloudSpellingWordDescription(words[1].Value));
  202. m_CurrentWordDescriptions.Add(new CloudSpellingWordDescription(words[2].Value));
  203. m_PhonemesArea.Setup(m_CurrentWordDescriptions[0].AvailableParts);
  204. ShowNextWord(((Treadmill)m_CurrentTreadmill + 1));
  205. }
  206. //================================================================================
  207. //
  208. //================================================================================
  209. public void InitNextLevel()
  210. {
  211. m_CurrentWordDescriptions.Clear();
  212. AudioManager.Instance().PlaySFX("10280");
  213. if (m_FreeBoxes != null)
  214. {
  215. foreach (CloudSpellingPhonemeBox box in m_FreeBoxes)
  216. {
  217. if (box != null)
  218. {
  219. GameObject.Destroy(box.gameObject);
  220. }
  221. }
  222. }
  223. m_FreeBoxes.Clear();
  224. m_PhonemesArea.Reset();
  225. foreach (CloudSpellingPhonemesRecipient r in m_Recipients)
  226. {
  227. r.Reset();
  228. }
  229. foreach (CloudSpellingChallengeObjectsCloud cloud in m_ObjectsClouds)
  230. {
  231. cloud.HideCurrentObject();
  232. foreach (Transform children in cloud.transform){
  233. if (children.gameObject.name == "Images"){
  234. children.gameObject.transform.localPosition = cloud.transform.position;
  235. }
  236. }
  237. }
  238. m_TreadmillController.Reset();
  239. m_CurrentTreadmill = Treadmill.INVALID_TREADMILL;
  240. LoadNextLevel();
  241. }
  242. //================================================================================
  243. //
  244. //================================================================================
  245. private List<JSONNode> GetWords()
  246. {
  247. TextAsset jsonText;
  248. jsonText = null;
  249. if(lang == 0) jsonText = Resources.Load<TextAsset>("Resources_DA/CloudSpellingChallenge/r1ca1");
  250. else if (lang == 1) jsonText = Resources.Load<TextAsset>("Resources_EN/CloudSpellingChallenge/r1ca1");
  251. else if (lang == 2) jsonText = Resources.Load<TextAsset>("Resources_NO/CloudSpellingChallenge/r1ca1");
  252. else if (lang == 3) jsonText = Resources.Load<TextAsset>("Resources_SP/CloudSpellingChallenge/r1ca1");
  253. else if (lang == 4) jsonText = Resources.Load<TextAsset>("Resources_SW/CloudSpellingChallenge/r1ca1");
  254. JSONNode json = JSONNode.Parse(jsonText.text);
  255. JSONNode currentLevelWordLists = json["DataSet"]["Level_" + m_CurrentMinigameLevel];
  256. int amountOfWordList = currentLevelWordLists.Count; //mycode --rafael --> use this and not the constatants in this script. This will help in localization.
  257. List<JSONNode> result = new List<JSONNode>();
  258. int currentListSize = amountOfWordList; //mycode --rafael --> original --> int currentListSize = GetCurrentWordListSize();
  259. currentListSize--;
  260. int randomIndex = UnityEngine.Random.Range(1, currentListSize);
  261. for (int i = 0; i < 3; ++i)
  262. {
  263. if (m_CurrentMinigameLevel == 3)
  264. {
  265. result.Add(currentLevelWordLists["WordList_" + (randomIndex + i)]["Set_1"]);
  266. }
  267. else
  268. {
  269. result.Add(currentLevelWordLists["WordList_" + (randomIndex + i)]["Set_" + UnityEngine.Random.Range(1, 4)]);
  270. }
  271. }
  272. return result;
  273. }
  274. //================================================================================
  275. //
  276. //================================================================================
  277. private int GetCurrentWordListSize()
  278. {
  279. int wordListSize = 0;
  280. //Check number of word lists
  281. /*if (!PlayerData.Instance().IsPracticeMode() &&
  282. !PlayerData.Instance().IsActivityLocked(Activity.CloudSpellingChallenge) &&
  283. PlayerData.Instance().GetLadder() == ItemState.None)
  284. {
  285. return WORD_LIST_NON_PRACTICE_SIZE;
  286. }*/
  287. if (!PlayerData.Instance().IsPracticeMode() && //mycode --rafael. Original commented above.
  288. !PlayerData.Instance().IsActivityLocked(Activity.CloudSpellingChallenge) &&
  289. m_WinsCount < 3)
  290. {
  291. return WORD_LIST_NON_PRACTICE_SIZE;
  292. }
  293. if (m_CurrentMinigameLevel == 1)
  294. {
  295. wordListSize = WORD_LIST_1_SIZE;
  296. }
  297. else if (m_CurrentMinigameLevel == 2)
  298. {
  299. wordListSize = WORD_LIST_2_SIZE;
  300. }
  301. else
  302. {
  303. wordListSize = WORD_LIST_3_SIZE;
  304. }
  305. return wordListSize;
  306. }
  307. //================================================================================
  308. //
  309. //================================================================================
  310. public void ShowNextWord(Treadmill treadmill)
  311. {
  312. if (treadmill != m_CurrentTreadmill)
  313. {
  314. m_CurrentTreadmill = treadmill;
  315. m_TreadmillController.Setup(m_CurrentWordDescriptions[(int)treadmill], treadmill);
  316. m_PhonemesArea.Setup(m_CurrentWordDescriptions[(int)treadmill].AvailableParts);
  317. m_ObjectsClouds[(int)treadmill].ShowObject(m_CurrentWordDescriptions[(int)treadmill].CorrectWord);
  318. m_CurrentRecipient = m_Recipients[(int)treadmill];
  319. m_PhonemesArea.EnableDrag();
  320. }
  321. PlayLetterOrWordSound(m_CurrentWordDescriptions[(int)treadmill].CorrectWord);
  322. }
  323. //================================================================================
  324. //
  325. //================================================================================
  326. public CloudSpellingPhonemeBox IsMouseOverCurrentRecipient()
  327. {
  328. return m_CurrentRecipient.IsMouseOverBox();
  329. }
  330. //================================================================================
  331. //
  332. //================================================================================
  333. public void AddPhonemeBoxToRecipient(CloudSpellingPhonemeBox boxToAdd, CloudSpellingPhonemeBox destiny)
  334. {
  335. m_CurrentRecipient.AddMovablePhonemeBox(boxToAdd, destiny);
  336. }
  337. //================================================================================
  338. //
  339. //================================================================================
  340. public void RemovePhonemeBoxFromRecipient(CloudSpellingPhonemeBox boxToRemove)
  341. {
  342. m_CurrentRecipient.RemoveMovablePhonemeBox(boxToRemove);
  343. }
  344. //================================================================================
  345. //
  346. //================================================================================
  347. public bool IsCurrentRecipientAnswerCorrect()
  348. {
  349. if (m_CurrentTreadmill == Treadmill.INVALID_TREADMILL)
  350. {
  351. return false;
  352. }
  353. List<CloudSpellingPhonemeBox> phonemes = m_CurrentRecipient.GetCurrentWordPhonemes();
  354. string correctWord = m_CurrentWordDescriptions[(int)m_CurrentTreadmill].CorrectWord;
  355. for (int i = 0, j = 0; i < phonemes.Count; ++i)
  356. {
  357. int phonemesLength = (phonemes[i].GetText01 == "")? 1 : 2;
  358. if (correctWord.Substring(j, phonemesLength) != (phonemes[i].GetText00 + phonemes[i].GetText01))
  359. {
  360. phonemes[i].RemoveToOriginalPosition();// ReturnToOriginalPosition();
  361. }
  362. j += phonemesLength;
  363. }
  364. bool result = (m_CurrentRecipient.GetCurrentWord() == m_CurrentWordDescriptions[(int)m_CurrentTreadmill].CorrectWord);
  365. return result;
  366. }
  367. //================================================================================
  368. //
  369. //================================================================================
  370. public bool PlayWrongAnswerSpeech(System.Action callback)
  371. {
  372. if (m_PhonemeToSoundMap.ContainsKey(m_CurrentRecipient.GetCurrentWord().ToLower()))
  373. {
  374. NewSequence();
  375. int sequence = 0;
  376. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, m_CurrentActiveWally, m_PhonemeToSoundMap[m_CurrentRecipient.GetCurrentWord().ToLower()]);
  377. if (UnityEngine.Random.Range(0, 1.0f) > 0.5f)
  378. {
  379. float randomCharacter = UnityEngine.Random.Range(0, 1.0f);
  380. if (randomCharacter > 0.66f)
  381. {
  382. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "10315");
  383. }
  384. else if (randomCharacter > 0.33f)
  385. {
  386. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "10316");
  387. }
  388. else
  389. {
  390. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Speech, m_CurrentActiveWally, "10318");
  391. }
  392. }
  393. SetSequence(sequence++, EventSequenceItem.EventSequenceType.Callback, callback);
  394. StartSequence(sequence);
  395. return true;
  396. }
  397. return false;
  398. }
  399. //================================================================================
  400. //
  401. //================================================================================
  402. public void OnRightAnswer()
  403. {
  404. PlayLetterOrWordSound(m_CurrentRecipient.GetCurrentWord());
  405. m_FreeBoxes.Add(null);
  406. this.m_FreeBoxes.AddRange(m_CurrentRecipient.FreeAddedBoxes());
  407. m_PhonemesArea.DisableDrag();
  408. }
  409. //================================================================================
  410. //
  411. //================================================================================
  412. public void RemoveBoxFromPhonemesArea(CloudSpellingPhonemeBox box)
  413. {
  414. m_PhonemesArea.RemovePhoneme(box);
  415. }
  416. //================================================================================
  417. //
  418. //================================================================================
  419. public void GivePrize()
  420. {
  421. //TODO: Play animation
  422. if (m_WinsCount == 3) //mycode --rafael --> original --> if (m_WinsCount > 2 && PlayerData.Instance().GetLadder() == ItemState.None)
  423. {
  424. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "10228");
  425. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.WallyOnLadder, "10235");
  426. SetSequence(2, EventSequenceItem.EventSequenceType.AnimationWithSfx,
  427. Characters.WallyOnLadder,
  428. 3, // Animation index.
  429. m_CharacterAnimations[(int)Characters.WallyOnLadder].AnimationCyclesString[3],
  430. "10240");
  431. SetSequence(3, EventSequenceItem.EventSequenceType.Callback, UpdateEnabledCharacters);
  432. // TODO: Use WallyStanding once it is added to SceneCode.
  433. SetSequence(4, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, "10245");
  434. SetSequence(5, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, "10246");
  435. SetSequence(6, EventSequenceItem.EventSequenceType.Callback, InitNextLevel);
  436. StartSequence(7);
  437. m_PrizeLadder.EnableClick();
  438. PlayerData.Instance().CSC_WinsCount = m_WinsCount; //mycode --rafael
  439. PlayerData.Instance().SaveData(); //mycode --rafael
  440. }
  441. else if (m_WinsCount > 3) //mycode --rafael --> original --> else if (m_WinsCount > 3 || PlayerData.Instance().GetLadder() != ItemState.None)
  442. {
  443. int[] possibleValues = { 0, 1, 2, 5, 6 };
  444. string sequence = "1026" + possibleValues[UnityEngine.Random.Range(0, possibleValues.Length)];
  445. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.WallyStanding, sequence);
  446. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, InitNextLevel);
  447. StartSequence(2);
  448. m_Marble.gameObject.SetActive(true);
  449. PlayerData.Instance().CSC_WinsCount = m_WinsCount; //mycode --rafael
  450. PlayerData.Instance().SaveData(); //mycode --rafael
  451. }
  452. else
  453. {
  454. InitNextLevel();
  455. }
  456. }
  457. void CanCollectLadder(){ //mycode --rafael
  458. if (m_WinsCount > 2 && WallyGOStanding.activeInHierarchy) //m_WinsCount > 2 && PlayerData.Instance().GetLadder() == ItemState.None
  459. {
  460. m_PrizeLadder.canCollect = true;
  461. }
  462. }
  463. protected override void Update() //mycode --rafael
  464. {
  465. base.Update();
  466. CanCollectLadder();
  467. }
  468. private void UpdateEnabledCharacters()
  469. {
  470. this.m_CurrentActiveWally = Characters.WallyStanding;
  471. this.m_CharacterAnimations[(int)Characters.WallyStanding].gameObject.SetActive(true);
  472. this.m_OtherCharacterRectangles[0].gameObject.SetActive(false);
  473. this.m_CharacterAnimations[(int)Characters.WallyOnLadder].gameObject.SetActive(false);
  474. this.m_OtherCharacterRectangles[1].gameObject.SetActive(true);
  475. }
  476. //================================================================================
  477. //
  478. //================================================================================
  479. public void StoreCloud()
  480. {
  481. AudioManager.Instance().PlaySFX("10270");
  482. m_WinsCount++;
  483. if (m_WinsCount <= 3) //mycode --rafael --> original: if (m_WinsCount <= 3 && PlayerData.Instance().GetLadder() == ItemState.None)
  484. {
  485. m_CloudGuyOnLadder.gameObject.SetActive(true);
  486. m_CharacterAnimations[(int)Characters.WallyOnLadder].gameObject.SetActive(false);
  487. m_CloudGuyOnLadder.SetTrigger("GetCloud");
  488. m_TreadmillController.SetCloudEnabled(false);
  489. }
  490. else
  491. {
  492. GivePrize();
  493. }
  494. }
  495. //================================================================================
  496. //
  497. //================================================================================
  498. public void OnCloudStored(string whatever)
  499. {
  500. if (m_WinsCount == 3)
  501. {
  502. m_CloudGuyOnLadder.gameObject.SetActive(false);
  503. }
  504. if (m_WinsCount <= 3)
  505. {
  506. m_CloudGuyOnLadder.gameObject.SetActive(false);
  507. m_CharacterAnimations[(int)Characters.WallyOnLadder].gameObject.SetActive(true);
  508. m_DeliveredClouds[m_WinsCount - 1].SetActive(true);
  509. }
  510. GivePrize();
  511. }
  512. //================================================================================
  513. //
  514. //================================================================================
  515. public override void SpeechPaige()
  516. {
  517. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayReaderSamIntereactionSpeech");
  518. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayReaderSamIntereactionSpeech:m_CurrentReaderSamInteractionSpeech = " + m_CurrentPaigeInteractionSpeech);
  519. if (m_CurrentPaigeInteractionSpeech > 2)
  520. {
  521. m_CurrentPaigeInteractionSpeech = 0;
  522. }
  523. NewSequence();
  524. if (m_CurrentPaigeInteractionSpeech == 0)
  525. {
  526. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "10381");
  527. }
  528. else if (m_CurrentPaigeInteractionSpeech == 1)
  529. {
  530. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "10382");
  531. }
  532. else if (m_CurrentPaigeInteractionSpeech == 2)
  533. {
  534. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Paige, "10380");
  535. }
  536. StartSequence(1);
  537. m_CurrentPaigeInteractionSpeech++;
  538. }
  539. //================================================================================
  540. //
  541. //================================================================================
  542. public override void SpeechReader()
  543. {
  544. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayReaderSamIntereactionSpeech");
  545. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayReaderSamIntereactionSpeech:m_CurrentReaderSamInteractionSpeech = " + "1040" + (m_CurrentReaderSamInteractionSpeech + 4));
  546. if (m_CurrentReaderSamInteractionSpeech > 4)
  547. {
  548. m_CurrentReaderSamInteractionSpeech = 0;
  549. }
  550. NewSequence();
  551. if (m_CurrentReaderSamInteractionSpeech < 3)
  552. {
  553. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "1040" + (m_CurrentReaderSamInteractionSpeech + 4));
  554. }
  555. else
  556. {
  557. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Sam, "1040" + (m_CurrentReaderSamInteractionSpeech + 4));
  558. }
  559. StartSequence(1);
  560. m_CurrentReaderSamInteractionSpeech++;
  561. }
  562. //================================================================================
  563. //
  564. //================================================================================
  565. private void PlayWallyOnLadderSpeech()
  566. {
  567. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayWallyOnLadderSpeech");
  568. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayWallyOnLadderSpeech:m_CurrentWallyOnLadderInteractionSpeech = " + "1035" + (m_CurrentWallyOnLadderInteractionSpeech + 4));
  569. if (m_CurrentWallyOnLadderInteractionSpeech > 3)
  570. {
  571. m_CurrentWallyOnLadderInteractionSpeech = 0;
  572. }
  573. NewSequence();
  574. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, m_CurrentActiveWally, "1035" + (m_CurrentWallyOnLadderInteractionSpeech + 5));
  575. StartSequence(1);
  576. m_CurrentWallyOnLadderInteractionSpeech++;
  577. }
  578. //================================================================================
  579. //
  580. //================================================================================
  581. private void PlayWallyRandomWelcomeBackPhrase()
  582. {
  583. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayWallyRandomWelcomeBackPhrase");
  584. string[] possibleNumbers = {"10", "11", "05"};
  585. string randomPhraseNumber = possibleNumbers[UnityEngine.Random.Range(0, possibleNumbers.Length)];
  586. NewSequence();
  587. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, m_CurrentActiveWally, "102" + randomPhraseNumber);
  588. SetSequence(1, EventSequenceItem.EventSequenceType.Callback, InvokeLoadNextLevelDelayed);
  589. SetSequence(2, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  590. StartSequence(3);
  591. }
  592. //================================================================================
  593. //
  594. //================================================================================
  595. private void PlayFirstDialogueFlow()
  596. {
  597. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("SceneCloudSpellingChallenge.PlayFirstDialogueFlow");
  598. NewSequence();
  599. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, Characters.Reader, "10180");
  600. SetSequence(1, EventSequenceItem.EventSequenceType.Speech, Characters.WallyOnLadder, "10182");
  601. SetSequence(2, EventSequenceItem.EventSequenceType.Speech, Characters.WallyOnLadder, "10185");
  602. SetSequence(3, EventSequenceItem.EventSequenceType.Speech, Characters.WallyOnLadder, "10183");
  603. SetSequence(4, EventSequenceItem.EventSequenceType.Speech, Characters.WallyOnLadder, "10184");
  604. SetSequence(5, EventSequenceItem.EventSequenceType.Callback, InvokeLoadNextLevelDelayed);
  605. SetSequence(6, EventSequenceItem.EventSequenceType.Callback, DoneFirstTime);
  606. StartSequence(7);
  607. }
  608. //================================================================================
  609. //
  610. //================================================================================
  611. private void InvokeLoadNextLevelDelayed()
  612. {
  613. Invoke("LoadNextLevel", 0.3f);
  614. }
  615. //================================================================================
  616. //
  617. //================================================================================
  618. protected override void OnOtherCharacterInteraction()
  619. {
  620. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCloudSpellingChallenge.OnOtherCharacterInteraction()...");
  621. if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "WallyOnLadder" ||
  622. m_CurrentInteractiveRectangle.GetActionParameter(0) == "WallyStanding")
  623. {
  624. PlayWallyOnLadderSpeech();
  625. }
  626. }
  627. //================================================================================
  628. //
  629. //================================================================================
  630. public void PlayLetterOrWordSound(string toBePlayed)
  631. {
  632. NewSequence();
  633. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, m_CurrentActiveWally, m_PhonemeToSoundMap[toBePlayed.ToLower()]);
  634. StartSequence(1);
  635. }
  636. //================================================================================
  637. //
  638. //================================================================================
  639. private void InitPhonemeSoundMap()
  640. {
  641. string[] separators = { "\r\n" };
  642. string text = "";
  643. if (lang == 0) text = Resources.Load<TextAsset>("Resources_DA/CloudSpellingChallenge/phonemeToAudioMapping").text;
  644. else if (lang == 1) text = Resources.Load<TextAsset>("Resources_EN/CloudSpellingChallenge/phonemeToAudioMapping").text;
  645. else if (lang == 2) text = Resources.Load<TextAsset>("Resources_NO/CloudSpellingChallenge/phonemeToAudioMapping").text;
  646. else if (lang == 3) text = Resources.Load<TextAsset>("Resources_SP/CloudSpellingChallenge/phonemeToAudioMapping").text;
  647. else if (lang == 4) text = Resources.Load<TextAsset>("Resources_SW/CloudSpellingChallenge/phonemeToAudioMapping").text;
  648. string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
  649. m_PhonemeToSoundMap = new Dictionary<string, string>();
  650. int initialSoundName = 10500;
  651. foreach (string word in words)
  652. {
  653. m_PhonemeToSoundMap.Add(word, initialSoundName.ToString());
  654. initialSoundName++;
  655. }
  656. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("m_PhonemeToSoundMap "+ m_PhonemeToSoundMap.Count);
  657. }
  658. //================================================================================
  659. //
  660. //================================================================================
  661. public void GetMarble()
  662. {
  663. m_Marble.DoAction();
  664. }
  665. } // public class SceneCloudSpellingChallenge : SceneCommon
  666. } // namespace ReaderRabbit