SceneCommon.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using KishiTechUnity.KishiTechDebug;
  8. //================================================================================
  9. //
  10. //================================================================================
  11. namespace ReaderRabbit
  12. {
  13. //================================================================================
  14. //
  15. //================================================================================
  16. public class SceneCommon : KishiTechUnity.ScreenResolution.SceneRoot
  17. {
  18. //================================================================================
  19. //
  20. //================================================================================
  21. public enum CharactersCommon
  22. {
  23. Reader = 0,
  24. Sam,
  25. Paige,
  26. Chester,
  27. StartSceneSpecific,
  28. }
  29. //================================================================================
  30. //
  31. //================================================================================
  32. [SerializeField] protected SceneIndex m_SceneIndex;
  33. [SerializeField] protected ChesterInSceneAnimation m_ChesterInScene;
  34. [SerializeField] protected RRInteractiveRectangle m_ChesterRectangle;
  35. [SerializeField] protected RRInteractiveRectangle[] m_CharacterRectangles;
  36. [SerializeField] protected RRInteractiveRectangle[] m_OtherCharacterRectangles;
  37. [SerializeField] protected RRInteractiveRectangle[] m_NavigationRectangles;
  38. protected RRInteractiveRectangle m_CurrentInteractiveRectangle;
  39. [SerializeField] protected HUDCommon[] m_HUD;
  40. [SerializeField] protected ItemCommon[] m_Items;
  41. [SerializeField] protected CharacterAnimation[] m_CharacterAnimations;
  42. protected CharacterAnimation m_CurrentCharacterAnimation;
  43. [SerializeField] protected float m_MinIdleDelay = 30.0f;
  44. protected float m_IdleDelay;
  45. // HACK: When map or Chester is closed, wait for n milliseconds before processing the next click,
  46. // otherwise we might navigate to another location when we should not (e.g. player has just closed map).
  47. protected float m_DelayForNextClick;
  48. // HACK: When map or Chester is closed, wait for n milliseconds before processing the next click,
  49. // otherwise we might navigate to another location when we should not (e.g. player has just closed map).
  50. protected const float DELAY_NEXT_CLICK = 0.1f;
  51. // Speech config.
  52. protected string m_SpeechFolder;
  53. protected string m_LastSpeech;
  54. protected int m_SpeechCount;
  55. // Event sequence.
  56. [SerializeField] protected int m_EventSequenceMaxItems = 10;
  57. protected EventSequenceItem[] m_CurrentSequence;
  58. protected int m_CurrentSequenceItems;
  59. protected int m_CurrentSequenceIndex;
  60. protected bool m_IsPlayingSequence;
  61. protected bool m_SkipCurrentSequence;
  62. protected bool m_IsSequenceSkippable;
  63. protected float m_SequenceStartTime;
  64. protected float m_SequenceWaitDelayBeforeSkip;
  65. bool m_CanHideLoading;
  66. protected bool m_IsFirstTime;
  67. private bool canPressInput; //mycode --rafael
  68. private float clockToResetInput; //mycode --rafael
  69. private const float TIME_TO_RESET = 1f; //mycode --rafael
  70. private const float TIME_FINAL = 0f; //mycode --rafael
  71. //================================================================================
  72. //
  73. //================================================================================
  74. protected virtual void Awake()
  75. {
  76. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.Awake()...");
  77. m_CanHideLoading = false;
  78. canPressInput = true; //mycode --rafael
  79. clockToResetInput = TIME_TO_RESET; //mycode --rafael
  80. }
  81. //================================================================================
  82. //
  83. //================================================================================
  84. void OnLevelWasLoaded(int level)
  85. {
  86. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnLevelWasLoaded()...");
  87. if (level == (int)m_SceneIndex)
  88. m_CanHideLoading = true;
  89. }
  90. //================================================================================
  91. //
  92. //================================================================================
  93. void OnApplicationPause(bool pauseStatus)
  94. {
  95. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnApplicationPause(" + pauseStatus + ")...");
  96. if (pauseStatus)
  97. PlayerData.Instance().SaveData();
  98. else
  99. {
  100. PlayerData.Instance().LoadData();
  101. AudioController.EnableMusic(PlayerData.Instance().IsBackgroundMusicEnabled());
  102. }
  103. }
  104. //================================================================================
  105. //
  106. //================================================================================
  107. void OnApplicationFocus(bool focusStatus)
  108. {
  109. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnApplicationFocus(" + focusStatus + ")...");
  110. if (!focusStatus)
  111. PlayerData.Instance().SaveData();
  112. else
  113. {
  114. PlayerData.Instance().LoadData();
  115. AudioController.EnableMusic(PlayerData.Instance().IsBackgroundMusicEnabled());
  116. }
  117. }
  118. //================================================================================
  119. //
  120. //================================================================================
  121. void OnApplicationQuit()
  122. {
  123. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnApplicationQuit()...");
  124. PlayerData.Instance().SaveData();
  125. }
  126. //================================================================================
  127. //
  128. //================================================================================
  129. protected override void Start()
  130. {
  131. m_IsFirstTime = !PlayerData.Instance().DidVisit(m_SceneIndex);
  132. Map.Instance().Close();
  133. Options.Instance().Close();
  134. Chester.Instance().Close();
  135. Chester.Instance().SetChesterInSceneAnimation(m_ChesterInScene);
  136. if (m_ChesterRectangle != null)
  137. Chester.Instance().SetInitialPosition(float.Parse(m_ChesterRectangle.GetActionParameter(0)), float.Parse(m_ChesterRectangle.GetActionParameter(1)));
  138. Chester.Instance().SetRightItemUsedInSceneCallback(OnRightItemUsedInScene);
  139. Chester.Instance().SetWrongItemUsedInSceneCallback(OnWrongItemUsedInScene);
  140. if (m_ChesterRectangle != null)
  141. m_ChesterRectangle.SetCallback(ProcessAction);
  142. if (m_CharacterRectangles != null)
  143. {
  144. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  145. {
  146. if (interactiveRectangle != null)
  147. interactiveRectangle.SetCallback(ProcessAction);
  148. }
  149. }
  150. if (m_OtherCharacterRectangles != null)
  151. {
  152. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  153. {
  154. if (interactiveRectangle != null)
  155. interactiveRectangle.SetCallback(ProcessAction);
  156. }
  157. }
  158. if (m_NavigationRectangles != null)
  159. {
  160. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  161. {
  162. if (interactiveRectangle != null)
  163. interactiveRectangle.SetCallback(ProcessAction);
  164. }
  165. }
  166. if (m_Items != null)
  167. {
  168. foreach (ItemCommon item in m_Items)
  169. item.SetParentScene(this);
  170. }
  171. if (m_CharacterAnimations != null)
  172. {
  173. foreach (CharacterAnimation characterAnimation in m_CharacterAnimations)
  174. {
  175. characterAnimation.SetParentScene(this);
  176. characterAnimation.SetOnAnimatorFinishedCallback(OnCharacterAnimationFinished);
  177. characterAnimation.SetOnAnimatorCustomTimelineEvent1Callback(OnCharacterAnimationCustomTimelineEvent1);
  178. characterAnimation.SetOnSpeechFinishedCallback(OnCharacterSpeechFinished);
  179. characterAnimation.SetCanRandomizeIdle(!m_IsFirstTime);
  180. }
  181. }
  182. m_LastSpeech = "";
  183. m_SpeechCount = 0;
  184. if (m_CurrentSequence == null)
  185. m_CurrentSequence = new EventSequenceItem[m_EventSequenceMaxItems];
  186. for (int i = 0; i < m_EventSequenceMaxItems; ++i)
  187. {
  188. if (m_CurrentSequence[i] == null)
  189. m_CurrentSequence[i] = new EventSequenceItem();
  190. m_CurrentSequence[i].Reset();
  191. }
  192. m_CurrentSequenceItems = 0;
  193. m_CurrentSequenceIndex = 0;
  194. m_IsPlayingSequence = false;
  195. m_SkipCurrentSequence = false;
  196. m_SequenceWaitDelayBeforeSkip = 0.5f;
  197. base.Start();
  198. UpdateIdleDelay();
  199. // HACK: Show loading screen so player does not see a bunch of animations on top of each other.
  200. //KishiTechUnity.Loading.Loading.Instance().Show();
  201. Invoke("EnableCharacterAnimatorFirstTime", 0.1f);
  202. }
  203. //================================================================================
  204. //
  205. //================================================================================
  206. protected virtual void EnableCharacterAnimatorFirstTime()
  207. {
  208. if (m_CharacterAnimations != null)
  209. {
  210. foreach (CharacterAnimation characterAnimation in m_CharacterAnimations)
  211. {
  212. characterAnimation.ChangeToIdle();
  213. }
  214. }
  215. if (m_CanHideLoading)
  216. KishiTechUnity.Loading.Loading.Instance().Hide();
  217. PlayFirstEvent();
  218. }
  219. //================================================================================
  220. //
  221. //================================================================================
  222. protected virtual void PlayFirstEvent()
  223. {
  224. }
  225. //================================================================================
  226. //
  227. //================================================================================
  228. protected virtual void DoneFirstTime()
  229. {
  230. if (m_CharacterAnimations != null)
  231. {
  232. foreach (CharacterAnimation characterAnimation in m_CharacterAnimations)
  233. {
  234. characterAnimation.SetCanRandomizeIdle(true);
  235. }
  236. }
  237. }
  238. //================================================================================
  239. //
  240. //================================================================================
  241. void DebugEnableAll()
  242. {
  243. if (m_ChesterRectangle != null)
  244. m_ChesterRectangle.DebugEnable();
  245. if (m_CharacterRectangles != null)
  246. {
  247. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  248. {
  249. if (interactiveRectangle != null)
  250. interactiveRectangle.DebugEnable();
  251. }
  252. }
  253. if (m_OtherCharacterRectangles != null)
  254. {
  255. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  256. {
  257. if (interactiveRectangle != null)
  258. interactiveRectangle.DebugEnable();
  259. }
  260. }
  261. if (m_NavigationRectangles != null)
  262. {
  263. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  264. {
  265. if (interactiveRectangle != null)
  266. interactiveRectangle.DebugEnable();
  267. }
  268. }
  269. }
  270. //================================================================================
  271. //
  272. //================================================================================
  273. void DebugDisableAll()
  274. {
  275. if (m_ChesterRectangle != null)
  276. m_ChesterRectangle.DebugDisable();
  277. if (m_CharacterRectangles != null)
  278. {
  279. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  280. {
  281. if (interactiveRectangle != null)
  282. interactiveRectangle.DebugDisable();
  283. }
  284. }
  285. if (m_OtherCharacterRectangles != null)
  286. {
  287. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  288. {
  289. if (interactiveRectangle != null)
  290. interactiveRectangle.DebugDisable();
  291. }
  292. }
  293. if (m_NavigationRectangles != null)
  294. {
  295. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  296. {
  297. if (interactiveRectangle != null)
  298. interactiveRectangle.DebugDisable();
  299. }
  300. }
  301. }
  302. //================================================================================
  303. //
  304. //================================================================================
  305. void UpdateDebugEnabledAll()
  306. {
  307. if (m_ChesterRectangle != null)
  308. m_ChesterRectangle.UpdateDebugEnabled();
  309. if (m_CharacterRectangles != null)
  310. {
  311. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  312. {
  313. if (interactiveRectangle != null)
  314. interactiveRectangle.UpdateDebugEnabled();
  315. }
  316. }
  317. if (m_OtherCharacterRectangles != null)
  318. {
  319. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  320. {
  321. if (interactiveRectangle != null)
  322. interactiveRectangle.UpdateDebugEnabled();
  323. }
  324. }
  325. if (m_NavigationRectangles != null)
  326. {
  327. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  328. {
  329. if (interactiveRectangle != null)
  330. interactiveRectangle.UpdateDebugEnabled();
  331. }
  332. }
  333. }
  334. //================================================================================
  335. //
  336. //================================================================================
  337. public virtual void UpdateOnce()
  338. {
  339. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.UpdateOnce()...");
  340. }
  341. //================================================================================
  342. //
  343. //================================================================================
  344. protected void EnableNavigationAll()
  345. {
  346. if (m_NavigationRectangles != null)
  347. {
  348. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  349. {
  350. if (interactiveRectangle != null)
  351. interactiveRectangle.Enable();
  352. }
  353. }
  354. }
  355. //================================================================================
  356. //
  357. //================================================================================
  358. protected void EnableNavigation(string gotoName)
  359. {
  360. if (m_NavigationRectangles != null)
  361. {
  362. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  363. {
  364. if (interactiveRectangle != null && interactiveRectangle.GetActionParameter(0) == gotoName)
  365. {
  366. interactiveRectangle.Enable();
  367. break;
  368. }
  369. }
  370. }
  371. }
  372. //================================================================================
  373. //
  374. //================================================================================
  375. protected void DisableNavigationAll()
  376. {
  377. if (m_NavigationRectangles != null)
  378. {
  379. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  380. {
  381. if (interactiveRectangle != null)
  382. interactiveRectangle.Disable();
  383. }
  384. }
  385. }
  386. //================================================================================
  387. //
  388. //================================================================================
  389. protected void DisableNavigation(string gotoName)
  390. {
  391. if (m_NavigationRectangles != null)
  392. {
  393. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  394. {
  395. if (interactiveRectangle != null && interactiveRectangle.GetActionParameter(0) == gotoName)
  396. {
  397. interactiveRectangle.Disable();
  398. break;
  399. }
  400. }
  401. }
  402. }
  403. //================================================================================
  404. //
  405. //================================================================================
  406. protected void RestorePreviousIsEnabledNavigationAll()
  407. {
  408. if (m_NavigationRectangles != null)
  409. {
  410. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  411. {
  412. if (interactiveRectangle != null)
  413. interactiveRectangle.RestorePreviousIsEnabled();
  414. }
  415. }
  416. }
  417. //================================================================================
  418. //
  419. //================================================================================
  420. public virtual void OnLevelChanged()
  421. {
  422. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnLevelChanged()...");
  423. }
  424. //================================================================================
  425. //
  426. //================================================================================
  427. public virtual void OnPopupClose()
  428. {
  429. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnPopupClose()...");
  430. }
  431. //================================================================================
  432. //
  433. //================================================================================
  434. public virtual void OnMapClose()
  435. {
  436. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnMapClose()...");
  437. }
  438. //================================================================================
  439. //
  440. //================================================================================
  441. public virtual void OnVideoClose()
  442. {
  443. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnVideoClose()...");
  444. this.gameObject.SetActive(true);
  445. AudioManager.Instance().PlayCurrentBGM();
  446. if (m_IsPlayingSequence)
  447. {
  448. if (IsPreviousSequenceIndexValid())
  449. {
  450. if (m_CurrentSequence[m_CurrentSequenceIndex - 1].EventType == EventSequenceItem.EventSequenceType.Video)
  451. {
  452. ProcessSequence();
  453. }
  454. }
  455. }
  456. }
  457. //================================================================================
  458. //
  459. //================================================================================
  460. public virtual void OnChesterOpened()
  461. {
  462. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnChesterOpened()...");
  463. }
  464. //================================================================================
  465. //
  466. //================================================================================
  467. public virtual void OnChesterClosed()
  468. {
  469. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnChesterClosed()...");
  470. }
  471. //================================================================================
  472. //
  473. //================================================================================
  474. protected virtual void OnRightItemUsedInScene(ItemEnum item)
  475. {
  476. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnRightItemUsedInScene()...");
  477. Chester.Instance().Close();
  478. }
  479. //================================================================================
  480. //
  481. //================================================================================
  482. protected virtual void OnWrongItemUsedInScene(ItemEnum item)
  483. {
  484. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnWrongItemUsedInScene()...");
  485. CharactersCommon[] characters = {
  486. CharactersCommon.Sam,
  487. CharactersCommon.Reader,
  488. CharactersCommon.Sam,
  489. CharactersCommon.Reader,
  490. CharactersCommon.Reader
  491. };
  492. string[] possibleNumbers = { "7010", "7011", "7012", "7013" };//, "7014" };
  493. int randomValue = Random.Range(0, possibleNumbers.Length);
  494. NewSequence();
  495. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, characters[randomValue], possibleNumbers[randomValue]);
  496. StartSequence(1);
  497. }
  498. //================================================================================
  499. //
  500. //================================================================================
  501. public void ChesterSpeechRubberBandNone()
  502. {
  503. NewSequence();
  504. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, CharactersCommon.Reader, "7451");
  505. StartSequence(1);
  506. }
  507. //================================================================================
  508. //
  509. //================================================================================
  510. public void ChesterSpeechHoopNone()
  511. {
  512. NewSequence();
  513. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, CharactersCommon.Reader, "7450");
  514. StartSequence(1);
  515. }
  516. //================================================================================
  517. //
  518. //================================================================================
  519. public void ChesterSpeechPillowNone()
  520. {
  521. NewSequence();
  522. SetSequence(0, EventSequenceItem.EventSequenceType.Speech, CharactersCommon.Sam, "7452");
  523. StartSequence(1);
  524. }
  525. //================================================================================
  526. //
  527. //================================================================================
  528. protected virtual void OnNavigation()
  529. {
  530. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnNavigation()...");
  531. if (m_CurrentInteractiveRectangle.IsEnabled())
  532. {
  533. // Player clicked on an enabled navigation rectangle; start fading. When fade is finished, we load the level inside FinishedFadeOut().
  534. KishiTechUnity.ScreenFade.ScreenFade.Instance().StartFading(KishiTechUnity.ScreenFade.ScreenFade.FadeType.FadeOut, 0.25f);
  535. }
  536. else
  537. {
  538. // Player tried to navigate to a blocked location. We might want to give the player some feedback.
  539. OnBlockedNavigation();
  540. }
  541. }
  542. //================================================================================
  543. //
  544. //================================================================================
  545. protected virtual void OnBlockedNavigation()
  546. {
  547. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnBlockedNavigation()...");
  548. }
  549. //================================================================================
  550. //
  551. //================================================================================
  552. protected virtual void OnCharacterInteraction()
  553. {
  554. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterInteraction()...");
  555. if (m_CurrentInteractiveRectangle.GetActionParameter(0) == "Paige")
  556. {
  557. SpeechPaige();
  558. }
  559. else
  560. {
  561. SpeechReader();
  562. }
  563. }
  564. //================================================================================
  565. //
  566. //================================================================================
  567. protected virtual void OnOtherCharacterInteraction()
  568. {
  569. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnOtherCharacterInteraction()...");
  570. }
  571. //================================================================================
  572. //
  573. //================================================================================
  574. public virtual Vector2 GetChesterPosition()
  575. {
  576. return new Vector2(float.Parse(m_ChesterRectangle.GetActionParameter(0)), float.Parse(m_ChesterRectangle.GetActionParameter(1)));
  577. }
  578. //================================================================================
  579. //
  580. //================================================================================
  581. protected virtual void OpenChester(float x, float y)
  582. {
  583. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OpenChester()...");
  584. Chester.Instance().Open(this, x, y);
  585. }
  586. //================================================================================
  587. //
  588. //================================================================================
  589. protected override void FinishedFadeOut()
  590. {
  591. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.FinishedFadeOut()...");
  592. Chester.Instance().CloseInstantly();
  593. KishiTechUnity.Loading.Loading.Instance().Show();
  594. // We know from ProcessAction that this RRInteractiveRectangle is of type kActionTypeLoadLevel, so we called started the fade out there.
  595. // When fade out is over, we load the level defined as Action param 0.
  596. Application.LoadLevel(m_CurrentInteractiveRectangle.GetActionParameter(0));
  597. }
  598. //================================================================================
  599. //
  600. //================================================================================
  601. public virtual void ProcessAction(RRInteractiveRectangle interactiveRectangle)
  602. {
  603. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.ProcessAction()...");
  604. if (Chester.Instance().IsOpened() || Chester.Instance().IsOpening() || Map.Instance().IsOpened())
  605. {
  606. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Cancelling SceneCommon.ProcessAction(): Chester or Map is opened.");
  607. return;
  608. }
  609. m_CurrentInteractiveRectangle = interactiveRectangle;
  610. switch (m_CurrentInteractiveRectangle.GetActionType())
  611. {
  612. case ActionType.Navigation:
  613. {
  614. OnNavigation();
  615. } break;
  616. case ActionType.OtherCharacter:
  617. {
  618. OnOtherCharacterInteraction();
  619. } break;
  620. case ActionType.Character:
  621. {
  622. OnCharacterInteraction();
  623. } break;
  624. case ActionType.Chester:
  625. {
  626. OpenChester(float.Parse(m_CurrentInteractiveRectangle.GetActionParameter(0)), float.Parse(m_CurrentInteractiveRectangle.GetActionParameter(1)));
  627. } break;
  628. }
  629. }
  630. //================================================================================
  631. //
  632. //================================================================================
  633. protected virtual bool CheckHUD()
  634. {
  635. if (m_HUD != null)
  636. {
  637. foreach (HUDCommon hud in m_HUD)
  638. {
  639. if (hud.WasUpAsButton() || hud.DidExitWhileDown())
  640. {
  641. hud.ClearWasUpAsButton();
  642. hud.ClearDidExitWhileDown();
  643. return true;
  644. }
  645. }
  646. }
  647. return false;
  648. }
  649. //================================================================================
  650. //
  651. //================================================================================
  652. protected virtual bool CheckItems()
  653. {
  654. if (m_Items != null)
  655. {
  656. foreach (ItemCommon item in m_Items)
  657. {
  658. if (item.WasUpAsButton())
  659. {
  660. item.ClearWasUpAsButton();
  661. return true;
  662. }
  663. }
  664. }
  665. return false;
  666. }
  667. //================================================================================
  668. //
  669. //================================================================================
  670. protected virtual bool CheckChester(float x, float y)
  671. {
  672. if (m_ChesterRectangle != null && m_ChesterRectangle.GetActionType() == ActionType.Chester)
  673. return m_ChesterRectangle.ExecuteIfPointInside(x, y);
  674. return false;
  675. }
  676. //================================================================================
  677. //
  678. //================================================================================
  679. protected virtual bool CheckCharacters(float x, float y)
  680. {
  681. if (m_CharacterRectangles != null)
  682. {
  683. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  684. {
  685. if (interactiveRectangle.ExecuteIfPointInside(x, y))
  686. return true;
  687. }
  688. }
  689. return false;
  690. }
  691. //================================================================================
  692. //
  693. //================================================================================
  694. protected virtual bool CheckOtherCharacters(float x, float y)
  695. {
  696. if (m_OtherCharacterRectangles != null)
  697. {
  698. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  699. {
  700. if (interactiveRectangle.ExecuteIfPointInside(x, y))
  701. return true;
  702. }
  703. }
  704. return false;
  705. }
  706. //================================================================================
  707. //
  708. //================================================================================
  709. protected virtual bool CheckNavigation(float x, float y)
  710. {
  711. if (PlayerData.Instance().IsPracticeMode())
  712. return false;
  713. if (m_NavigationRectangles != null)
  714. {
  715. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  716. {
  717. if (interactiveRectangle.ExecuteIfPointInside(x, y))
  718. return true;
  719. // For navigation rectangles, we ignore the InteractiveRectangle.IsEnabled flag,
  720. // because when a location is blocked (navigation rectangle is disabled) we
  721. // might need to give the player some feedback.
  722. // We decide what to do inside OnNavigation() method.
  723. if (interactiveRectangle.IsPointInside(x, y) && !interactiveRectangle.IsEnabled())
  724. {
  725. interactiveRectangle.ExecuteCommand();
  726. // We return false so we don't skip the sequenced events feedback.
  727. return false;
  728. }
  729. }
  730. }
  731. return false;
  732. }
  733. //================================================================================
  734. //
  735. //================================================================================
  736. protected virtual void CheckAll(float x, float y)
  737. {
  738. // HUD priority is #1.
  739. bool clickedOnHUD = CheckHUD();
  740. if (!clickedOnHUD)
  741. {
  742. // Chester priority is #2.
  743. bool clickedOnChester = CheckChester(x, y);
  744. if (!clickedOnChester)
  745. {
  746. // Game characters priority is #3.
  747. bool clickedOnCharacter = CheckCharacters(x, y);
  748. if (!clickedOnCharacter)
  749. {
  750. // Other game characters priority is #4.
  751. bool clickedOnOtherCharacter = CheckOtherCharacters(x, y);
  752. if (!clickedOnOtherCharacter)
  753. {
  754. // Item priority is #5.
  755. bool clickedOnItem = CheckItems();
  756. if (!clickedOnItem)
  757. {
  758. // Navigation priority is #6.
  759. if (CheckNavigation(x, y))
  760. {
  761. // We do not skip the Video event. If we did, the player would never see the "From EdgeOfCloudNine to RaingearIsland" and
  762. // "From RaingearIsland to EdgeOfCloudNine" videos (down and up ship videos).
  763. if (m_IsPlayingSequence
  764. && m_IsSequenceSkippable
  765. && IsPreviousSequenceIndexValid()
  766. && m_CurrentSequence[m_CurrentSequenceIndex - 1].EventType != EventSequenceItem.EventSequenceType.Video)
  767. {
  768. SkipSequence();
  769. }
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. //================================================================================
  778. //
  779. //================================================================================
  780. public void CheckAllDown(float x, float y)
  781. {
  782. }
  783. //================================================================================
  784. //
  785. //================================================================================
  786. protected virtual void SetCurrentToChester()
  787. {
  788. if (m_ChesterRectangle != null)
  789. {
  790. m_CurrentInteractiveRectangle = m_ChesterRectangle;
  791. }
  792. }
  793. //================================================================================
  794. //
  795. //================================================================================
  796. protected virtual void SetCurrentToCharacter(string name)
  797. {
  798. if (m_CharacterRectangles != null)
  799. {
  800. foreach (RRInteractiveRectangle interactiveRectangle in m_CharacterRectangles)
  801. {
  802. if (interactiveRectangle.GetActionParameter(0) == name)
  803. {
  804. m_CurrentInteractiveRectangle = interactiveRectangle;
  805. break;
  806. }
  807. }
  808. }
  809. }
  810. //================================================================================
  811. //
  812. //================================================================================
  813. protected virtual void SetCurrentToOtherCharacter(string name)
  814. {
  815. if (m_OtherCharacterRectangles != null)
  816. {
  817. foreach (RRInteractiveRectangle interactiveRectangle in m_OtherCharacterRectangles)
  818. {
  819. if (interactiveRectangle.GetActionParameter(0) == name)
  820. {
  821. m_CurrentInteractiveRectangle = interactiveRectangle;
  822. break;
  823. }
  824. }
  825. }
  826. }
  827. //================================================================================
  828. //
  829. //================================================================================
  830. protected virtual void SetCurrentToNavigation(string name)
  831. {
  832. if (m_NavigationRectangles != null)
  833. {
  834. foreach (RRInteractiveRectangle interactiveRectangle in m_NavigationRectangles)
  835. {
  836. if (interactiveRectangle.GetActionParameter(0) == name)
  837. {
  838. m_CurrentInteractiveRectangle = interactiveRectangle;
  839. break;
  840. }
  841. }
  842. }
  843. }
  844. //================================================================================
  845. //
  846. //================================================================================
  847. protected virtual void OnAnimatorFinished()
  848. {
  849. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnAnimatorFinished()...");
  850. //ProcessSequence();
  851. }
  852. //================================================================================
  853. //
  854. //================================================================================
  855. protected virtual void OnCharacterAnimationFinished(CharacterAnimation character)
  856. {
  857. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterAnimationFinished(" + character + ")...");
  858. if (m_IsPlayingSequence)
  859. {
  860. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterAnimationFinished(" + character + ")...");
  861. if (IsPreviousSequenceIndexValid())
  862. {
  863. int previousSequenceIndex = m_CurrentSequenceIndex - 1;
  864. if (m_CurrentSequence[previousSequenceIndex].EventType == EventSequenceItem.EventSequenceType.Animation
  865. || m_CurrentSequence[previousSequenceIndex].EventType == EventSequenceItem.EventSequenceType.AnimationWithSfx)
  866. {
  867. int characterIndex = (int)m_CurrentSequence[previousSequenceIndex].Values[0];
  868. if (m_CharacterAnimations[characterIndex].Equals(character))
  869. ProcessSequence();
  870. }
  871. }
  872. }
  873. }
  874. //================================================================================
  875. //
  876. //================================================================================
  877. protected virtual void OnCharacterAnimationCustomTimelineEvent1(CharacterAnimation character)
  878. {
  879. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterAnimationCustomTimelineEvent1(" + character + ")...");
  880. }
  881. //================================================================================
  882. //
  883. //================================================================================
  884. protected void DecSpeechCount()
  885. {
  886. if (m_SpeechCount > 0)
  887. --m_SpeechCount;
  888. }
  889. //================================================================================
  890. //
  891. //================================================================================
  892. protected void IncSpeechCount()
  893. {
  894. ++m_SpeechCount;
  895. }
  896. //================================================================================
  897. //
  898. //================================================================================
  899. protected virtual void OnCharacterSpeechFinished(CharacterAnimation character)
  900. {
  901. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterSpeechFinished(" + character + ")...");
  902. DecSpeechCount();
  903. if (m_IsPlayingSequence)
  904. {
  905. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnCharacterSpeechFinished(" + character + ")...");
  906. if (IsPreviousSequenceIndexValid())
  907. {
  908. int previousSequenceIndex = m_CurrentSequenceIndex - 1;
  909. // HACK: When event type is DoubleSpeech, this method will be called twice. So change it from DoubleSpeech to Speech the first time.
  910. // If we do not do this, the next event in the sequence will not work properly.
  911. if (m_CurrentSequence[previousSequenceIndex].EventType == EventSequenceItem.EventSequenceType.DoubleSpeech)
  912. {
  913. m_CurrentSequence[previousSequenceIndex].EventType = EventSequenceItem.EventSequenceType.Speech;
  914. m_CurrentSequence[previousSequenceIndex].Values[0] = m_CurrentSequence[previousSequenceIndex].Values[1];
  915. return;
  916. }
  917. if (m_CurrentSequence[previousSequenceIndex].EventType == EventSequenceItem.EventSequenceType.Speech)
  918. {
  919. int characterIndex = (int)m_CurrentSequence[previousSequenceIndex].Values[0];
  920. //string speechID = m_CurrentSequence[m_CurrentSequenceIndex - 1].Values[1].ToString();
  921. if (m_CharacterAnimations[characterIndex].Equals(character))// && speechID.Equals(m_LastSpeech))
  922. ProcessSequence();
  923. }
  924. }
  925. }
  926. }
  927. //================================================================================
  928. //
  929. //================================================================================
  930. public bool IsSomebodySpeaking()
  931. {
  932. return m_SpeechCount > 0;
  933. }
  934. //================================================================================
  935. //
  936. //================================================================================
  937. public virtual void CharacterTriggerAnimation(int characterIndex, int animationIndex, string triggerName)
  938. {
  939. m_CharacterAnimations[characterIndex].TriggerAnimation(animationIndex, triggerName);
  940. }
  941. //================================================================================
  942. //
  943. //================================================================================
  944. public virtual void CharacterPlaySpeech(int characterIndex, string speechID)
  945. {
  946. m_LastSpeech = speechID;
  947. m_CharacterAnimations[characterIndex].PlaySpeech(m_SpeechFolder, m_LastSpeech);
  948. IncSpeechCount();
  949. }
  950. //================================================================================
  951. //
  952. //================================================================================
  953. public virtual void CharacterPlayDoubleSpeech(int characterIndex, int characterIndex2, string speechID)
  954. {
  955. m_LastSpeech = speechID;
  956. m_CharacterAnimations[characterIndex].PlaySpeech(m_SpeechFolder, m_LastSpeech);
  957. m_CharacterAnimations[characterIndex2].PlaySpeechAnimationOnly(m_SpeechFolder, m_LastSpeech);
  958. IncSpeechCount();
  959. IncSpeechCount();
  960. }
  961. //================================================================================
  962. //
  963. //================================================================================
  964. public virtual void CharacterPlaySpeechAnimationOnly(int characterIndex, string speechID)
  965. {
  966. m_LastSpeech = speechID;
  967. m_CharacterAnimations[characterIndex].PlaySpeechAnimationOnly(m_SpeechFolder, m_LastSpeech);
  968. IncSpeechCount();
  969. }
  970. //================================================================================
  971. //
  972. //================================================================================
  973. public string SpeechFolder
  974. {
  975. get { return m_SpeechFolder; }
  976. }
  977. //================================================================================
  978. //
  979. //================================================================================
  980. public bool IsPlayingSequence()
  981. {
  982. return m_IsPlayingSequence;
  983. }
  984. //================================================================================
  985. //
  986. //================================================================================
  987. public bool IsSkippingCurrentSequence()
  988. {
  989. return m_SkipCurrentSequence;
  990. }
  991. //================================================================================
  992. //
  993. //================================================================================
  994. public virtual void SpeechReader()
  995. {
  996. }
  997. //================================================================================
  998. //
  999. //================================================================================
  1000. public virtual void ReaderRandomSpeech(bool ignoreSomebodySpeaking)
  1001. {
  1002. }
  1003. //================================================================================
  1004. //
  1005. //================================================================================
  1006. public virtual void SamRandomSpeech(bool ignoreSomebodySpeaking)
  1007. {
  1008. }
  1009. //================================================================================
  1010. //
  1011. //================================================================================
  1012. public virtual void SpeechPaige()
  1013. {
  1014. }
  1015. //================================================================================
  1016. //
  1017. //================================================================================
  1018. public virtual void PaigeRandomSpeech(bool ignoreSomebodySpeaking)
  1019. {
  1020. }
  1021. //================================================================================
  1022. //
  1023. //================================================================================
  1024. public void DisableColliders()
  1025. {
  1026. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.DisableColliders()...");
  1027. foreach (ItemCommon item in m_Items)
  1028. item.Disable();
  1029. foreach (HUDCommon hud in m_HUD)
  1030. hud.Disable();
  1031. DisableNavigationAll();
  1032. }
  1033. //================================================================================
  1034. //
  1035. //================================================================================
  1036. public void RestoreColliders()
  1037. {
  1038. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.RestoreColliders()...");
  1039. foreach (ItemCommon item in m_Items)
  1040. {
  1041. //item.RestorePrevious();
  1042. item.Enable();
  1043. item.ClearWasUpAsButton();
  1044. }
  1045. foreach (HUDCommon hud in m_HUD)
  1046. {
  1047. //hud.RestorePrevious();
  1048. hud.Enable();
  1049. hud.ClearWasUpAsButton();
  1050. }
  1051. RestorePreviousIsEnabledNavigationAll();
  1052. // We are assuming that RestoreColliders is called when map or Chester is closed.
  1053. m_DelayForNextClick = Time.time + DELAY_NEXT_CLICK;
  1054. }
  1055. //================================================================================
  1056. //
  1057. //================================================================================
  1058. protected void SetSequence(int index, EventSequenceItem.EventSequenceType eventSequenceType, params System.Object[] values)
  1059. {
  1060. if (index <= m_CurrentSequence.Length) {
  1061. m_CurrentSequence [index].Setup (eventSequenceType, values);
  1062. } else {
  1063. Debug.Log("Something goes wrong: " + index);
  1064. }
  1065. }
  1066. //================================================================================
  1067. //
  1068. //================================================================================
  1069. protected void SetSequence(int index, EventSequenceItem.EventSequenceType eventSequenceType, System.Action callback, params System.Object[] values)
  1070. {
  1071. m_CurrentSequence[index].Setup(eventSequenceType, callback, values);
  1072. }
  1073. //================================================================================
  1074. //
  1075. //================================================================================
  1076. protected void SetSequenceCallbackWithParameters(int index, EventSequenceItem.EventSequenceType eventSequenceType, System.Action<System.Object[]> callback, params System.Object[] values)
  1077. {
  1078. m_CurrentSequence[index].SetupCallbackWithParameters(eventSequenceType, callback, values);
  1079. }
  1080. //================================================================================
  1081. //
  1082. //================================================================================
  1083. bool IsPreviousSequenceIndexValid()
  1084. {
  1085. return m_CurrentSequenceIndex < m_CurrentSequence.Length && m_CurrentSequenceIndex > 0;
  1086. }
  1087. //================================================================================
  1088. //
  1089. //================================================================================
  1090. protected void NewSequence()
  1091. {
  1092. if (m_IsPlayingSequence)
  1093. SkipSequence();
  1094. }
  1095. //================================================================================
  1096. //
  1097. //================================================================================
  1098. protected void StartSequence(int sequenceItems, bool isSequenceSkippable = true)
  1099. {
  1100. if (PlayVideo.Instance().IsOpened())
  1101. {
  1102. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("StartSequence not started - Video is opened!");
  1103. return;
  1104. }
  1105. if (m_IsPlayingSequence)
  1106. {
  1107. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("There is a sequence being played, skipping to start a new one...");
  1108. SkipSequence();
  1109. }
  1110. m_CurrentSequenceItems = Mathf.Min(sequenceItems, m_EventSequenceMaxItems);
  1111. m_CurrentSequenceIndex = 0;
  1112. m_IsPlayingSequence = true;
  1113. m_SkipCurrentSequence = false;
  1114. m_SequenceStartTime = Time.time;
  1115. m_IsSequenceSkippable = isSequenceSkippable;
  1116. ProcessSequence();
  1117. }
  1118. //================================================================================
  1119. //
  1120. //================================================================================
  1121. protected void SkipSequence()
  1122. {
  1123. m_SkipCurrentSequence = true;
  1124. for (int i = 0; i < m_CharacterAnimations.Length; ++i)
  1125. m_CharacterAnimations[i].StopSpeech();
  1126. if (Chester.Instance().IsOpening())// || Chester.Instance().IsOpened())
  1127. Chester.Instance().CloseInstantly();
  1128. if (IsPreviousSequenceIndexValid())
  1129. {
  1130. // There is a video playing in the current sequence event.
  1131. if (m_CurrentSequence[m_CurrentSequenceIndex - 1].EventType == EventSequenceItem.EventSequenceType.Video)
  1132. {
  1133. PlayVideo.Instance().Stop();
  1134. }
  1135. }
  1136. ProcessSequence();
  1137. }
  1138. //================================================================================
  1139. //
  1140. //================================================================================
  1141. protected void ProcessSequence()
  1142. {
  1143. if (m_SkipCurrentSequence)
  1144. {
  1145. for (int i = m_CurrentSequenceIndex; i < m_CurrentSequenceItems; ++i)
  1146. {
  1147. if (m_CurrentSequence[i].DidProcess || m_CurrentSequence[i].EventType == EventSequenceItem.EventSequenceType.Unknown)
  1148. continue;
  1149. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("ProcessSequence: " + m_CurrentSequenceIndex + ", " + m_CurrentSequence[m_CurrentSequenceIndex]);
  1150. m_CurrentSequence[i].DidProcess = true;
  1151. if (m_CurrentSequence[i].EventType == EventSequenceItem.EventSequenceType.Callback)
  1152. {
  1153. if (m_CurrentSequence[i].Callback != null)
  1154. m_CurrentSequence[i].Callback();
  1155. }
  1156. else if (m_CurrentSequence[i].EventType == EventSequenceItem.EventSequenceType.CallbackWithParameters)
  1157. {
  1158. if (m_CurrentSequence[i].CallbackWithParameters != null)
  1159. m_CurrentSequence[i].CallbackWithParameters(m_CurrentSequence[i].Values.ToArray());
  1160. }
  1161. else if (m_CurrentSequence[i].EventType == EventSequenceItem.EventSequenceType.Video)
  1162. {
  1163. VideoType videoType = (VideoType)m_CurrentSequence[i].Values[0];
  1164. if ((int)videoType < (int)VideoType.Quantity)
  1165. PlayerData.Instance().UnlockVideo(videoType);
  1166. }
  1167. }
  1168. OnSequenceFinished();
  1169. return;
  1170. }
  1171. if (m_CurrentSequenceIndex < m_CurrentSequenceItems)
  1172. {
  1173. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("ProcessSequence: " + m_CurrentSequenceIndex + ", " + m_CurrentSequence[m_CurrentSequenceIndex]);
  1174. bool callProcessSequence = false;
  1175. m_CurrentSequence[m_CurrentSequenceIndex].DidProcess = true;
  1176. switch (m_CurrentSequence[m_CurrentSequenceIndex].EventType)
  1177. {
  1178. case EventSequenceItem.EventSequenceType.Speech:
  1179. CharacterPlaySpeech((int)m_CurrentSequence[m_CurrentSequenceIndex].Values[0],
  1180. m_CurrentSequence[m_CurrentSequenceIndex].Values[1].ToString());
  1181. break;
  1182. case EventSequenceItem.EventSequenceType.Animation:
  1183. CharacterTriggerAnimation((int)m_CurrentSequence[m_CurrentSequenceIndex].Values[0],
  1184. (int)m_CurrentSequence[m_CurrentSequenceIndex].Values[1],
  1185. m_CurrentSequence[m_CurrentSequenceIndex].Values[2].ToString());
  1186. break;
  1187. case EventSequenceItem.EventSequenceType.AnimationWithSfx:
  1188. CharacterTriggerAnimation((int)m_CurrentSequence[m_CurrentSequenceIndex].Values[0],
  1189. (int)m_CurrentSequence[m_CurrentSequenceIndex].Values[1],
  1190. m_CurrentSequence[m_CurrentSequenceIndex].Values[2].ToString());
  1191. AudioManager.Instance().PlaySFX(m_CurrentSequence[m_CurrentSequenceIndex].Values[3].ToString());
  1192. break;
  1193. case EventSequenceItem.EventSequenceType.AnimationNoWait:
  1194. callProcessSequence = true;
  1195. CharacterTriggerAnimation((int)m_CurrentSequence[m_CurrentSequenceIndex].Values[0],
  1196. (int)m_CurrentSequence[m_CurrentSequenceIndex].Values[1],
  1197. m_CurrentSequence[m_CurrentSequenceIndex].Values[2].ToString());
  1198. break;
  1199. case EventSequenceItem.EventSequenceType.Callback:
  1200. callProcessSequence = true;
  1201. if (m_CurrentSequence[m_CurrentSequenceIndex].Callback != null)
  1202. m_CurrentSequence[m_CurrentSequenceIndex].Callback();
  1203. break;
  1204. case EventSequenceItem.EventSequenceType.CallbackWithParameters:
  1205. callProcessSequence = true;
  1206. if (m_CurrentSequence[m_CurrentSequenceIndex].CallbackWithParameters != null)
  1207. m_CurrentSequence[m_CurrentSequenceIndex].CallbackWithParameters(m_CurrentSequence[m_CurrentSequenceIndex].Values.ToArray());
  1208. break;
  1209. case EventSequenceItem.EventSequenceType.Video:
  1210. //callProcessSequence = true;
  1211. VideoType videoType = (VideoType)m_CurrentSequence[m_CurrentSequenceIndex].Values[0];
  1212. if ((int)videoType < (int)VideoType.Quantity)
  1213. PlayerData.Instance().UnlockVideo(videoType);
  1214. this.gameObject.SetActive(false);
  1215. AudioManager.Instance().StopBGM();
  1216. PlayVideo.Instance().LoadAndPlay(this, videoType, null, PlayerPrefs.GetInt("language"));
  1217. break;
  1218. case EventSequenceItem.EventSequenceType.DoubleSpeech:
  1219. CharacterPlayDoubleSpeech((int)m_CurrentSequence[m_CurrentSequenceIndex].Values[0],
  1220. (int)m_CurrentSequence[m_CurrentSequenceIndex].Values[1],
  1221. m_CurrentSequence[m_CurrentSequenceIndex].Values[2].ToString());
  1222. break;
  1223. case EventSequenceItem.EventSequenceType.GetItem:
  1224. callProcessSequence = true;
  1225. break;
  1226. case EventSequenceItem.EventSequenceType.UseItem:
  1227. callProcessSequence = true;
  1228. break;
  1229. case EventSequenceItem.EventSequenceType.Unknown:
  1230. callProcessSequence = true;
  1231. KishiTechUnity.KishiTechDebug.KTDebug.Instance().LogWarning("ProcessSequence --- processed an Unknown sequence. Is that correct???");
  1232. break;
  1233. }
  1234. ++m_CurrentSequenceIndex;
  1235. if (callProcessSequence)
  1236. ProcessSequence();
  1237. }
  1238. else
  1239. {
  1240. OnSequenceFinished();
  1241. }
  1242. }
  1243. //================================================================================
  1244. //
  1245. //================================================================================
  1246. protected virtual void OnSequenceFinished()
  1247. {
  1248. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Calling SceneCommon.OnSequenceFinished()...");
  1249. KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("m_SkipCurrentSequence: " + m_SkipCurrentSequence);
  1250. for (int i = 0; i < m_EventSequenceMaxItems; ++i)
  1251. m_CurrentSequence[i].Reset();
  1252. m_CurrentSequenceItems = 0;
  1253. m_CurrentSequenceIndex = 0;
  1254. m_IsPlayingSequence = false;
  1255. m_SkipCurrentSequence = false;
  1256. }
  1257. //================================================================================
  1258. //
  1259. //================================================================================
  1260. protected virtual void OnIdle()
  1261. {
  1262. }
  1263. //================================================================================
  1264. //
  1265. //================================================================================
  1266. protected void UpdateIdleDelay()
  1267. {
  1268. m_IdleDelay = Time.time + m_MinIdleDelay;
  1269. }
  1270. //================================================================================
  1271. //
  1272. //================================================================================
  1273. protected void TimeToNextInput() //mycode --rafael --> use this to avoid constant clicks.
  1274. {
  1275. if (!canPressInput) {
  1276. clockToResetInput -= Time.deltaTime;
  1277. if (clockToResetInput <= TIME_FINAL){
  1278. clockToResetInput = TIME_TO_RESET;
  1279. canPressInput = true;
  1280. }
  1281. }
  1282. }
  1283. //================================================================================
  1284. //
  1285. //================================================================================
  1286. protected override void Update()
  1287. {
  1288. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().Update();
  1289. // Chester, Options and Map have priority over game scene when it is opened.
  1290. if (!m_CanUpdate
  1291. || Time.time <= m_DelayForNextClick
  1292. || Chester.Instance().IsOpening()
  1293. || Options.Instance().IsOpened()
  1294. || Map.Instance ().IsOpened()
  1295. )
  1296. return;
  1297. //=====
  1298. // TODO: REMOVE ME - temp code (for debug purposes).
  1299. if (Input.GetKeyDown(KeyCode.F6))
  1300. {
  1301. //PlayerData.Instance().CheatAllItemsInInventory();
  1302. }
  1303. if (Time.time > m_IdleDelay && !m_IsPlayingSequence)
  1304. {
  1305. OnIdle();
  1306. UpdateIdleDelay();
  1307. }
  1308. if (Input.GetMouseButtonDown(KishiTechUnity.KTInput.MouseButton.kLeft) || Input.GetMouseButtonUp(KishiTechUnity.KTInput.MouseButton.kLeft))
  1309. UpdateIdleDelay();
  1310. // A sequence is playing.
  1311. if (m_IsPlayingSequence)
  1312. {
  1313. if (m_IsSequenceSkippable)
  1314. {
  1315. if (Time.time > m_SequenceStartTime + m_SequenceWaitDelayBeforeSkip)
  1316. {
  1317. if (Input.GetMouseButtonUp(KishiTechUnity.KTInput.MouseButton.kLeft))
  1318. {
  1319. SkipSequence();
  1320. return;
  1321. }
  1322. }
  1323. }
  1324. else
  1325. {
  1326. return;
  1327. }
  1328. }
  1329. // Chester has priority over game scene when it is open.
  1330. if (Chester.Instance().IsOpened())
  1331. {
  1332. clockToResetInput = TIME_FINAL; //mycode --rafael --> use this to reset clock. Without this, while chester is opened, the time is fronzen.
  1333. if (Item.isDragingItem == true || Chester.isDragingChester == true){// my code --rafael. Isto evita o bug de arrastar o baú ou item quando algum personagem fala.
  1334. SkipSequence();
  1335. }
  1336. Chester.Instance().CheckLocker(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  1337. if (Input.GetMouseButtonDown(KishiTechUnity.KTInput.MouseButton.kLeft))
  1338. {
  1339. //KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Input.mousePosition.x = " + Input.mousePosition.x + ", Input.mousePosition.y = " + Input.mousePosition.y + ", Screen.height - Input.mousePosition.y = " + (Screen.height - Input.mousePosition.y));
  1340. Chester.Instance().CheckAllDown(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  1341. }
  1342. else if (Input.GetMouseButtonUp(KishiTechUnity.KTInput.MouseButton.kLeft))
  1343. {
  1344. //KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Input.mousePosition.x = " + Input.mousePosition.x + ", Input.mousePosition.y = " + Input.mousePosition.y + ", Screen.height - Input.mousePosition.y = " + (Screen.height - Input.mousePosition.y));
  1345. Chester.Instance().CheckAll(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  1346. }
  1347. return;
  1348. }
  1349. if (Input.GetMouseButton (KishiTechUnity.KTInput.MouseButton.kLeft)) {
  1350. KishiTechUnity.KishiTechDebug.KTDebug.Instance ().Log ("Input.mousePosition.x = " + Input.mousePosition.x + ", Input.mousePosition.y = " + Input.mousePosition.y + ", Screen.height - Input.mousePosition.y = " + (Screen.height - Input.mousePosition.y));
  1351. CheckAllDown (Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  1352. } else if (Input.GetMouseButtonUp (KishiTechUnity.KTInput.MouseButton.kLeft) && canPressInput) { //mycode --rafael --> add canPressInput to condition.
  1353. canPressInput = false; //mycode --rafael
  1354. //KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Input.mousePosition.x = " + Input.mousePosition.x + ", Input.mousePosition.y = " + Input.mousePosition.y + ", Screen.height - Input.mousePosition.y = " + (Screen.height - Input.mousePosition.y));
  1355. CheckAll (Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  1356. }
  1357. TimeToNextInput (); //mycode --rafael
  1358. }
  1359. } // public class public class SceneCommon : KishiTechUnity.ScreenResolution.SceneRoot
  1360. } // namespace ReaderRabbit