StoryDialogView.cs 46 KB

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