StoryDialogView.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq",
  576. headAniCfg.HeadAni,
  577. onComplete: (effect) =>
  578. {
  579. if (effect != null)
  580. {
  581. _effectUI1 = effect;
  582. }
  583. });
  584. }
  585. else
  586. {
  587. //换装
  588. _ui.m_dialogHead.m_comphead.target.visible = false;
  589. //_dressUpObjUI.ResetSceneObj(80, true, false, sceneObject.transform.Find("Scene").gameObject, false);
  590. GRoot.inst.touchable = false;
  591. _dressUpObj.setSceneObj(_dressUpSceneObj, false, false, null, false, ChangeHeadImgLayer);
  592. if (storyDialogCfg.SuitId > 0)
  593. {
  594. _dressUpObj.PutOnSuitCfg(storyDialogCfg.SuitId, false,
  595. new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  596. }
  597. else
  598. {
  599. _dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData,
  600. new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  601. if (_dressUpObj.actionId > 0)
  602. {
  603. _dressUpObj.CancelAction(true, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  604. }
  605. }
  606. if (headAniCfg != null && headAniCfg.FaceId > 0)
  607. {
  608. //表情
  609. _dressUpObj.AddOrRemove(headAniCfg.FaceId, true);
  610. Timers.inst.Add(0.01f, 1, OnTimerUpDate, storyDialogCfg);
  611. }
  612. _ui.m_dialogHead.m_compDressUp.target.visible = true ;
  613. }
  614. _ui.m_dialogHead.target.visible = true;
  615. _wordTextField = _ui.m_dialogHead.m_txtContent;
  616. _arrow = _ui.m_dialogHead.m_iconNext;
  617. lastTextFieldType = "head";
  618. }
  619. else if (!string.IsNullOrEmpty(headRes))
  620. {
  621. _ui.m_dialogHead.target.visible = true;
  622. _ui.m_dialogHead.m_txtName.text = roleName;
  623. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  624. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  625. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  626. _wordTextField = _ui.m_dialogHead.m_txtContent;
  627. _arrow = _ui.m_dialogHead.m_iconNext;
  628. lastTextFieldType = "head";
  629. }
  630. else if (!string.IsNullOrEmpty(roleName))
  631. {
  632. _ui.m_dialogName.target.visible = true;
  633. if (IsTeaParty)
  634. {
  635. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  636. var teapartyRoleCfg =
  637. CommonDataManager.Tables.TblTeapartyRoleCfg.GetGroup1ById(LeagueDataManager.Instance
  638. .TeaPartyId);
  639. int roleIndex = Convert.ToInt32(roleName);
  640. _ui.m_dialogName.m_txtName.text = teapartyRoleCfg[roleIndex - 1].Name;
  641. _ui.m_dialogName.m_bgType.selectedIndex = 1;
  642. _ui.m_dialogName.m_showArrow.selectedIndex = 1;
  643. if (roleIndex <= roleContainerList.Count &&
  644. roleContainerList[roleIndex - 1].MaxScoreRoleName != null &&
  645. roleContainerList[roleIndex - 1].MaxScoreRoleName != "" &&
  646. _ui.m_dialogName.m_txtName.text != "")
  647. {
  648. _ui.m_comPlayName.visible = true;
  649. _ui.m_txtPlayName.text = roleContainerList[roleIndex - 1].MaxScoreRoleName;
  650. if (_ui.m_txtPlayName.text == RoleDataManager.roleName)
  651. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  652. }
  653. else
  654. _ui.m_comPlayName.visible = false;
  655. }
  656. else
  657. {
  658. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  659. _ui.m_dialogName.m_showArrow.selectedIndex = 0;
  660. _ui.m_dialogName.m_txtName.text = roleName;
  661. }
  662. _wordTextField = _ui.m_dialogName.m_txtContent;
  663. _arrow = _ui.m_dialogName.m_iconNext;
  664. if (!lastTextFieldType.Equals("name"))
  665. {
  666. lastTextFieldType = "name";
  667. StoryDialogDataManager.Instance.waiting = true;
  668. _ui.m_t0.Play(() => { StoryDialogDataManager.Instance.waiting = false; });
  669. }
  670. }
  671. else
  672. {
  673. if (IsTeaParty)
  674. _ui.m_dialogText.m_showArrow.selectedIndex = 1;
  675. else
  676. _ui.m_dialogText.m_showArrow.selectedIndex = 0;
  677. _ui.m_dialogText.target.visible = true;
  678. _wordTextField = _ui.m_dialogText.m_txtContent;
  679. _arrow = _ui.m_dialogText.m_iconNext;
  680. lastTextFieldType = "text";
  681. _ui.m_comPlayName.visible = false;
  682. }
  683. _wordIndex = 0;
  684. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  685. _typingEffect.typeFinishedAction = ShowCurrentWords;
  686. ShowNextDialog();
  687. }
  688. else
  689. {
  690. OnStepComplete();
  691. //if (effectInfo.Length > 0)
  692. //{
  693. // // 等待CG播放完毕直接进入下一段
  694. // Timers.inst.StartCoroutine(WaitCGAnimFinish(effectInfo[0], int.Parse(effectInfo[1])));
  695. //}
  696. //// 播放效果等
  697. //else
  698. //{
  699. // OnStepComplete();
  700. //}
  701. }
  702. }
  703. /// <summary>
  704. /// 延迟显示头像,防止换装异步加载/换表情 未完成时显示了头像
  705. /// </summary>
  706. private async void ShowSelfHeadImg()
  707. {
  708. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  709. await Task.Delay(80);
  710. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  711. }
  712. private void ShowNextDialog()
  713. {
  714. if (_wordList != null && _wordList.Length > _wordIndex)
  715. {
  716. string itemInfo = _wordList[_wordIndex];
  717. string[] itemInfoList = Regex.Split(itemInfo, "=");
  718. _currentWords = itemInfoList[0];
  719. if (itemInfoList.Length > 1)
  720. {
  721. _wordTextField.data = itemInfoList[1];
  722. }
  723. else
  724. {
  725. _wordTextField.data = null;
  726. }
  727. Timers.inst.StartCoroutine(StartShowLetters());
  728. }
  729. else
  730. {
  731. OnStepComplete();
  732. }
  733. }
  734. private void ShowCurrentWords()
  735. {
  736. //_arrow.target.visible = true;
  737. //Timers.inst.Remove(UpdateLetters);
  738. StopTyping();
  739. _typingEffect?.Cancel();
  740. _wordTextField.text = _currentWords;
  741. _dialogListLookBack.Add(_currentWords);
  742. _isShowLetters = false;
  743. _wordIndex++;
  744. if (_autoPlay)
  745. {
  746. float interval = Mathf.Max(VoiceManager.Instance.GetClipRemainingLength(),
  747. GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay);
  748. Timers.inst.Add(interval, 1, ShowNextWords);
  749. }
  750. }
  751. private void ShowNextWords(object param = null)
  752. {
  753. if (_wordTextField != null)
  754. {
  755. if (_isShowLetters)
  756. {
  757. ShowCurrentWords();
  758. }
  759. else
  760. {
  761. string stepID = (string)_wordTextField.data;
  762. if (stepID != null)
  763. {
  764. OnStepComplete(stepID);
  765. }
  766. else
  767. {
  768. ShowNextDialog();
  769. }
  770. }
  771. }
  772. }
  773. private IEnumerator StartShowLetters()
  774. {
  775. _isShowLetters = true;
  776. _arrow.target.visible = false;
  777. _wordTextField.verticalAlign = VertAlignType.Top;
  778. _wordTextField.text = "";
  779. _canClickBtnNext = false;
  780. while (StoryDialogDataManager.Instance.waitPicFade || StoryDialogDataManager.Instance.waiting)
  781. {
  782. //Debug.Log("等待立绘/动画结束");
  783. yield return new WaitForEndOfFrame();
  784. }
  785. _canClickBtnNext = true;
  786. _wordTextField.text = _currentWords;
  787. StartTyping();
  788. }
  789. /// <summary>
  790. /// 开启打字机显示
  791. /// </summary>
  792. private void StartTyping()
  793. {
  794. _typingEffect.SetSpeed(_speedAutoPlay);
  795. _typingEffect.Start();
  796. // 如果配置了语音,则播放语音
  797. VoiceManager.Instance.PlayVoice();
  798. }
  799. private void StopTyping()
  800. {
  801. _typingEffect.Cancel();
  802. }
  803. private void UpdateBg(string value)
  804. {
  805. if (value.Length > 0)
  806. {
  807. SceneController.UpdateDialogBg(value, _sceneObject);
  808. }
  809. }
  810. private void UpdatePic(string value, string faceValue = "", string emojiValue = "")
  811. {
  812. if (IsTeaParty) return;
  813. // 同步处理 value
  814. if (value.Length > 0)
  815. {
  816. SceneController.UpdateDialogPic(value, _sceneObject);
  817. }
  818. // 异步处理 faceValue
  819. if (faceValue.Length > 0)
  820. {
  821. SceneController.InitPicFaceAsync(faceValue, _sceneObject, () =>
  822. {
  823. // faceValue 加载完成后处理 emojiValue
  824. if (emojiValue.Length > 0)
  825. {
  826. UpdateLiveEmoji(emojiValue);
  827. }
  828. });
  829. }
  830. else if (emojiValue.Length > 0) // 如果不需要加载 faceValue,直接处理 emoji
  831. {
  832. UpdateLiveEmoji(emojiValue);
  833. }
  834. }
  835. private void UpdateLiveEmoji(string EmojiRes)
  836. {
  837. if (EmojiRes.Length > 0 && !IsTeaParty)
  838. {
  839. SceneController.UpdateEmojiAni(EmojiRes, _animObject);
  840. }
  841. }
  842. private void UpdateAnim(string value)
  843. {
  844. if (value.Length > 0 && !IsTeaParty)
  845. {
  846. if (value == "0")
  847. {
  848. //SceneController.ControlBgVisible(_sceneObject, true);
  849. _ui.m_hideAnimMask.Play();
  850. SceneController.UpdateDialogAnim(value, _animObject);
  851. }
  852. // 播放动画
  853. else
  854. {
  855. SceneController.UpdateDialogAnim(value, _animObject);
  856. _animObject.SetActive(false);
  857. _canClickBtnNext = false;
  858. _ui.m_showMask.Play(() =>
  859. {
  860. //_canClickBtnNext = true;
  861. if (_animObject != null)
  862. {
  863. _ui.m_hideMask.Play();
  864. _ui.m_showAnimMask.Play();
  865. _animObject.SetActive(true);
  866. }
  867. //SceneController.ControlBgVisible(_sceneObject, false);
  868. });
  869. }
  870. }
  871. }
  872. private void UpdateRoleObj(string value)
  873. {
  874. if (IsTeaParty)
  875. {
  876. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  877. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  878. for (int i = 0; i < roleContainerList.Count; i++)
  879. {
  880. if (value == (i + 1).ToString() && roleContainerList[i].EquipIds.Count > 0)
  881. {
  882. MyDressUpHelper.dressUpObj.PutOnItemList(roleContainerList[i].EquipIds);
  883. return;
  884. }
  885. }
  886. MyDressUpHelper.dressUpObj.PutOnDefaultDressUpData(IsTeaParty);
  887. }
  888. }
  889. private void UpdateMusic(string value)
  890. {
  891. if (value.Length > 0)
  892. {
  893. if (value == "0")
  894. {
  895. MusicManager.Instance.Stop();
  896. }
  897. else
  898. {
  899. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"), false, 0.1f);
  900. }
  901. }
  902. }
  903. private void PlayEffect(List<string> value)
  904. {
  905. if (value.Count > 0)
  906. {
  907. if (value[0] == "0")
  908. {
  909. EffectUIPool.Recycle(_effect);
  910. _effect = null;
  911. }
  912. else
  913. {
  914. EffectUIPool.Recycle(_effect);
  915. _effect = null;
  916. string effectPath = string.Format("ui_Juqing/{0}", value[0]);
  917. EffectUIPool.CreateEffectUI(_ui.m_effect, effectPath, value[0],
  918. onComplete: (effect) =>
  919. {
  920. if (effect != null)
  921. {
  922. _effect = effect;
  923. }
  924. });
  925. _ui.m_effect.visible = true;
  926. }
  927. }
  928. }
  929. private void PlayShake(List<int> shakeInfoArr)
  930. {
  931. if (shakeInfoArr != null && shakeInfoArr.Count > 0)
  932. {
  933. Vector3 position = _sceneObject.transform.position;
  934. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  935. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  936. _sceneObject.transform.position = position;
  937. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  938. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  939. float interval = (float)shakeInfoArr[4] / 1000;
  940. float duration = (float)shakeInfoArr[5] / 1000;
  941. int repeat = Mathf.RoundToInt(duration / interval);
  942. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  943. }
  944. }
  945. private void UpdateShake(object param)
  946. {
  947. float[] attenuations = param as float[];
  948. float attenuationX = attenuations[0];
  949. float attenuationY = attenuations[1];
  950. Vector3 position = _sceneObject.transform.position;
  951. bool done = false;
  952. bool doneX = false;
  953. float absX = Mathf.Abs(position.x);
  954. if (absX > attenuationX)
  955. {
  956. int dir = (int)(position.x / absX);
  957. position.x = Mathf.Abs(position.x) - attenuationX;
  958. position.x *= -1 * dir;
  959. }
  960. else
  961. {
  962. doneX = true;
  963. position.x = 0;
  964. }
  965. bool doneY = false;
  966. float absY = Mathf.Abs(position.y);
  967. if (absY > attenuationY)
  968. {
  969. int dir = (int)(position.y / absY);
  970. position.y = Mathf.Abs(position.y) - attenuationY;
  971. position.y *= -1 * dir;
  972. }
  973. else
  974. {
  975. doneY = true;
  976. position.y = 0;
  977. }
  978. done = doneX && doneY;
  979. _sceneObject.transform.position = position;
  980. if (done)
  981. {
  982. Timers.inst.Remove(UpdateShake);
  983. }
  984. }
  985. private void Over(bool done = true)
  986. {
  987. if (_onCompleteStoryDialogCall != null)
  988. {
  989. _onCompleteStoryDialogCall(done, _onCompleteStoryDialogCallParam);
  990. }
  991. this.Hide();
  992. }
  993. private void UpdateSpeedUpBtn()
  994. {
  995. if (_speedAutoPlay > 1)
  996. {
  997. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  998. }
  999. else
  1000. {
  1001. _ui.m_btnSpeedUp.text = "";
  1002. }
  1003. _typingEffect?.SetSpeed(_speedAutoPlay);
  1004. }
  1005. private void StopAutoPlay()
  1006. {
  1007. _autoPlay = false;
  1008. _ui.m_btnAutoPlay.selected = false;
  1009. Timers.inst.Remove(ShowNextWords);
  1010. }
  1011. // private IEnumerator WaitCGAnimFinish(string resName, int times = 1)
  1012. // {
  1013. // GameObject cg = PrefabManager.Instance.InstantiateSync("test");
  1014. // Animator animator = cg.GetComponentInChildren<Animator>();
  1015. // AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
  1016. //
  1017. // yield return new WaitForSeconds(info.length * times);
  1018. // //while (info.normalizedTime < 0.95)
  1019. // //{
  1020. // // info = animator.GetCurrentAnimatorStateInfo(0);
  1021. // // yield return new WaitForSeconds(0.1f);
  1022. // //}
  1023. //
  1024. // PrefabManager.Instance.Restore(cg);
  1025. // OnStepComplete();
  1026. // }
  1027. /// <summary>
  1028. /// 检查资源加载是否完成
  1029. /// </summary>
  1030. private IEnumerator CheckResLoad()
  1031. {
  1032. List<string> resList = new List<string>();
  1033. for (int i = 0; i < _stepListToRead.Count; i++)
  1034. {
  1035. StoryDialogCfg cfg = _stepListToRead[i];
  1036. if (cfg.BgRes.Length > 0 && cfg.BgRes != "0")
  1037. {
  1038. string bgRes = ResPathUtil.GetSceneBgPath(cfg.BgRes);
  1039. if (!resList.Contains(bgRes))
  1040. {
  1041. resList.Add(bgRes);
  1042. }
  1043. }
  1044. if (cfg.AniRes.Length > 0 && cfg.AniRes != "0")
  1045. {
  1046. string res = cfg.AniRes.Split('/')[1];
  1047. string aniRes = ResPathUtil.GetStoryDialogCGPath(cfg.AniRes, res);
  1048. if (!resList.Contains(aniRes))
  1049. {
  1050. resList.Add(aniRes);
  1051. }
  1052. }
  1053. if (cfg.EmojiRes.Length > 0 && cfg.EmojiRes != "0")
  1054. {
  1055. string EmojiPath = string.Format("DressUp/{0}", cfg.EmojiRes);
  1056. string aniRes = ResPathUtil.GetEmojiResPath(EmojiPath, cfg.EmojiRes);
  1057. if (!resList.Contains(aniRes))
  1058. {
  1059. resList.Add(aniRes);
  1060. }
  1061. }
  1062. }
  1063. // 异步加载资源
  1064. ResourceDownloaderOperation downloaderOperation = YooAssets.CreateBundleDownloader(resList.ToArray(), 3, 3);
  1065. if (downloaderOperation.TotalDownloadCount == 0)
  1066. {
  1067. ShowNextStep(_storyStartID);
  1068. yield break;
  1069. }
  1070. ViewManager.Show<LoadingView>();
  1071. LoadingView.Instance.SetDesc("正在加载剧情资源...");
  1072. // 开始异步下载
  1073. downloaderOperation.BeginDownload();
  1074. yield return downloaderOperation;
  1075. // 检测下载结果
  1076. if (downloaderOperation.Status != EOperationStatus.Succeed)
  1077. {
  1078. Alert.Show("下载失败!请检查网络状态后重试。")
  1079. .SetLeftButton(true, "返回", (data) =>
  1080. {
  1081. ViewManager.Hide<LoadingView>();
  1082. Hide();
  1083. });
  1084. yield break;
  1085. }
  1086. // 加载完成
  1087. LoadingView.Instance.SetProgress(100, () =>
  1088. {
  1089. ViewManager.Hide<LoadingView>();
  1090. ShowNextStep(_storyStartID);
  1091. });
  1092. }
  1093. private RenderTexture renderTexure;
  1094. private void CreateHeadImg()
  1095. {
  1096. // 创建render texture
  1097. renderTexure = new RenderTexture(550, 760, 24);
  1098. // 异步加载换装父节点 + 相机
  1099. PrefabManager.Instance.InstantiateAsync(
  1100. ResPathUtil.GetPrefabPath("StoryDialogSelfImg/StoryDialogDressUpObj"),
  1101. (go) =>
  1102. {
  1103. if (go != null)
  1104. {
  1105. _dressUpSceneObj = go;
  1106. Camera camera = _dressUpSceneObj.transform.Find("Camera").GetComponent<Camera>();
  1107. camera.targetTexture = renderTexure;
  1108. // 异步加载RawImg
  1109. PrefabManager.Instance.InstantiateAsync(
  1110. ResPathUtil.GetPrefabPath("StoryDialogSelfImg/Canvas"),
  1111. (canvasGo) =>
  1112. {
  1113. if (canvasGo != null)
  1114. {
  1115. _selfHeadImgObj = canvasGo;
  1116. RawImage rawImage = _selfHeadImgObj.transform.Find("mask/RawImage")
  1117. .GetComponent<RawImage>();
  1118. rawImage.texture = renderTexure;
  1119. // 将RawImg放在FGUI上
  1120. GoWrapper goWrapper = new GoWrapper(_selfHeadImgObj);
  1121. _ui.m_dialogHead.m_compDressUp.m_holder.SetNativeObject(goWrapper);
  1122. }
  1123. else
  1124. {
  1125. Debug.LogError("Failed to load Canvas prefab");
  1126. }
  1127. }
  1128. );
  1129. }
  1130. else
  1131. {
  1132. Debug.LogError("Failed to load DressUpObj prefab");
  1133. }
  1134. }
  1135. );
  1136. }
  1137. private void DestroyHeadImg()
  1138. {
  1139. // 清空render Texture
  1140. Camera camera = _dressUpSceneObj.transform.Find("Camera").GetComponent<Camera>();
  1141. camera.targetTexture = null;
  1142. RawImage rawImage = _selfHeadImgObj.transform.Find("mask/RawImage").GetComponent<RawImage>();
  1143. rawImage.texture = null;
  1144. renderTexure.Release();
  1145. renderTexure = null;
  1146. // 回收人物
  1147. _dressUpObj?.Dispose();
  1148. _dressUpObj = null;
  1149. // 回收RawImage
  1150. if (_selfHeadImgObj != null)
  1151. {
  1152. PrefabManager.Instance.Restore(_selfHeadImgObj);
  1153. _selfHeadImgObj = null;
  1154. }
  1155. // 回收相机预制
  1156. if (_dressUpSceneObj != null)
  1157. {
  1158. PrefabManager.Instance.Restore(_dressUpSceneObj);
  1159. _dressUpSceneObj = null;
  1160. }
  1161. }
  1162. /// <summary>
  1163. /// 修改主角头像组件层级
  1164. /// </summary>
  1165. private void ChangeHeadImgLayer()
  1166. {
  1167. if (_dressUpSceneObj == null)
  1168. {
  1169. return;
  1170. }
  1171. Transform parent = _dressUpSceneObj.transform.Find("Role");
  1172. // HeadImg的层级:6
  1173. ChangeLayer(parent, 6);
  1174. GRoot.inst.touchable = true;
  1175. }
  1176. private void ChangeLayer(Transform transform, int layer)
  1177. {
  1178. if (transform == null)
  1179. {
  1180. return;
  1181. }
  1182. if (transform.childCount > 0)
  1183. {
  1184. for (int i = 0; i < transform.childCount; i++)
  1185. {
  1186. ChangeLayer(transform.GetChild(i), layer);
  1187. }
  1188. transform.gameObject.layer = layer;
  1189. }
  1190. else
  1191. {
  1192. transform.gameObject.layer = layer;
  1193. }
  1194. }
  1195. }
  1196. }