StoryDialogView.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.Main;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. using System;
  8. using System.Linq;
  9. using YooAsset;
  10. using GFGGame.Launcher;
  11. using UnityEngine.UI;
  12. using System.Threading.Tasks;
  13. using cfg.GfgCfg;
  14. using ET;
  15. namespace GFGGame
  16. {
  17. public delegate void OnCompleteStoryDialogCall(bool isSkip, object param);
  18. public class StoryDialogView : BaseView
  19. {
  20. private UI_StoryDialogUI _ui;
  21. private UI_CompArrow _arrow;
  22. private GameObject _sceneObject;
  23. private GameObject _animObject;
  24. private EffectUI _effectUI1;
  25. private EffectUI _effect;
  26. private DressUpObj _dressUpObj;
  27. private GameObject _dressUpSceneObj;
  28. private GameObject _selfHeadImgObj;
  29. private GTextField _wordTextField;
  30. //剧情完成回调
  31. private OnCompleteStoryDialogCall _onCompleteStoryDialogCall;
  32. private object _onCompleteStoryDialogCallParam;
  33. //回顾
  34. private List<string> _dialogListLookBack;
  35. //自动播放
  36. private int _speedAutoPlay = 1;
  37. private bool _autoPlay = false;
  38. //剧情状态
  39. private List<StoryDialogCfg> _stepListToRead;
  40. private StoryDialogCfg _currentStepCfg;
  41. private string _nextStepId;
  42. private string[] _wordList;
  43. private int _wordIndex = 0;
  44. private bool _isShowLetters;
  45. private bool _canClickBtnNext;
  46. private string _currentWords;
  47. private string _storyStartID;
  48. private string lastTextFieldType; // 上一段文本框的类型
  49. private bool IsTeaParty; //是否是茶话会里的对话
  50. private bool _work; // 对话系统运行状态,true:正常运行; false:停止运行
  51. TypingFadeEffectPro _typingEffect;
  52. //屏幕效果中
  53. private Action<object> _onScreenEffectComplete;
  54. public override void Dispose()
  55. {
  56. if (_sceneObject != null)
  57. {
  58. PrefabManager.Instance.Restore(_sceneObject);
  59. _sceneObject = null;
  60. }
  61. if (_animObject != null)
  62. {
  63. PrefabManager.Instance.Restore(_animObject);
  64. _animObject = null;
  65. }
  66. _wordTextField = null;
  67. _arrow = null;
  68. _isShowLetters = false;
  69. EffectUIPool.Recycle(_effectUI1);
  70. _effectUI1 = null;
  71. EffectUIPool.Recycle(_effect);
  72. _effect = null;
  73. _onScreenEffectComplete = null;
  74. _typingEffect = null;
  75. if (_ui != null)
  76. {
  77. _ui.Dispose();
  78. _ui = null;
  79. }
  80. base.Dispose();
  81. }
  82. protected override void OnInit()
  83. {
  84. base.OnInit();
  85. packageName = UI_StoryDialogUI.PACKAGE_NAME;
  86. _ui = UI_StoryDialogUI.Create();
  87. viewCom = _ui.target;
  88. isfullScreen = true;
  89. isReturnView = true;
  90. _ui.m_dialogText.target.visible = false;
  91. _ui.m_dialogName.target.visible = false;
  92. _ui.m_dialogHead.target.visible = false;
  93. _ui.m_list.visible = false;
  94. _ui.m_btnNext.width = GRoot.inst.width;
  95. _ui.m_btnNext.height = GRoot.inst.height;
  96. _ui.m_mask1.height = (GRoot.inst.height - 1920) / 2;
  97. _ui.m_mask2.height = (GRoot.inst.height - 1920) / 2;
  98. _ui.m_mask1.y = -ViewGlobal.GetRealTopOffset();
  99. _ui.m_mask2.y = GRoot.inst.height - _ui.m_mask2.height - ViewGlobal.GetRealTopOffset();
  100. _ui.m_btnNext.AddRelation(GRoot.inst, RelationType.Size);
  101. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  102. _ui.m_btnNext.onClick.Add(OnClickBtnNext);
  103. _ui.m_btnLookBack.onClick.Add(OnClickBtnLookBack);
  104. _ui.m_btnSkip.onClick.Add(OnBtnSkip);
  105. _ui.m_list.onClickItem.Add(OnClickListItem);
  106. _ui.m_btnSpeedUp.onClick.Add(OnClickBtnSpeedUp);
  107. _ui.m_btnAutoPlay.onClick.Add(OnClickBtnAutoPlay);
  108. }
  109. protected override void OnShown()
  110. {
  111. base.OnShown();
  112. // 初始化
  113. _work = true;
  114. MusicManager.Instance.Stop();
  115. MusicManager.Instance.SetVolume(0);
  116. _ui.m_hideAnimMask.Play();
  117. // 异步加载场景对象
  118. if (_sceneObject == null)
  119. {
  120. PrefabManager.Instance.InstantiateAsync(
  121. ResPathUtil.GetPrefabPath("SceneStoryDialog"),
  122. (go) =>
  123. {
  124. if (go != null)
  125. {
  126. _sceneObject = go;
  127. // 场景加载完成后继续初始化
  128. ContinueAfterSceneLoad();
  129. }
  130. else
  131. {
  132. Debug.LogError("Failed to load SceneStoryDialog");
  133. }
  134. }
  135. );
  136. }
  137. else
  138. {
  139. ContinueAfterSceneLoad();
  140. }
  141. }
  142. private void ContinueAfterSceneLoad()
  143. {
  144. if (_dressUpObj == null)
  145. {
  146. _dressUpObj = new DressUpObj();
  147. }
  148. CreateHeadImg();
  149. _speedAutoPlay = FightDataManager.Instance.dialogSpeed;
  150. lastTextFieldType = "";
  151. UpdateSpeedUpBtn();
  152. _dialogListLookBack = new List<string>();
  153. object[] datas = viewData as object[];
  154. _storyStartID = (string)datas[0];
  155. bool skipable = (bool)datas[1];
  156. _onCompleteStoryDialogCall = (OnCompleteStoryDialogCall)datas[2];
  157. if (datas.Length > 3)
  158. {
  159. _onCompleteStoryDialogCallParam = datas[3];
  160. }
  161. IsTeaParty = (bool)datas[4];
  162. _autoPlay = _lastStartAutoPlay;
  163. //修改需求,所有关卡打开跳过(第一关除外)dd
  164. skipable = true;
  165. if (MainStoryDataManager.currentLevelCfgId == 100001001 &&
  166. !InstanceZonesDataManager.CheckLevelPass(MainStoryDataManager.currentLevelCfgId))
  167. {
  168. skipable = false;
  169. }
  170. _ui.m_btnSkip.visible = skipable;
  171. _ui.m_c1.selectedIndex = 0;
  172. if (_storyStartID == MainStoryDataManager.priorId)
  173. {
  174. _ui.m_c1.selectedIndex = 1;
  175. OnClickBtnAutoPlay();
  176. _speedAutoPlay = 1;
  177. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  178. }
  179. // 茶会修改参数
  180. if (IsTeaParty)
  181. {
  182. _autoPlay = true;
  183. _ui.m_c1.selectedIndex = 2;
  184. _speedAutoPlay = 1;
  185. }
  186. _ui.m_btnAutoPlay.selected = _autoPlay;
  187. _ui.m_btnBack.visible = InstanceZonesDataManager.CheckLevelPass(100001001);
  188. StoryDialogDataManager.Instance.Clear();
  189. InitStepListById(_storyStartID);
  190. // 检查资源的初始化
  191. Timers.inst.StartCoroutine(CheckResLoad());
  192. }
  193. private bool _lastStartAutoPlay = false;
  194. protected override void OnHide()
  195. {
  196. base.OnHide();
  197. _work = false;
  198. Timers.inst.Remove(OnTimerUpDate);
  199. Timers.inst.Remove(UpdateShake);
  200. Timers.inst.Remove(OnScreenEffectComplete);
  201. Timers.inst.Remove(OnWait);
  202. ScreenBlackController.Instance.HideBlack();
  203. // 不是茶话会,则记录上一次自动播放按钮的状态
  204. if (!IsTeaParty)
  205. {
  206. _lastStartAutoPlay = _autoPlay;
  207. }
  208. StopAutoPlay();
  209. VoiceManager.Instance.StopVoice();
  210. if (_sceneObject != null)
  211. {
  212. PrefabManager.Instance.Restore(_sceneObject);
  213. _sceneObject = null;
  214. }
  215. if (_animObject != null)
  216. {
  217. PrefabManager.Instance.Restore(_animObject);
  218. _animObject = null;
  219. }
  220. EffectUIPool.Recycle(_effect);
  221. _effect = null;
  222. _dressUpObj.TakeOffAll();
  223. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  224. _onCompleteStoryDialogCall = null;
  225. _onCompleteStoryDialogCallParam = null;
  226. StoryDialogDataManager.Instance.Clear();
  227. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 3);
  228. DestroyHeadImg();
  229. }
  230. protected override void TryCompleteGuide()
  231. {
  232. base.TryCompleteGuide();
  233. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 3);
  234. }
  235. private void OnClickBtnBack()
  236. {
  237. Over(false);
  238. }
  239. private void OnClickBtnNext()
  240. {
  241. if (!_canClickBtnNext || IsTeaParty)
  242. {
  243. return;
  244. }
  245. StopAutoPlay();
  246. if (_onScreenEffectComplete != null)
  247. {
  248. Timers.inst.Remove(OnScreenEffectComplete);
  249. _onScreenEffectComplete.Invoke(null);
  250. }
  251. else
  252. {
  253. ShowNextWords();
  254. }
  255. }
  256. private void OnClickBtnLookBack()
  257. {
  258. StopAutoPlay();
  259. if (_ui.m_btnSkip.visible)
  260. {
  261. ViewManager.Show<StoryLookBackView>(_storyStartID);
  262. }
  263. else
  264. {
  265. ViewManager.Show<StoryLookBackView>(_dialogListLookBack);
  266. }
  267. }
  268. private void OnBtnSkip()
  269. {
  270. _work = false;
  271. Over(true);
  272. }
  273. private void OnClickListItem(EventContext context)
  274. {
  275. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(context.data as GObject);
  276. _dialogListLookBack.Add(dialogItem.m_txtContent.text);
  277. string stepID = (string)dialogItem.target.data;
  278. if (stepID == null)
  279. {
  280. stepID = "0";
  281. }
  282. UI_ListDialogItem.ProxyEnd();
  283. OnStepComplete(stepID);
  284. }
  285. private void OnClickBtnSpeedUp()
  286. {
  287. //如果没有自动播放先开始自动播放
  288. if (!_autoPlay)
  289. {
  290. _ui.m_btnAutoPlay.selected = true;
  291. OnClickBtnAutoPlay();
  292. }
  293. _speedAutoPlay = _speedAutoPlay * 2;
  294. if (_speedAutoPlay > GameConst.MAX_SPEED_AUTO_PLAY)
  295. {
  296. _speedAutoPlay = 1;
  297. }
  298. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  299. UpdateSpeedUpBtn();
  300. //if (_speedAutoPlay > 1)
  301. //{
  302. // VoiceManager.Instance.StopVoice();
  303. //}
  304. }
  305. private void OnClickBtnAutoPlay()
  306. {
  307. _autoPlay = _ui.m_btnAutoPlay.selected;
  308. if (_autoPlay)
  309. {
  310. ShowNextWords();
  311. }
  312. }
  313. private void InitStepListById(string dialogID)
  314. {
  315. var temp = CommonDataManager.Tables.TblStoryDialogCfg.DataList.Where(a => a.Id == int.Parse(dialogID))
  316. .ToList();
  317. _stepListToRead = new List<StoryDialogCfg>(temp);
  318. }
  319. private void ShowNextStep(string nextStepId)
  320. {
  321. if (!_work)
  322. {
  323. return;
  324. }
  325. if (nextStepId != null)
  326. {
  327. InitStepListById(nextStepId);
  328. }
  329. if (_stepListToRead != null && _stepListToRead.Count > 0)
  330. {
  331. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  332. _stepListToRead.RemoveAt(0);
  333. Timers.inst.StartCoroutine(InitStepContent(storyDialogCfg));
  334. }
  335. else
  336. {
  337. Over();
  338. }
  339. }
  340. private void OnStepComplete(string nextStepId = null)
  341. {
  342. _nextStepId = nextStepId;
  343. _ui.m_dialogText.target.visible = false;
  344. _ui.m_dialogName.target.visible = false;
  345. _ui.m_dialogHead.target.visible = false;
  346. float delay = 0;
  347. bool isWait = false;
  348. //屏幕效果
  349. if (_currentStepCfg != null)
  350. {
  351. if (_currentStepCfg.BlackScreenDur > 0)
  352. {
  353. delay = _currentStepCfg.BlackScreenDur;
  354. ScreenBlackController.Instance.ShowBlack(delay, this.viewCom, 0);
  355. }
  356. if (_currentStepCfg.BlankScreenDur > 0)
  357. {
  358. isWait = true;
  359. delay = _currentStepCfg.BlankScreenDur;
  360. UpdatePic("0");
  361. }
  362. }
  363. if (delay > 0 && !isWait)
  364. {
  365. //转换成秒
  366. delay = delay / 1000f;
  367. _onScreenEffectComplete = OnScreenEffectComplete;
  368. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  369. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  370. }
  371. else if (isWait)
  372. {
  373. float waitTime = delay / 1000f;
  374. _canClickBtnNext = false;
  375. Timers.inst.Add(waitTime, 1, OnWait);
  376. if (_autoPlay)
  377. {
  378. //转换成秒
  379. delay = delay / 1000f;
  380. _onScreenEffectComplete = OnScreenEffectComplete;
  381. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  382. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  383. }
  384. else if (_currentStepCfg.EffectInfo.Count > 0)
  385. {
  386. delay = delay / 1000f;
  387. _onScreenEffectComplete = OnScreenEffectComplete;
  388. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  389. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  390. }
  391. else
  392. {
  393. _onScreenEffectComplete = OnScreenEffectComplete;
  394. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  395. }
  396. }
  397. else
  398. {
  399. OnScreenEffectComplete();
  400. }
  401. }
  402. private void OnWait(object param = null)
  403. {
  404. _canClickBtnNext = true;
  405. Timers.inst.Remove(OnWait);
  406. }
  407. private void OnScreenEffectComplete(object param = null)
  408. {
  409. _onScreenEffectComplete = null;
  410. if (_nextStepId == "0")
  411. {
  412. Over();
  413. }
  414. else
  415. {
  416. ShowNextStep(_nextStepId);
  417. }
  418. }
  419. private IEnumerator InitStepContent(StoryDialogCfg storyDialogCfg)
  420. {
  421. if (!_work)
  422. {
  423. yield break;
  424. }
  425. _canClickBtnNext = false;
  426. StoryDialogDataManager.Instance.waitPicFade = false;
  427. _ui.m_hide.Play(); // 隐藏遮罩
  428. HideAllDialogUI();
  429. // Init resource
  430. _currentStepCfg = storyDialogCfg;
  431. UpdateMusic(storyDialogCfg.MusicRes);
  432. UpdateBg(storyDialogCfg.BgRes);
  433. UpdatePic(storyDialogCfg.PicRes, storyDialogCfg.FaceRes, storyDialogCfg.EmojiRes);
  434. UpdateAnim(storyDialogCfg.AniRes);
  435. UpdateRoleObj(storyDialogCfg.Name);
  436. PlayEffect(storyDialogCfg.EffectInfo);
  437. PlayShake(storyDialogCfg.ShakeInfo);
  438. string content = storyDialogCfg.Content;
  439. content = storyDialogCfg.Content.Replace("self", RoleDataManager.roleName);
  440. while (StoryDialogDataManager.Instance.waitBgChange)
  441. {
  442. //Debug.Log("等待背景转换");
  443. yield return new WaitForEndOfFrame();
  444. }
  445. if (StoryDialogDataManager.Instance.dialogShowDelay > 0)
  446. {
  447. yield return new WaitForSeconds(StoryDialogDataManager.Instance.dialogShowDelay);
  448. StoryDialogDataManager.Instance.dialogShowDelay = 0f;
  449. }
  450. _canClickBtnNext = true;
  451. if (content.IndexOf("//") >= 0)
  452. {
  453. ShowList(content);
  454. }
  455. else
  456. {
  457. Timers.inst.StartCoroutine(ShowDialog(storyDialogCfg));
  458. }
  459. }
  460. private void ShowList(string content)
  461. {
  462. StopAutoPlay();
  463. _ui.m_btnAutoPlay.enabled = false;
  464. _wordTextField = null;
  465. _ui.m_list.visible = true;
  466. _ui.m_list.RemoveChildrenToPool();
  467. string[] list = Regex.Split(content, "//");
  468. _ui.m_list.itemRenderer = (int index, GObject item) =>
  469. {
  470. string itemInfo = list[index];
  471. string[] itemInfoList = Regex.Split(itemInfo, "=");
  472. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  473. dialogItem.m_txtContent.text = itemInfoList[0];
  474. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  475. UI_ListDialogItem.ProxyEnd();
  476. };
  477. _ui.m_list.numItems = list.Length;
  478. }
  479. private void HideAllDialogUI()
  480. {
  481. _ui.m_dialogText.target.visible = false;
  482. _ui.m_dialogName.target.visible = false;
  483. _ui.m_dialogHead.target.visible = false;
  484. _ui.m_list.visible = false;
  485. }
  486. private void OnTimerUpDate(object param = null)
  487. {
  488. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)param;
  489. string headAniRes = storyDialogCfg.HeadAni;
  490. var headAniCfg = CommonDataManager.Tables.TblHeadAniCfg.GetOrDefault(headAniRes);
  491. if (storyDialogCfg.SuitId > 0)
  492. {
  493. _dressUpObj.PutOnSuitCfg(storyDialogCfg.SuitId, false,
  494. new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  495. }
  496. else
  497. {
  498. _dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData,
  499. new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  500. if (_dressUpObj.actionId > 0)
  501. {
  502. _dressUpObj.CancelAction(true, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  503. }
  504. }
  505. _dressUpObj.AddOrRemove(headAniCfg.FaceId, true);
  506. }
  507. /// <summary>
  508. /// 初始化对话框/语音/CG等
  509. /// </summary>
  510. /// <param name="storyDialogCfg"></param>
  511. /// <returns></returns>
  512. private IEnumerator ShowDialog(StoryDialogCfg storyDialogCfg)
  513. {
  514. if (!_work)
  515. {
  516. yield break;
  517. }
  518. if (storyDialogCfg.ShowChangeName == 1 &&
  519. StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  520. {
  521. GameController.ShowCreateRole();
  522. StoryDialogDataManager.Instance.waiting = true;
  523. while (StoryDialogDataManager.Instance.waiting)
  524. {
  525. yield return new WaitForEndOfFrame();
  526. }
  527. //if (_autoPlay)
  528. //{
  529. // _ui.m_btnAutoPlay.selected = false;
  530. // OnClickBtnAutoPlay();
  531. //}
  532. }
  533. _ui.m_loaMask.url = ResPathUtil.GetSceneBgPath(storyDialogCfg.MaskRes);
  534. _ui.m_btnAutoPlay.enabled = true;
  535. _ui.m_list.visible = false;
  536. var content = storyDialogCfg.Content.Replace("self", RoleDataManager.roleName);
  537. string words = content;
  538. string roleName = storyDialogCfg.Name;
  539. string headRes = storyDialogCfg.Head;
  540. string headAniRes = storyDialogCfg.HeadAni;
  541. //List<string> effectInfo = storyDialogCfg.EffectInfo;
  542. VoiceManager.Instance.StopVoice();
  543. // 如果没开倍速才加载语音
  544. if (_speedAutoPlay == 1 || !_autoPlay)
  545. {
  546. // 如果配置了语音,读取语音
  547. VoiceManager.Instance.LoadResAsync(ResPathUtil.GetVoicePath(storyDialogCfg.VoiceRes));
  548. }
  549. _wordList = Regex.Split(words, "&&");
  550. // 有对话
  551. if (_wordList.Length > 0 && !_wordList[0].Equals(""))
  552. {
  553. if (roleName == "self")
  554. {
  555. roleName = RoleDataManager.roleName;
  556. }
  557. //回顾
  558. if (roleName != null)
  559. {
  560. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  561. }
  562. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.SuitId > 0)
  563. {
  564. //显示对话框半身像
  565. _ui.m_dialogHead.m_txtName.text = roleName;
  566. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  567. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  568. _ui.m_dialogHead.m_txtContent.text = "";
  569. var headAniCfg = CommonDataManager.Tables.TblHeadAniCfg.GetOrDefault(headAniRes);
  570. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.HeadAni))
  571. {
  572. //独立动画
  573. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  574. _ui.m_dialogHead.m_comphead.target.visible = true;
  575. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq",
  576. headAniCfg.HeadAni);
  577. }
  578. else
  579. {
  580. //换装
  581. _ui.m_dialogHead.m_comphead.target.visible = false;
  582. //_dressUpObjUI.ResetSceneObj(80, true, false, sceneObject.transform.Find("Scene").gameObject, false);
  583. GRoot.inst.touchable = false;
  584. _dressUpObj.setSceneObj(_dressUpSceneObj, false, false, null, false, ChangeHeadImgLayer);
  585. if (storyDialogCfg.SuitId > 0)
  586. {
  587. _dressUpObj.PutOnSuitCfg(storyDialogCfg.SuitId, false,
  588. new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  589. }
  590. else
  591. {
  592. _dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData,
  593. new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  594. if (_dressUpObj.actionId > 0)
  595. {
  596. _dressUpObj.CancelAction(true, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  597. }
  598. }
  599. if (headAniCfg != null && headAniCfg.FaceId > 0)
  600. {
  601. //表情
  602. _dressUpObj.AddOrRemove(headAniCfg.FaceId, true);
  603. Timers.inst.Add(0.01f, 1, OnTimerUpDate, storyDialogCfg);
  604. }
  605. _ui.m_dialogHead.m_compDressUp.target.visible = true ;
  606. }
  607. _ui.m_dialogHead.target.visible = true;
  608. _wordTextField = _ui.m_dialogHead.m_txtContent;
  609. _arrow = _ui.m_dialogHead.m_iconNext;
  610. lastTextFieldType = "head";
  611. }
  612. else if (!string.IsNullOrEmpty(headRes))
  613. {
  614. _ui.m_dialogHead.target.visible = true;
  615. _ui.m_dialogHead.m_txtName.text = roleName;
  616. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  617. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  618. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  619. _wordTextField = _ui.m_dialogHead.m_txtContent;
  620. _arrow = _ui.m_dialogHead.m_iconNext;
  621. lastTextFieldType = "head";
  622. }
  623. else if (!string.IsNullOrEmpty(roleName))
  624. {
  625. _ui.m_dialogName.target.visible = true;
  626. if (IsTeaParty)
  627. {
  628. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  629. var teapartyRoleCfg =
  630. CommonDataManager.Tables.TblTeapartyRoleCfg.GetGroup1ById(LeagueDataManager.Instance
  631. .TeaPartyId);
  632. int roleIndex = Convert.ToInt32(roleName);
  633. _ui.m_dialogName.m_txtName.text = teapartyRoleCfg[roleIndex - 1].Name;
  634. _ui.m_dialogName.m_bgType.selectedIndex = 1;
  635. _ui.m_dialogName.m_showArrow.selectedIndex = 1;
  636. if (roleIndex <= roleContainerList.Count &&
  637. roleContainerList[roleIndex - 1].MaxScoreRoleName != null &&
  638. roleContainerList[roleIndex - 1].MaxScoreRoleName != "" &&
  639. _ui.m_dialogName.m_txtName.text != "")
  640. {
  641. _ui.m_comPlayName.visible = true;
  642. _ui.m_txtPlayName.text = roleContainerList[roleIndex - 1].MaxScoreRoleName;
  643. if (_ui.m_txtPlayName.text == RoleDataManager.roleName)
  644. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  645. }
  646. else
  647. _ui.m_comPlayName.visible = false;
  648. }
  649. else
  650. {
  651. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  652. _ui.m_dialogName.m_showArrow.selectedIndex = 0;
  653. _ui.m_dialogName.m_txtName.text = roleName;
  654. }
  655. _wordTextField = _ui.m_dialogName.m_txtContent;
  656. _arrow = _ui.m_dialogName.m_iconNext;
  657. if (!lastTextFieldType.Equals("name"))
  658. {
  659. lastTextFieldType = "name";
  660. StoryDialogDataManager.Instance.waiting = true;
  661. _ui.m_t0.Play(() => { StoryDialogDataManager.Instance.waiting = false; });
  662. }
  663. }
  664. else
  665. {
  666. if (IsTeaParty)
  667. _ui.m_dialogText.m_showArrow.selectedIndex = 1;
  668. else
  669. _ui.m_dialogText.m_showArrow.selectedIndex = 0;
  670. _ui.m_dialogText.target.visible = true;
  671. _wordTextField = _ui.m_dialogText.m_txtContent;
  672. _arrow = _ui.m_dialogText.m_iconNext;
  673. lastTextFieldType = "text";
  674. _ui.m_comPlayName.visible = false;
  675. }
  676. _wordIndex = 0;
  677. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  678. _typingEffect.typeFinishedAction = ShowCurrentWords;
  679. ShowNextDialog();
  680. }
  681. else
  682. {
  683. OnStepComplete();
  684. //if (effectInfo.Length > 0)
  685. //{
  686. // // 等待CG播放完毕直接进入下一段
  687. // Timers.inst.StartCoroutine(WaitCGAnimFinish(effectInfo[0], int.Parse(effectInfo[1])));
  688. //}
  689. //// 播放效果等
  690. //else
  691. //{
  692. // OnStepComplete();
  693. //}
  694. }
  695. }
  696. /// <summary>
  697. /// 延迟显示头像,防止换装异步加载/换表情 未完成时显示了头像
  698. /// </summary>
  699. private async void ShowSelfHeadImg()
  700. {
  701. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  702. await Task.Delay(80);
  703. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  704. }
  705. private void ShowNextDialog()
  706. {
  707. if (_wordList != null && _wordList.Length > _wordIndex)
  708. {
  709. string itemInfo = _wordList[_wordIndex];
  710. string[] itemInfoList = Regex.Split(itemInfo, "=");
  711. _currentWords = itemInfoList[0];
  712. if (itemInfoList.Length > 1)
  713. {
  714. _wordTextField.data = itemInfoList[1];
  715. }
  716. else
  717. {
  718. _wordTextField.data = null;
  719. }
  720. Timers.inst.StartCoroutine(StartShowLetters());
  721. }
  722. else
  723. {
  724. OnStepComplete();
  725. }
  726. }
  727. private void ShowCurrentWords()
  728. {
  729. //_arrow.target.visible = true;
  730. //Timers.inst.Remove(UpdateLetters);
  731. StopTyping();
  732. _typingEffect?.Cancel();
  733. _wordTextField.text = _currentWords;
  734. _dialogListLookBack.Add(_currentWords);
  735. _isShowLetters = false;
  736. _wordIndex++;
  737. if (_autoPlay)
  738. {
  739. float interval = Mathf.Max(VoiceManager.Instance.GetClipRemainingLength(),
  740. GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay);
  741. Timers.inst.Add(interval, 1, ShowNextWords);
  742. }
  743. }
  744. private void ShowNextWords(object param = null)
  745. {
  746. if (_wordTextField != null)
  747. {
  748. if (_isShowLetters)
  749. {
  750. ShowCurrentWords();
  751. }
  752. else
  753. {
  754. string stepID = (string)_wordTextField.data;
  755. if (stepID != null)
  756. {
  757. OnStepComplete(stepID);
  758. }
  759. else
  760. {
  761. ShowNextDialog();
  762. }
  763. }
  764. }
  765. }
  766. private IEnumerator StartShowLetters()
  767. {
  768. _isShowLetters = true;
  769. _arrow.target.visible = false;
  770. _wordTextField.verticalAlign = VertAlignType.Top;
  771. _wordTextField.text = "";
  772. _canClickBtnNext = false;
  773. while (StoryDialogDataManager.Instance.waitPicFade || StoryDialogDataManager.Instance.waiting)
  774. {
  775. //Debug.Log("等待立绘/动画结束");
  776. yield return new WaitForEndOfFrame();
  777. }
  778. _canClickBtnNext = true;
  779. _wordTextField.text = _currentWords;
  780. StartTyping();
  781. }
  782. /// <summary>
  783. /// 开启打字机显示
  784. /// </summary>
  785. private void StartTyping()
  786. {
  787. _typingEffect.SetSpeed(_speedAutoPlay);
  788. _typingEffect.Start();
  789. // 如果配置了语音,则播放语音
  790. VoiceManager.Instance.PlayVoice();
  791. }
  792. private void StopTyping()
  793. {
  794. _typingEffect.Cancel();
  795. }
  796. private void UpdateBg(string value)
  797. {
  798. if (value.Length > 0)
  799. {
  800. SceneController.UpdateDialogBg(value, _sceneObject);
  801. }
  802. }
  803. private void UpdatePic(string value, string faceValue = "", string emojiValue = "")
  804. {
  805. if (IsTeaParty) return;
  806. // 同步处理 value
  807. if (value.Length > 0)
  808. {
  809. SceneController.UpdateDialogPic(value, _sceneObject);
  810. }
  811. // 异步处理 faceValue
  812. if (faceValue.Length > 0)
  813. {
  814. SceneController.InitPicFaceAsync(faceValue, _sceneObject, () =>
  815. {
  816. // faceValue 加载完成后处理 emojiValue
  817. if (emojiValue.Length > 0)
  818. {
  819. UpdateLiveEmoji(emojiValue);
  820. }
  821. });
  822. }
  823. else if (emojiValue.Length > 0) // 如果不需要加载 faceValue,直接处理 emoji
  824. {
  825. UpdateLiveEmoji(emojiValue);
  826. }
  827. }
  828. private void UpdateLiveEmoji(string EmojiRes)
  829. {
  830. if (EmojiRes.Length > 0 && !IsTeaParty)
  831. {
  832. SceneController.UpdateEmojiAni(EmojiRes, _animObject);
  833. }
  834. }
  835. private void UpdateAnim(string value)
  836. {
  837. if (value.Length > 0 && !IsTeaParty)
  838. {
  839. if (value == "0")
  840. {
  841. //SceneController.ControlBgVisible(_sceneObject, true);
  842. _ui.m_hideAnimMask.Play();
  843. SceneController.UpdateDialogAnim(value, _animObject);
  844. }
  845. // 播放动画
  846. else
  847. {
  848. SceneController.UpdateDialogAnim(value, _animObject);
  849. _animObject.SetActive(false);
  850. _canClickBtnNext = false;
  851. _ui.m_showMask.Play(() =>
  852. {
  853. //_canClickBtnNext = true;
  854. if (_animObject != null)
  855. {
  856. _ui.m_hideMask.Play();
  857. _ui.m_showAnimMask.Play();
  858. _animObject.SetActive(true);
  859. }
  860. //SceneController.ControlBgVisible(_sceneObject, false);
  861. });
  862. }
  863. }
  864. }
  865. private void UpdateRoleObj(string value)
  866. {
  867. if (IsTeaParty)
  868. {
  869. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  870. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  871. for (int i = 0; i < roleContainerList.Count; i++)
  872. {
  873. if (value == (i + 1).ToString() && roleContainerList[i].EquipIds.Count > 0)
  874. {
  875. MyDressUpHelper.dressUpObj.PutOnItemList(roleContainerList[i].EquipIds);
  876. return;
  877. }
  878. }
  879. MyDressUpHelper.dressUpObj.PutOnDefaultDressUpData(IsTeaParty);
  880. }
  881. }
  882. private void UpdateMusic(string value)
  883. {
  884. if (value.Length > 0)
  885. {
  886. if (value == "0")
  887. {
  888. MusicManager.Instance.Stop();
  889. }
  890. else
  891. {
  892. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"), false, 0.1f);
  893. }
  894. }
  895. }
  896. private void PlayEffect(List<string> value)
  897. {
  898. if (value.Count > 0)
  899. {
  900. if (value[0] == "0")
  901. {
  902. EffectUIPool.Recycle(_effect);
  903. _effect = null;
  904. }
  905. else
  906. {
  907. EffectUIPool.Recycle(_effect);
  908. _effect = null;
  909. string effectPath = string.Format("ui_Juqing/{0}", value[0]);
  910. _effect = EffectUIPool.CreateEffectUI(_ui.m_effect, effectPath, value[0]);
  911. _ui.m_effect.visible = true;
  912. }
  913. }
  914. }
  915. private void PlayShake(List<int> shakeInfoArr)
  916. {
  917. if (shakeInfoArr != null && shakeInfoArr.Count > 0)
  918. {
  919. Vector3 position = _sceneObject.transform.position;
  920. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  921. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  922. _sceneObject.transform.position = position;
  923. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  924. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  925. float interval = (float)shakeInfoArr[4] / 1000;
  926. float duration = (float)shakeInfoArr[5] / 1000;
  927. int repeat = Mathf.RoundToInt(duration / interval);
  928. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  929. }
  930. }
  931. private void UpdateShake(object param)
  932. {
  933. float[] attenuations = param as float[];
  934. float attenuationX = attenuations[0];
  935. float attenuationY = attenuations[1];
  936. Vector3 position = _sceneObject.transform.position;
  937. bool done = false;
  938. bool doneX = false;
  939. float absX = Mathf.Abs(position.x);
  940. if (absX > attenuationX)
  941. {
  942. int dir = (int)(position.x / absX);
  943. position.x = Mathf.Abs(position.x) - attenuationX;
  944. position.x *= -1 * dir;
  945. }
  946. else
  947. {
  948. doneX = true;
  949. position.x = 0;
  950. }
  951. bool doneY = false;
  952. float absY = Mathf.Abs(position.y);
  953. if (absY > attenuationY)
  954. {
  955. int dir = (int)(position.y / absY);
  956. position.y = Mathf.Abs(position.y) - attenuationY;
  957. position.y *= -1 * dir;
  958. }
  959. else
  960. {
  961. doneY = true;
  962. position.y = 0;
  963. }
  964. done = doneX && doneY;
  965. _sceneObject.transform.position = position;
  966. if (done)
  967. {
  968. Timers.inst.Remove(UpdateShake);
  969. }
  970. }
  971. private void Over(bool done = true)
  972. {
  973. if (_onCompleteStoryDialogCall != null)
  974. {
  975. _onCompleteStoryDialogCall(done, _onCompleteStoryDialogCallParam);
  976. }
  977. this.Hide();
  978. }
  979. private void UpdateSpeedUpBtn()
  980. {
  981. if (_speedAutoPlay > 1)
  982. {
  983. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  984. }
  985. else
  986. {
  987. _ui.m_btnSpeedUp.text = "";
  988. }
  989. _typingEffect?.SetSpeed(_speedAutoPlay);
  990. }
  991. private void StopAutoPlay()
  992. {
  993. _autoPlay = false;
  994. _ui.m_btnAutoPlay.selected = false;
  995. Timers.inst.Remove(ShowNextWords);
  996. }
  997. // private IEnumerator WaitCGAnimFinish(string resName, int times = 1)
  998. // {
  999. // GameObject cg = PrefabManager.Instance.InstantiateSync("test");
  1000. // Animator animator = cg.GetComponentInChildren<Animator>();
  1001. // AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
  1002. //
  1003. // yield return new WaitForSeconds(info.length * times);
  1004. // //while (info.normalizedTime < 0.95)
  1005. // //{
  1006. // // info = animator.GetCurrentAnimatorStateInfo(0);
  1007. // // yield return new WaitForSeconds(0.1f);
  1008. // //}
  1009. //
  1010. // PrefabManager.Instance.Restore(cg);
  1011. // OnStepComplete();
  1012. // }
  1013. /// <summary>
  1014. /// 检查资源加载是否完成
  1015. /// </summary>
  1016. private IEnumerator CheckResLoad()
  1017. {
  1018. List<string> resList = new List<string>();
  1019. for (int i = 0; i < _stepListToRead.Count; i++)
  1020. {
  1021. StoryDialogCfg cfg = _stepListToRead[i];
  1022. if (cfg.BgRes.Length > 0 && cfg.BgRes != "0")
  1023. {
  1024. string bgRes = ResPathUtil.GetSceneBgPath(cfg.BgRes);
  1025. if (!resList.Contains(bgRes))
  1026. {
  1027. resList.Add(bgRes);
  1028. }
  1029. }
  1030. if (cfg.AniRes.Length > 0 && cfg.AniRes != "0")
  1031. {
  1032. string res = cfg.AniRes.Split('/')[1];
  1033. string aniRes = ResPathUtil.GetStoryDialogCGPath(cfg.AniRes, res);
  1034. if (!resList.Contains(aniRes))
  1035. {
  1036. resList.Add(aniRes);
  1037. }
  1038. }
  1039. if (cfg.EmojiRes.Length > 0 && cfg.EmojiRes != "0")
  1040. {
  1041. string EmojiPath = string.Format("DressUp/{0}", cfg.EmojiRes);
  1042. string aniRes = ResPathUtil.GetEmojiResPath(EmojiPath, cfg.EmojiRes);
  1043. if (!resList.Contains(aniRes))
  1044. {
  1045. resList.Add(aniRes);
  1046. }
  1047. }
  1048. }
  1049. // 异步加载资源
  1050. ResourceDownloaderOperation downloaderOperation = YooAssets.CreateBundleDownloader(resList.ToArray(), 3, 3);
  1051. if (downloaderOperation.TotalDownloadCount == 0)
  1052. {
  1053. ShowNextStep(_storyStartID);
  1054. yield break;
  1055. }
  1056. ViewManager.Show<LoadingView>();
  1057. LoadingView.Instance.SetDesc("正在加载剧情资源...");
  1058. // 开始异步下载
  1059. downloaderOperation.BeginDownload();
  1060. yield return downloaderOperation;
  1061. // 检测下载结果
  1062. if (downloaderOperation.Status != EOperationStatus.Succeed)
  1063. {
  1064. Alert.Show("下载失败!请检查网络状态后重试。")
  1065. .SetLeftButton(true, "返回", (data) =>
  1066. {
  1067. ViewManager.Hide<LoadingView>();
  1068. Hide();
  1069. });
  1070. yield break;
  1071. }
  1072. // 加载完成
  1073. LoadingView.Instance.SetProgress(100, () =>
  1074. {
  1075. ViewManager.Hide<LoadingView>();
  1076. ShowNextStep(_storyStartID);
  1077. });
  1078. }
  1079. private RenderTexture renderTexure;
  1080. private void CreateHeadImg()
  1081. {
  1082. // 创建render texture
  1083. renderTexure = new RenderTexture(550, 760, 24);
  1084. // 异步加载换装父节点 + 相机
  1085. PrefabManager.Instance.InstantiateAsync(
  1086. ResPathUtil.GetPrefabPath("StoryDialogSelfImg/StoryDialogDressUpObj"),
  1087. (go) =>
  1088. {
  1089. if (go != null)
  1090. {
  1091. _dressUpSceneObj = go;
  1092. Camera camera = _dressUpSceneObj.transform.Find("Camera").GetComponent<Camera>();
  1093. camera.targetTexture = renderTexure;
  1094. // 异步加载RawImg
  1095. PrefabManager.Instance.InstantiateAsync(
  1096. ResPathUtil.GetPrefabPath("StoryDialogSelfImg/Canvas"),
  1097. (canvasGo) =>
  1098. {
  1099. if (canvasGo != null)
  1100. {
  1101. _selfHeadImgObj = canvasGo;
  1102. RawImage rawImage = _selfHeadImgObj.transform.Find("mask/RawImage")
  1103. .GetComponent<RawImage>();
  1104. rawImage.texture = renderTexure;
  1105. // 将RawImg放在FGUI上
  1106. GoWrapper goWrapper = new GoWrapper(_selfHeadImgObj);
  1107. _ui.m_dialogHead.m_compDressUp.m_holder.SetNativeObject(goWrapper);
  1108. }
  1109. else
  1110. {
  1111. Debug.LogError("Failed to load Canvas prefab");
  1112. }
  1113. }
  1114. );
  1115. }
  1116. else
  1117. {
  1118. Debug.LogError("Failed to load DressUpObj prefab");
  1119. }
  1120. }
  1121. );
  1122. }
  1123. private void DestroyHeadImg()
  1124. {
  1125. // 清空render Texture
  1126. Camera camera = _dressUpSceneObj.transform.Find("Camera").GetComponent<Camera>();
  1127. camera.targetTexture = null;
  1128. RawImage rawImage = _selfHeadImgObj.transform.Find("mask/RawImage").GetComponent<RawImage>();
  1129. rawImage.texture = null;
  1130. renderTexure.Release();
  1131. renderTexure = null;
  1132. // 回收人物
  1133. _dressUpObj?.Dispose();
  1134. _dressUpObj = null;
  1135. // 回收RawImage
  1136. if (_selfHeadImgObj != null)
  1137. {
  1138. PrefabManager.Instance.Restore(_selfHeadImgObj);
  1139. _selfHeadImgObj = null;
  1140. }
  1141. // 回收相机预制
  1142. if (_dressUpSceneObj != null)
  1143. {
  1144. PrefabManager.Instance.Restore(_dressUpSceneObj);
  1145. _dressUpSceneObj = null;
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// 修改主角头像组件层级
  1150. /// </summary>
  1151. private void ChangeHeadImgLayer()
  1152. {
  1153. if (_dressUpSceneObj == null)
  1154. {
  1155. return;
  1156. }
  1157. Transform parent = _dressUpSceneObj.transform.Find("Role");
  1158. // HeadImg的层级:6
  1159. ChangeLayer(parent, 6);
  1160. GRoot.inst.touchable = true;
  1161. }
  1162. private void ChangeLayer(Transform transform, int layer)
  1163. {
  1164. if (transform == null)
  1165. {
  1166. return;
  1167. }
  1168. if (transform.childCount > 0)
  1169. {
  1170. for (int i = 0; i < transform.childCount; i++)
  1171. {
  1172. ChangeLayer(transform.GetChild(i), layer);
  1173. }
  1174. transform.gameObject.layer = layer;
  1175. }
  1176. else
  1177. {
  1178. transform.gameObject.layer = layer;
  1179. }
  1180. }
  1181. }
  1182. }