DressUpObj.cs 27 KB

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