StoryDialogView.cs 46 KB

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