DressUpObj.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using System.Linq;
  5. using ET;
  6. using FairyGUI;
  7. using ProtoBuf.Meta;
  8. namespace GFGGame
  9. {
  10. public enum DressUpOption
  11. {
  12. Auto,
  13. Add,
  14. Remove
  15. }
  16. //用于换装对象的数据存储和方法封装
  17. public class DressUpObj
  18. {
  19. public int bgId
  20. {
  21. get
  22. {
  23. return _dressUpData.bgId;
  24. }
  25. }
  26. public int suitId
  27. {
  28. get
  29. {
  30. return _dressUpData.suitId;
  31. }
  32. }
  33. public int actionId
  34. {
  35. get
  36. {
  37. return _dressUpData.actionId;
  38. }
  39. }
  40. public bool IsAction
  41. {
  42. get
  43. {
  44. return _dressUpData.actionId > 0;
  45. }
  46. }
  47. public List<int> itemList
  48. {
  49. get
  50. {
  51. return _dressUpData.itemList.ToList();
  52. }
  53. }
  54. private Action onUpdateAction;
  55. /// <summary>
  56. ///
  57. /// </summary>
  58. /// <param name="sceneObj"></param>
  59. /// <param name="needSetMask"></param>
  60. /// <param name="showSceneType"></param>
  61. /// <param name="roleObj"></param>
  62. /// <param name="showBg"></param>
  63. /// <param name="resetData">是否重置装备数据</param>
  64. public void setSceneObj(GameObject sceneObj, bool needSetMask = false, bool showSceneType = true, GameObject roleObj = null, bool showBg = true, Action onUpdateAction = null)
  65. {
  66. if (_sceneObj != null && _sceneObj != sceneObj)
  67. {
  68. PrefabManager.Instance.Restore(_sceneObj);
  69. }
  70. _sceneObj = sceneObj;
  71. _needSetMask = needSetMask;
  72. _showSceneType = showSceneType;
  73. _showBg = showBg;
  74. _roleObj = roleObj;
  75. this.onUpdateAction = onUpdateAction;
  76. if (_dressUpData.IsNew)
  77. {
  78. PutOnDefaultDressUpData(_showBg);
  79. }
  80. else
  81. {
  82. var tempData = DressUpDataClone();
  83. TakeOffAll(false);
  84. PutOnDressUpData(tempData);
  85. }
  86. Timers.inst.AddUpdate(OnUpdate);
  87. }
  88. public DressUpData DressUpDataClone()
  89. {
  90. return _dressUpData.Clone();
  91. }
  92. public void Dispose()
  93. {
  94. _sceneObj = null;
  95. _dressUpData = null;
  96. Timers.inst.Remove(OnUpdate);
  97. foreach (var t in handlers)
  98. {
  99. t.Release();
  100. }
  101. onUpdateAction = null;
  102. }
  103. private void ClearView()
  104. {
  105. Timers.inst.Remove(OnUpdate);
  106. foreach (var t in handlers)
  107. {
  108. t.Cancel();
  109. t.Release();
  110. }
  111. }
  112. //传入一个服装部件Id,判断是否有与此部件同类型服装已穿着
  113. public bool CheckSameTypeIsOn(int itemId)
  114. {
  115. int subType = ItemUtilCS.GetItemSubType(itemId);
  116. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  117. {
  118. int _subType = ItemUtilCS.GetItemSubType(_dressUpData.itemList[i]);
  119. if (subType == _subType) return true;
  120. }
  121. return false;
  122. }
  123. /// <summary>
  124. /// 仅判断换装部件是否已穿着
  125. /// </summary>
  126. /// <param name="itemId"></param>
  127. /// <returns></returns>
  128. public bool CheckDressUpItemIsOn(int itemId)
  129. {
  130. if (itemId == _dressUpData.bgId)
  131. {
  132. return true;
  133. }
  134. return _dressUpData.itemList.Contains(itemId);
  135. }
  136. /// <summary>
  137. /// 仅判断套装是否穿上
  138. /// </summary>
  139. /// <param name="id"></param>
  140. /// <returns></returns>
  141. public bool CheckSuitIsOn(int id)
  142. {
  143. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  144. if (suitCfg == null)
  145. {
  146. return false;
  147. }
  148. int[] items = suitCfg.partsArr;
  149. foreach (int itemId in items)
  150. {
  151. if (_dressUpData.actionId == id)
  152. {
  153. if (SuitCfgArray.Instance.CheckActionContainsItem(itemId, id))
  154. {
  155. continue;
  156. }
  157. }
  158. bool isOn = CheckDressUpItemIsOn(itemId);
  159. if (!isOn)
  160. {
  161. return false;
  162. }
  163. }
  164. return true;
  165. }
  166. public void AddOrRemove(int itemId, bool checkDefault, DressUpOption dressUpOption = DressUpOption.Auto)
  167. {
  168. int subType = ItemUtilCS.GetItemSubType(itemId);
  169. if (subType == ConstDressUpItemType.BEI_JING)
  170. {
  171. if (!_showBg)
  172. {
  173. return;
  174. }
  175. _dressUpData.bgId = itemId;
  176. List<DressUpLayerOperation> handlers = DressUpUtil.AddItemAsync(_dressUpData.bgId, _sceneObj, _needSetMask, true, _roleObj);
  177. TryAddHandlers(handlers);
  178. }
  179. else
  180. {
  181. if (!CheckDressUpItemIsOn(itemId))
  182. {
  183. if (dressUpOption != DressUpOption.Remove)
  184. {
  185. if (checkDefault)
  186. {
  187. TryCancelActionWhenPutOn(itemId);
  188. }
  189. CheckRemoveSameType(subType);
  190. Add(itemId);
  191. }
  192. }
  193. else
  194. {
  195. if (dressUpOption != DressUpOption.Add)
  196. {
  197. Remove(itemId);
  198. }
  199. }
  200. if (checkDefault)
  201. {
  202. checkDefaultItem();
  203. }
  204. }
  205. }
  206. //脱掉所有换装,换成默认装(不处理背景)
  207. public void TakeOffAll(bool checkDefault = true)
  208. {
  209. if(_sceneObj == null)
  210. {
  211. return;
  212. }
  213. _dressUpData.suitId = 0;
  214. _dressUpData.actionId = 0;
  215. foreach (int itemID in itemList)
  216. {
  217. AddOrRemove(itemID, false, DressUpOption.Remove);
  218. }
  219. if (checkDefault)
  220. {
  221. checkDefaultItem();
  222. }
  223. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  224. // FightDataManager.Instance.score = roleLevelCfg.baseScore;
  225. // foreach (int itemId in _dressUpData.itemList)
  226. // {
  227. // FightDataManager.Instance.score += ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  228. // }
  229. }
  230. //穿上或脱掉一个动作
  231. public void PutOnOrTakeOffAction(int actionId)
  232. {
  233. if (_dressUpData.actionId == actionId)
  234. {
  235. CancelAction();
  236. }
  237. else
  238. {
  239. PutOnAction(actionId);
  240. }
  241. }
  242. /// <summary>
  243. /// 尝试穿戴配置套装
  244. /// </summary>
  245. /// <param name="suitId">套装id</param>
  246. /// <param name="tryShowAction">尝试穿上动作</param>
  247. /// <param name="excludeType">排除类型列表</param>
  248. /// <param name="showOptional">是否显示可选部件</param>
  249. /// <param name="CheckOwn">是否只显示主角拥有的部件</param>
  250. public void PutOnSuitCfg(int suitId, bool tryShowAction, int[] excludeType = null, bool showOptional = true, bool CheckOwn = true,bool isDress = false)
  251. {
  252. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  253. if(suitCfg == null)
  254. {
  255. return;
  256. }
  257. bool oldIsAction = IsAction;
  258. _dressUpData.suitId = suitId;
  259. bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasActionRes(_dressUpData.suitId);
  260. _dressUpData.actionId = (hasSuitActionRes && tryShowAction) ? suitId : 0;
  261. //找到要穿的散件
  262. List<int> targetItemList = DressUpUtil.GetSuitItems(suitId, IsAction, excludeType, showOptional, CheckOwn, isDress);
  263. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  264. checkDefaultItem();
  265. }
  266. /// <summary>
  267. /// 取消动作,默认直接脱下
  268. /// </summary>
  269. /// <param name="changeToStand">转换成站立动作</param>
  270. /// <param name="excludeType">转换成站立动作时排除一些类型不穿</param>
  271. public void CancelAction(bool changeToStand = false, int[] excludeType = null)
  272. {
  273. if (_dressUpData.actionId <= 0)
  274. {
  275. return;
  276. }
  277. var tempActionId = _dressUpData.actionId;
  278. _dressUpData.actionId = 0;
  279. //更新非场景类型部件形态
  280. foreach (int itemId in itemList)
  281. {
  282. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  283. {
  284. //场景类型不受动作影响并且本来就有动画,对非场景类型处理
  285. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  286. if (notInAction)
  287. {
  288. //更新成图片模式
  289. Update(itemId);
  290. }
  291. }
  292. }
  293. if (changeToStand)
  294. {
  295. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(tempActionId);
  296. List<int> items = new List<int>(suitCfg.partsArr);
  297. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  298. {
  299. items.AddRange(suitCfg.partsOptionalArr);
  300. }
  301. foreach (int itemId in items)
  302. {
  303. if (DressUpMenuItemDataManager.CheckHasItem(itemId))
  304. {
  305. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  306. if (!notInAction)
  307. {
  308. int subType = ItemDataManager.GetItemSubType(itemId);
  309. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  310. {
  311. AddOrRemove(itemId, false, DressUpOption.Add);
  312. }
  313. }
  314. }
  315. }
  316. }
  317. checkDefaultItem();
  318. }
  319. //穿戴一组换装数据
  320. public void PutOnDressUpData(DressUpData targetDressUpData, int[] excludeType = null)
  321. {
  322. bool oldIsAction = IsAction;
  323. _dressUpData.suitId = targetDressUpData.suitId;
  324. _dressUpData.actionId = targetDressUpData.actionId;
  325. var targetItemList = new List<int>();
  326. foreach(var itemId in targetDressUpData.itemList)
  327. {
  328. int subType = ItemUtilCS.GetItemSubType(itemId);
  329. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  330. {
  331. targetItemList.Add(itemId);
  332. }
  333. }
  334. if (targetDressUpData.bgId > 0 && (excludeType == null || Array.IndexOf(excludeType, ConstDressUpItemType.BEI_JING) < 0))
  335. {
  336. targetItemList.Add(targetDressUpData.bgId);
  337. }
  338. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  339. checkDefaultItem();
  340. }
  341. //穿戴默认换装数据
  342. public void PutOnDefaultDressUpData(bool bgType = false)
  343. {
  344. var dressUpData = DressUpData.CreateDefault();
  345. if (bgType) {
  346. dressUpData.bgId = 180002;
  347. }
  348. PutOnDressUpData(dressUpData);
  349. }
  350. //穿戴一组散件数据(会脱掉不包含的部分)
  351. public void PutOnItemList(List<int> targetItemList)
  352. {
  353. bool oldIsAction = IsAction;
  354. _dressUpData.suitId = 0;
  355. _dressUpData.actionId = 0;
  356. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  357. checkDefaultItem();
  358. }
  359. #region private
  360. private GameObject _sceneObj;
  361. private GameObject _roleObj;
  362. private bool _needSetMask;
  363. private bool _showSceneType = true;
  364. private bool _showBg = true;
  365. private DressUpData _dressUpData = new DressUpData();
  366. private List<DressUpOperationBase> handlers = new List<DressUpOperationBase>();
  367. //穿上一个动作
  368. private void PutOnAction(int actionId)
  369. {
  370. bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasActionRes(actionId);
  371. _dressUpData.actionId = actionId;
  372. if (hasSuitActionRes)
  373. {
  374. foreach (int itemId in itemList)
  375. {
  376. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  377. {
  378. //场景类型不受动作影响并且本来就有动画,对非场景类型处理
  379. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  380. if (notInAction)
  381. {
  382. //更新成动画模式
  383. Update(itemId);
  384. }
  385. else
  386. {
  387. AddOrRemove(itemId, false, DressUpOption.Remove);
  388. }
  389. }
  390. }
  391. }
  392. else
  393. {
  394. CancelAction(true);
  395. }
  396. checkDefaultItem();
  397. }
  398. //当穿一件部件时检查是否需要取消动作,如果需要则取消该动作
  399. private void TryCancelActionWhenPutOn(int itemId)
  400. {
  401. if (_dressUpData.actionId > 0)
  402. {
  403. bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableOnAction(itemId, _dressUpData.actionId);
  404. if (!replaceableByAction)
  405. {
  406. CancelAction();
  407. _dressUpData.actionId = 0;
  408. }
  409. }
  410. }
  411. private void Add(int itemId)
  412. {
  413. if (!_showSceneType)
  414. {
  415. if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  416. {
  417. return;
  418. }
  419. }
  420. if (!_dressUpData.itemList.Contains(itemId))
  421. {
  422. _dressUpData.itemList.Add(itemId);
  423. Update(itemId);
  424. if (actionId != 0)
  425. {
  426. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  427. Transform effGameobj = _sceneObj.transform.Find(string.Format("Role/Body_eff/{0}", itemCfg.res));
  428. if (effGameobj != null)
  429. {
  430. if (effGameobj.gameObject != null)
  431. {
  432. effGameobj.gameObject.SetActive(true);
  433. }
  434. }
  435. }
  436. }
  437. }
  438. private void Update(int itemId)
  439. {
  440. bool showAni = IsAction || DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId);
  441. var handlers = DressUpUtil.AddItemAsync(itemId, _sceneObj, _needSetMask, showAni, _roleObj);
  442. TryAddHandlers(handlers);
  443. }
  444. private void Remove(int itemId)
  445. {
  446. if (_dressUpData.itemList == null)
  447. {
  448. return;
  449. }
  450. if (_dressUpData.itemList.Contains(itemId))
  451. {
  452. _dressUpData.itemList.Remove(itemId);
  453. var handler = DressUpUtil.RemoveItemAsync(itemId, _sceneObj, _roleObj);
  454. TryAddHandler(handler);
  455. if (actionId != 0)
  456. {
  457. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  458. Transform effGameobj = _sceneObj.transform.Find(string.Format("Role/Body_eff/{0}", itemCfg.res));
  459. if (effGameobj != null)
  460. {
  461. if (effGameobj.gameObject != null)
  462. {
  463. effGameobj.gameObject.SetActive(false);
  464. }
  465. }
  466. }
  467. }
  468. }
  469. private void CheckRemoveSameType(int subType)
  470. {
  471. ItemTypeCfg itemTypeCfg = ItemTypeCfgArray.Instance.GetCfg(subType);
  472. int count = 0;
  473. int firstTeshuId = 0;
  474. int maxNum = 1;
  475. if(itemTypeCfg != null && itemTypeCfg.maxNum > 0)
  476. {
  477. maxNum = itemTypeCfg.maxNum;
  478. }
  479. else if(subType > ConstDressUpItemType.TE_SHU)
  480. {
  481. maxNum = 3;
  482. }
  483. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  484. {
  485. int itemID = (int)_dressUpData.itemList[i];
  486. int itemSubType = ItemUtilCS.GetItemSubType(itemID);
  487. bool isSameType = false;
  488. if(itemTypeCfg != null && itemTypeCfg.maxNum > 0)
  489. {
  490. if(itemSubType == subType)
  491. {
  492. isSameType = true;
  493. }
  494. }
  495. else if (subType > ConstDressUpItemType.TE_SHU && itemSubType > ConstDressUpItemType.TE_SHU)
  496. {
  497. isSameType = true;
  498. }
  499. else if (itemSubType == subType
  500. || (subType == ConstDressUpItemType.LIAN_YI_QUN && (itemSubType == ConstDressUpItemType.SHANG_YI || itemSubType == ConstDressUpItemType.XIA_ZHUANG || itemSubType == ConstDressUpItemType.NEI_DA))
  501. || (subType == ConstDressUpItemType.SHANG_YI && itemSubType == ConstDressUpItemType.LIAN_YI_QUN)
  502. || (subType == ConstDressUpItemType.XIA_ZHUANG && itemSubType == ConstDressUpItemType.LIAN_YI_QUN)
  503. || (subType == ConstDressUpItemType.NEI_DA && itemSubType == ConstDressUpItemType.LIAN_YI_QUN))
  504. {
  505. Remove(itemID);
  506. i--;
  507. }
  508. if (isSameType)
  509. {
  510. if (count == 0)
  511. {
  512. firstTeshuId = itemID;
  513. }
  514. count++;
  515. }
  516. }
  517. if (count >= maxNum)
  518. {
  519. //超出允许的件数会顶掉第一件
  520. Remove(firstTeshuId);
  521. }
  522. }
  523. //与身上的散件对比差异然后添加
  524. private void CompareAndAddItemList(bool oldIsAction, bool newIsAction, List<int> targetItemList)
  525. {
  526. bool actionStatusChanged = (oldIsAction && !newIsAction) || (!oldIsAction && newIsAction);
  527. foreach (int itemID in itemList)
  528. {
  529. if (!targetItemList.Contains(itemID))
  530. {
  531. //移除不穿的部件
  532. AddOrRemove(itemID, false, DressUpOption.Remove);
  533. }
  534. else if (actionStatusChanged)
  535. {
  536. //当动画形态切换时
  537. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID))
  538. {
  539. //非场景类型重穿
  540. Update(itemID);
  541. targetItemList.Remove(itemID);
  542. }
  543. }
  544. }
  545. foreach (int itemID in targetItemList)
  546. {
  547. AddOrRemove(itemID, false, DressUpOption.Add);
  548. }
  549. }
  550. //检测当前穿戴是否是一件完整套装,且只穿了一件套装,返回套装id
  551. private int CheckCurDressIsSuit()
  552. {
  553. var suitId = 0;
  554. var suitIdList = new List<int>();
  555. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  556. {
  557. int itemSuitId = SuitCfgArray.Instance.GetSuitIdOfItem(_dressUpData.itemList[i]);
  558. if (!suitIdList.Contains(itemSuitId))
  559. {
  560. suitIdList.Add(itemSuitId);
  561. }
  562. }
  563. foreach (var itemSuitId in suitIdList)
  564. {
  565. if (CheckSuitIsOn(itemSuitId))
  566. {
  567. suitId = itemSuitId;
  568. break;
  569. }
  570. }
  571. _dressUpData.suitId = suitId;
  572. return _dressUpData.suitId;
  573. }
  574. private void checkDefaultItem()
  575. {
  576. //是否有头发
  577. bool hasFaXing = false;
  578. //检查默认资源
  579. //是否有连衣裙
  580. int itemIdLianYiQun = 0;
  581. //是否有内搭
  582. bool hasNeiDa = false;
  583. //是否有上衣
  584. bool hasShangYi = false;
  585. //是否有下装
  586. bool hasXiaZhuang = false;
  587. //是否有默认内搭
  588. bool hasNeiDaDefault = false;
  589. //是否有默认下装
  590. bool hasXiaZhuangDefault = false;
  591. //是否有妆容
  592. bool hasZhuangRong = false;
  593. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  594. {
  595. int itemID = (int)_dressUpData.itemList[i];
  596. int subType = ItemUtilCS.GetItemSubType(itemID);
  597. if (subType == (int)ConstDressUpItemType.FA_XING)
  598. {
  599. hasFaXing = true;
  600. }
  601. else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  602. {
  603. itemIdLianYiQun = itemID;
  604. }
  605. else if (subType == ConstDressUpItemType.NEI_DA)
  606. {
  607. hasNeiDa = true;
  608. }
  609. else if (subType == ConstDressUpItemType.XIA_ZHUANG)
  610. {
  611. hasXiaZhuang = true;
  612. }
  613. else if (subType == ConstDressUpItemType.SHANG_YI)
  614. {
  615. hasShangYi = true;
  616. }
  617. else if (subType == ConstDressUpItemType.ZHUANG_RONG)
  618. {
  619. hasZhuangRong = true;
  620. }
  621. if (itemID == ConstItemID.DEFULT_NEI_DA)
  622. {
  623. hasNeiDaDefault = true;
  624. }
  625. else if (itemID == ConstItemID.DEFULT_XIA_ZHUANG)
  626. {
  627. hasXiaZhuangDefault = true;
  628. }
  629. }
  630. if (!hasFaXing)
  631. {
  632. Add(ConstItemID.DEFULT_FA_XING);
  633. }
  634. if (!IsAction)
  635. {
  636. if (itemIdLianYiQun <= 0)
  637. {
  638. if (!hasShangYi && (!hasNeiDa || hasNeiDaDefault) && (!hasXiaZhuang || hasXiaZhuangDefault))
  639. {
  640. Remove(ConstItemID.DEFULT_XIA_ZHUANG);
  641. Remove(ConstItemID.DEFULT_NEI_DA);
  642. Add(ConstItemID.DEFULT_LIAN_YI_QUN);
  643. }
  644. //else
  645. //{
  646. // if (!hasXiaZhuang)
  647. // {
  648. // Add(ConstItemID.DEFULT_XIA_ZHUANG);
  649. // }
  650. // if (!hasNeiDa)
  651. // {
  652. // Add(ConstItemID.DEFULT_NEI_DA);
  653. // }
  654. //}
  655. }
  656. }
  657. CheckCurDressIsSuit();
  658. var handler = DressUpUtil.UpdateHeadAsync(!hasZhuangRong, _sceneObj, _needSetMask, _roleObj);
  659. TryAddHandler(handler);
  660. UpdateBodyView(itemIdLianYiQun);
  661. }
  662. //更新整个身体
  663. private void UpdateBodyView(int itemIdLianYiQun)
  664. {
  665. string actionRes = null;
  666. if (IsAction)
  667. {
  668. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_dressUpData.actionId);
  669. var hasAniRes = ResPathUtil.CheckDressUpAnimationResExist(suitCfg.aniRes);
  670. actionRes = hasAniRes ? suitCfg.aniRes : null;
  671. }
  672. var handler = DressUpUtil.UpdateBodyAsync(actionRes, _sceneObj, _needSetMask, _roleObj, itemIdLianYiQun);
  673. TryAddHandler(handler);
  674. }
  675. //遍历各部件操作器,检查状态并统一处理
  676. private void OnUpdate(object param = null)
  677. {
  678. if(_sceneObj == null)
  679. {
  680. ClearView();
  681. return;
  682. }
  683. if(handlers != null && handlers.Count > 0)
  684. {
  685. bool draw = true;
  686. foreach(var handler in handlers)
  687. {
  688. if(!handler.IsDone)
  689. {
  690. draw = false;
  691. }
  692. }
  693. if(draw)
  694. {
  695. var t = handlers.ToArray();
  696. handlers.Clear();
  697. foreach (var handler in t)
  698. {
  699. if(handler.Status == YooAsset.EOperationStatus.Succeed)
  700. {
  701. handler.UpdateView();
  702. }
  703. handler.Release();
  704. }
  705. onUpdateAction?.Invoke();
  706. //LogUtil.LogEditor($"draw {TimeHelper.ClientNow()}");
  707. }
  708. }
  709. }
  710. private void TryAddHandlers(List<DressUpLayerOperation> t)
  711. {
  712. if (t != null)
  713. {
  714. foreach(var h in t)
  715. {
  716. TryAddHandler(h);
  717. }
  718. //this.handlers.AddRange(t);
  719. }
  720. }
  721. private void TryAddHandler(DressUpOperationBase t)
  722. {
  723. if (t != null)
  724. {
  725. var len = handlers.Count;
  726. for (var i = len - 1; i >= 0; i--)
  727. {
  728. var h = handlers[i];
  729. if (h.CheckRepeated(t))
  730. {
  731. h.Cancel();
  732. h.Release();
  733. handlers.RemoveAt(i);
  734. }
  735. }
  736. this.handlers.Add(t);
  737. }
  738. }
  739. #endregion
  740. }
  741. }