DressUpObj.cs 28 KB

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