DressUpUtil.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. using UnityEngine;
  2. using Live2D.Cubism.Rendering;
  3. using System.IO;
  4. using UnityEngine.Rendering;
  5. using YooAsset;
  6. using System.Collections.Generic;
  7. using System;
  8. using cfg.GfgCfg;
  9. namespace GFGGame
  10. {
  11. //提供各种换装相关的方法
  12. public class DressUpUtil
  13. {
  14. public const string HEAD_DEFAULT_RES_NAME = "head";
  15. public const string BODY_DEFAULT_RES_NAME = "body";
  16. public const string ROLE_OBJ_NAME = "Role";
  17. public const string HEAD_SPRITE_NAME = "Head";
  18. public const string BODY_SPRITE_NAME = "Body";
  19. public const string BODY_ANIMATION_NAME = "Body_a";
  20. public const string BODY_EFFECT_OBJ_NAME = "Body_eff";
  21. public const string FORMAT_SPRITE_NAME = "I_{0}_s{1}";
  22. public const string FORMAT_ANIMATION_NAME = "I_{0}_a{1}";
  23. public const string FORMAT_EFFECT_OBJ_NAME = "I_{0}_e{1}";
  24. public static List<DressUpLayerOperation> AddItemAsync(int itemID, GameObject sceneObj,
  25. bool needSetMask = false, bool showAni = true, GameObject parentObj = null, int resLayer = 0)
  26. {
  27. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
  28. if (itemCfg == null) return null;
  29. if (parentObj == null)
  30. {
  31. if (itemCfg.SubType == ConstDressUpItemType.BEI_JING ||
  32. DressUpMenuItemCfg1Array.Instance.CheckIsSceneTypeBySubType(itemCfg.SubType))
  33. {
  34. parentObj = sceneObj;
  35. }
  36. else
  37. {
  38. //角色
  39. Transform role = sceneObj.transform.Find(ROLE_OBJ_NAME);
  40. parentObj = role.gameObject;
  41. }
  42. }
  43. showAni = showAni || itemCfg.SubType == ConstDressUpItemType.ZHUANG_RONG;
  44. List<DressUpLayerOperation> handlers = new List<DressUpLayerOperation>();
  45. DressUpLayerOperation handler;
  46. if (resLayer > 0)
  47. {
  48. string layerName = "";
  49. switch (resLayer)
  50. {
  51. case 1:
  52. layerName = itemCfg.ResLayer1;
  53. break;
  54. case 2:
  55. layerName = itemCfg.ResLayer2;
  56. break;
  57. case 3:
  58. layerName = itemCfg.ResLayer3;
  59. break;
  60. }
  61. if (!string.IsNullOrEmpty(layerName))
  62. {
  63. handler = UpdateLayerResAsync(itemCfg, parentObj, resLayer, needSetMask, showAni);
  64. if (handler != null) handlers.Add(handler);
  65. }
  66. }
  67. else
  68. {
  69. //普通层
  70. if (!string.IsNullOrEmpty(itemCfg.ResLayer1))
  71. {
  72. handler = UpdateLayerResAsync(itemCfg, parentObj, 1, needSetMask, showAni);
  73. if (handler != null) handlers.Add(handler);
  74. }
  75. //第二层
  76. if (!string.IsNullOrEmpty(itemCfg.ResLayer2))
  77. {
  78. handler = UpdateLayerResAsync(itemCfg, parentObj, 2, needSetMask, showAni);
  79. if (handler != null) handlers.Add(handler);
  80. }
  81. //第三层
  82. if (!string.IsNullOrEmpty(itemCfg.ResLayer3))
  83. {
  84. handler = UpdateLayerResAsync(itemCfg, parentObj, 3, needSetMask, showAni);
  85. if (handler != null) handlers.Add(handler);
  86. }
  87. }
  88. if (handlers.Count > 0)
  89. {
  90. return handlers;
  91. }
  92. return null;
  93. }
  94. public static string GetSpriteName(ItemCfg itemCfg, int layer)
  95. {
  96. if (itemCfg.SubType == ConstDressUpItemType.BEI_JING)
  97. {
  98. return "Bg";
  99. }
  100. return string.Format(FORMAT_SPRITE_NAME, itemCfg.Id, layer);
  101. }
  102. public static void RemoveItem(int itemID, GameObject parentObj)
  103. {
  104. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
  105. if (itemCfg == null || parentObj == null) return;
  106. string spritObjName;
  107. string aniObjName;
  108. //默认层
  109. if (!string.IsNullOrEmpty(itemCfg.ResLayer1))
  110. {
  111. spritObjName = GetSpriteName(itemCfg, 1);
  112. TryRemoveSprite(parentObj, spritObjName);
  113. aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.Id, 1);
  114. TryRemoveObj(parentObj, aniObjName);
  115. aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.Id, 1);
  116. TryRemoveObj(parentObj, aniObjName);
  117. }
  118. //特殊层
  119. if (!string.IsNullOrEmpty(itemCfg.ResLayer2))
  120. {
  121. spritObjName = GetSpriteName(itemCfg, 2);
  122. TryRemoveSprite(parentObj, spritObjName);
  123. aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.Id, 2);
  124. TryRemoveObj(parentObj, aniObjName);
  125. aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.Id, 2);
  126. TryRemoveObj(parentObj, aniObjName);
  127. }
  128. //第三层
  129. if (!string.IsNullOrEmpty(itemCfg.ResLayer3))
  130. {
  131. spritObjName = GetSpriteName(itemCfg, 3);
  132. TryRemoveSprite(parentObj, spritObjName);
  133. aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.Id, 3);
  134. TryRemoveObj(parentObj, aniObjName);
  135. aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.Id, 3);
  136. TryRemoveObj(parentObj, aniObjName);
  137. }
  138. }
  139. public static DressUpRemoveOperation RemoveItemAsync(int itemID, GameObject sceneObj,
  140. GameObject parentObj = null)
  141. {
  142. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
  143. if (itemCfg == null) return null;
  144. if (parentObj == null)
  145. {
  146. if (itemCfg.SubType == ConstDressUpItemType.BEI_JING ||
  147. DressUpMenuItemCfg1Array.Instance.CheckIsSceneTypeBySubType(itemCfg.SubType))
  148. {
  149. parentObj = sceneObj;
  150. }
  151. else
  152. {
  153. //角色
  154. Transform role = sceneObj.transform.Find(ROLE_OBJ_NAME);
  155. parentObj = role.gameObject;
  156. }
  157. }
  158. var operation = new DressUpRemoveOperation(itemID, parentObj);
  159. operation.Begin();
  160. return operation;
  161. }
  162. public static DressUpLayerOperation UpdateHeadAsync(bool show, GameObject sceneObj, bool needSetMask = false,
  163. GameObject parentObj = null)
  164. {
  165. var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
  166. parentObj = parentObj == null ? roleTf.gameObject : parentObj;
  167. string res = null;
  168. string resPath = null;
  169. if (show)
  170. {
  171. res = HEAD_DEFAULT_RES_NAME;
  172. resPath = ResPathUtil.GetDressUpPath(res);
  173. }
  174. DressUpLayerOperation handler = new DressUpLayerOperation(parentObj, needSetMask, false, resPath, null);
  175. handler.InitHead();
  176. handler.Begin();
  177. return handler;
  178. }
  179. public static DressUpLayerOperation UpdateBodyAsync(string actionRes, GameObject sceneObj,
  180. bool needSetMask = false, GameObject parentObj = null, int itemIdLianYiQun = 0)
  181. {
  182. //角色
  183. var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
  184. parentObj = parentObj == null ? roleTf.gameObject : parentObj;
  185. var extPng = "png";
  186. string resPath = null;
  187. string effectResPath = null;
  188. bool showAni = !string.IsNullOrEmpty(actionRes);
  189. string aniResPath = null;
  190. if (showAni)
  191. {
  192. aniResPath = ResPathUtil.GetDressUpAnimationPath(actionRes);
  193. if (!YooAssets.CheckResExist(aniResPath))
  194. {
  195. showAni = false;
  196. }
  197. }
  198. if (showAni)
  199. {
  200. resPath = aniResPath;
  201. //特效
  202. effectResPath = ResPathUtil.GetDressUpEffectPath(actionRes, true);
  203. if (!YooAssets.CheckResExist(effectResPath))
  204. {
  205. effectResPath = null;
  206. }
  207. }
  208. else
  209. {
  210. bool hideBody = false;
  211. if (itemIdLianYiQun > 0)
  212. {
  213. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemIdLianYiQun);
  214. hideBody = itemCfg.HideBody > 0;
  215. }
  216. if (hideBody)
  217. {
  218. resPath = null;
  219. }
  220. else
  221. {
  222. resPath = ResPathUtil.GetDressUpPath(BODY_DEFAULT_RES_NAME, extPng);
  223. }
  224. }
  225. DressUpLayerOperation handler =
  226. new DressUpLayerOperation(parentObj, needSetMask, showAni, resPath, effectResPath);
  227. handler.InitBody();
  228. handler.Begin();
  229. return handler;
  230. }
  231. private static DressUpLayerOperation UpdateLayerResAsync(ItemCfg itemCfg, GameObject parentObj, int layerId,
  232. bool needSetMask, bool showAni = true)
  233. {
  234. string resPath;
  235. string aniResPath = null;
  236. //根据资源存在与否再次检查是否播放动画
  237. if (showAni)
  238. {
  239. aniResPath = ResPathUtil.GetDressUpLayerAnimationResPath(itemCfg, layerId);
  240. if (!YooAssets.CheckResExist(aniResPath))
  241. {
  242. showAni = false;
  243. }
  244. }
  245. if (showAni)
  246. {
  247. resPath = aniResPath;
  248. }
  249. else
  250. {
  251. resPath = ResPathUtil.GetDressUpLayerSpriteResPath(itemCfg, layerId);
  252. }
  253. if (!YooAssets.CheckResExist(resPath))
  254. {
  255. return null;
  256. }
  257. //特效
  258. string effectResPath = ResPathUtil.GetDressUpLayerEffectResPath(itemCfg, layerId, showAni);
  259. if (!YooAssets.CheckResExist(effectResPath))
  260. {
  261. effectResPath = null;
  262. }
  263. DressUpLayerOperation handler =
  264. new DressUpLayerOperation(parentObj, needSetMask, showAni, resPath, effectResPath);
  265. handler.InitLayer(itemCfg, layerId);
  266. handler.Begin();
  267. return handler;
  268. }
  269. public static void AddSpriteObjAsync(
  270. string resPath,
  271. string objName,
  272. GameObject parentObj,
  273. int sortingOrder,
  274. bool needSetMask,
  275. Action<GameObject> onComplete)
  276. {
  277. // 检查资源是否存在
  278. if (!YooAssets.CheckResExist(resPath))
  279. {
  280. onComplete?.Invoke(null);
  281. return;
  282. }
  283. // 检查是否已存在相同对象
  284. var existedObj = GetGameObjExisted(parentObj, objName, resPath);
  285. if (existedObj != null)
  286. {
  287. onComplete?.Invoke(existedObj);
  288. return;
  289. }
  290. // 查找或创建游戏对象
  291. GameObject gameObj = parentObj.transform.Find(objName)?.gameObject;
  292. if (gameObj == null)
  293. {
  294. gameObj = new GameObject(objName);
  295. gameObj.transform.SetParent(parentObj.transform, false);
  296. }
  297. // 获取或添加SpriteRenderer
  298. SpriteRenderer spr = gameObj.GetComponent<SpriteRenderer>();
  299. if (spr == null)
  300. {
  301. spr = gameObj.AddComponent<SpriteRenderer>();
  302. }
  303. // 异步加载精灵位置
  304. LoadSpritePosAsync(resPath, (tx, ty) =>
  305. {
  306. // 设置位置
  307. gameObj.transform.localPosition = new Vector3(tx, ty, gameObj.transform.localPosition.z);
  308. // 添加精灵
  309. SpriteHelper.AddSpriteTo(spr, resPath);
  310. gameObj.SetActive(true);
  311. spr.sortingOrder = sortingOrder;
  312. // 设置遮罩交互
  313. if (needSetMask)
  314. {
  315. spr.maskInteraction = parentObj.transform.parent != null &&
  316. parentObj.transform.parent.name == "targetRole"
  317. ? SpriteMaskInteraction.VisibleOutsideMask
  318. : SpriteMaskInteraction.VisibleInsideMask;
  319. }
  320. else
  321. {
  322. spr.maskInteraction = SpriteMaskInteraction.None;
  323. }
  324. onComplete?.Invoke(gameObj);
  325. });
  326. }
  327. public static void AddAnimationObjAsync(
  328. string resPath,
  329. string objName,
  330. GameObject parentObj,
  331. int sortingOrder,
  332. Action<GameObject> callback)
  333. {
  334. // 检查已有对象
  335. var gameObj = GetGameObjExisted(parentObj, objName, resPath);
  336. if (gameObj != null)
  337. {
  338. callback?.Invoke(gameObj);
  339. return;
  340. }
  341. // 异步加载预制体
  342. PrefabManager.Instance.SpawnAsync(resPath, (loadedObj) =>
  343. {
  344. if (loadedObj == null)
  345. {
  346. callback?.Invoke(null);
  347. return;
  348. }
  349. if (objName == BODY_ANIMATION_NAME)
  350. {
  351. DressUpOffsetInfo dressUpOffsetInfo = loadedObj.GetComponent<DressUpOffsetInfo>();
  352. if (dressUpOffsetInfo == null)
  353. {
  354. dressUpOffsetInfo = loadedObj.AddComponent<DressUpOffsetInfo>();
  355. dressUpOffsetInfo.OffsetPosition = loadedObj.transform.localPosition;
  356. dressUpOffsetInfo.Rotation = loadedObj.transform.localRotation;
  357. }
  358. parentObj.transform.localPosition = dressUpOffsetInfo.OffsetPosition;
  359. parentObj.transform.rotation = dressUpOffsetInfo.Rotation;
  360. }
  361. // 设置位置和父对象
  362. loadedObj.transform.localPosition = Vector3.zero;
  363. loadedObj.transform.rotation = Quaternion.identity;
  364. loadedObj.name = objName;
  365. loadedObj.transform.SetParent(parentObj.transform, false);
  366. // 设置渲染顺序
  367. var render = loadedObj.GetComponent<CubismRenderController>();
  368. if (render == null && loadedObj.transform.childCount > 0)
  369. {
  370. var childObj = loadedObj.transform.GetChild(0);
  371. if (childObj != null)
  372. {
  373. render = childObj.GetComponent<CubismRenderController>();
  374. }
  375. }
  376. if (render != null && render.gameObject.activeSelf)
  377. {
  378. render.SortingOrder = sortingOrder;
  379. }
  380. SetRenderersOrder(loadedObj, sortingOrder);
  381. callback?.Invoke(loadedObj);
  382. });
  383. }
  384. // public static GameObject AddAnimationObj(string resPath, string objName, GameObject parentObj, int sortingOrder)
  385. // {
  386. // var gameObj = GetGameObjExisted(parentObj, objName, resPath);
  387. // if (gameObj != null)
  388. // {
  389. // return gameObj;
  390. // }
  391. //
  392. // gameObj = PrefabManager.Instance.SpawnSync(resPath);
  393. // if (gameObj == null)
  394. // {
  395. // return null;
  396. // }
  397. //
  398. // if (objName == BODY_ANIMATION_NAME)
  399. // {
  400. // //这里有个需求是一些特殊动作需要自定义位置和角度,
  401. // //实现方法就是美术在动作预制体上设置这个位置,
  402. // //然后程序记录下这个位置,把他设置到role节点上,并把动作节点的位置重置成默认值。
  403. // DressUpOffsetInfo dressUpOffsetInfo = gameObj.GetComponent<DressUpOffsetInfo>();
  404. // if (dressUpOffsetInfo == null)
  405. // {
  406. // dressUpOffsetInfo = gameObj.AddComponent<DressUpOffsetInfo>();
  407. // dressUpOffsetInfo.OffsetPosition = gameObj.transform.localPosition;
  408. // dressUpOffsetInfo.Rotation = gameObj.transform.localRotation;
  409. // }
  410. //
  411. // //如果是动作动画,就根据动画位置及角度信息设置给Role对象
  412. // parentObj.transform.localPosition = dressUpOffsetInfo.OffsetPosition;
  413. // parentObj.transform.rotation = dressUpOffsetInfo.Rotation;
  414. // //.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
  415. // }
  416. //
  417. // gameObj.transform.localPosition = Vector3.zero;
  418. // gameObj.transform.rotation = Quaternion.identity;
  419. // gameObj.name = objName;
  420. // gameObj.transform.SetParent(parentObj.transform, false);
  421. // var render = gameObj.GetComponent<CubismRenderController>();
  422. // if (render == null && gameObj.transform.childCount > 0)
  423. // {
  424. // var childObj = gameObj.transform.GetChild(0);
  425. // if (childObj != null)
  426. // {
  427. // render = childObj.GetComponent<CubismRenderController>();
  428. // }
  429. // }
  430. //
  431. // if (render != null && render.gameObject.activeSelf == true)
  432. // {
  433. // render.SortingOrder = sortingOrder;
  434. // }
  435. //
  436. // SetRenderersOrder(gameObj, sortingOrder);
  437. // return gameObj;
  438. // }
  439. public static GameObject TryAddEffectObj(string resPath, string objName, GameObject parentObj, int sortingOrder)
  440. {
  441. var gameObj = GetGameObjExisted(parentObj, objName, resPath);
  442. if (gameObj != null)
  443. {
  444. return gameObj;
  445. }
  446. gameObj = PrefabManager.Instance.SpawnSync(resPath);
  447. if (gameObj == null)
  448. {
  449. return null;
  450. }
  451. DressUpOffsetInfo dressUpOffsetInfo = gameObj.GetComponent<DressUpOffsetInfo>();
  452. if (dressUpOffsetInfo == null)
  453. {
  454. //这里因为特效资源初始是有位移偏移的,记录下来每次设置为初始位置和角度,以防unity自身的坐标转换导致位置偏移
  455. dressUpOffsetInfo = gameObj.AddComponent<DressUpOffsetInfo>();
  456. dressUpOffsetInfo.OffsetPosition = gameObj.transform.localPosition;
  457. dressUpOffsetInfo.Rotation = gameObj.transform.localRotation;
  458. }
  459. gameObj.transform.localPosition = dressUpOffsetInfo.OffsetPosition;
  460. gameObj.transform.rotation = dressUpOffsetInfo.Rotation;
  461. gameObj.transform.SetParent(parentObj.transform, false);
  462. gameObj.name = objName;
  463. var sortingGroup = gameObj.transform.GetComponent<SortingGroup>();
  464. if (sortingGroup != null)
  465. {
  466. GameObject.Destroy(sortingGroup);
  467. }
  468. SetRenderersOrder(gameObj, sortingOrder + 1); //特效层默认高一个层级
  469. return gameObj;
  470. }
  471. public static bool TryRemoveObj(GameObject parentObj, string objName)
  472. {
  473. if (parentObj == null)
  474. {
  475. return false;
  476. }
  477. Transform transform = parentObj.transform.Find(objName);
  478. if (transform != null)
  479. {
  480. GameObject gameObj = transform.gameObject;
  481. if (gameObj != null)
  482. {
  483. PrefabManager.Instance.Restore(gameObj);
  484. return true;
  485. }
  486. }
  487. return false;
  488. }
  489. public static bool TryRemoveSprite(GameObject parentObj, string objName)
  490. {
  491. if (parentObj == null)
  492. {
  493. return false;
  494. }
  495. Transform transform = parentObj.transform.Find(objName);
  496. if (transform != null)
  497. {
  498. GameObject gameObj = transform.gameObject;
  499. if (gameObj != null)
  500. {
  501. var spr = gameObj.GetComponent<SpriteRenderer>();
  502. if (spr != null)
  503. {
  504. //LogUtil.LogEditor($"TryRemoveSprite {objName}");
  505. SpriteHelper.RemoveSpriteFrom(spr);
  506. gameObj.SetActive(false);
  507. }
  508. return true;
  509. }
  510. }
  511. return false;
  512. }
  513. public static GameObject GetGameObjExisted(GameObject parentObj, string objName, string resPath)
  514. {
  515. if (parentObj == null)
  516. {
  517. return null;
  518. }
  519. Transform transform = parentObj.transform.Find(objName);
  520. if (transform != null)
  521. {
  522. GameObject gameObj = transform.gameObject;
  523. if (gameObj != null)
  524. {
  525. var assetReleaser = gameObj.GetComponent<AssetReleaser>();
  526. if (assetReleaser != null)
  527. {
  528. if (assetReleaser.ResPath == resPath)
  529. {
  530. return gameObj;
  531. }
  532. }
  533. }
  534. }
  535. return null;
  536. }
  537. // public static void LoadSpritePos(string resPath, out float tx, out float ty)
  538. // {
  539. // int index = resPath.LastIndexOf('.');
  540. // resPath = resPath.Substring(0, index) + ".bytes";
  541. // if (YooAssets.CheckResExist(resPath))
  542. // {
  543. // var handle = YooAssets.LoadAssetSync<TextAsset>(resPath);
  544. // TextAsset asset = handle.AssetObject as TextAsset;
  545. // var st = new MemoryStream(asset.bytes);
  546. // var br = new BinaryReader(st);
  547. // tx = br.ReadInt32() / 100f;
  548. // ty = -br.ReadInt32() / 100f;
  549. // handle.Release();
  550. // }
  551. // else
  552. // {
  553. // tx = 0;
  554. // ty = 0;
  555. // }
  556. // }
  557. public static void LoadSpritePosAsync(string resPath, Action<float, float> onComplete)
  558. {
  559. int index = resPath.LastIndexOf('.');
  560. resPath = resPath.Substring(0, index) + ".bytes";
  561. if (YooAssets.CheckResExist(resPath))
  562. {
  563. var handle = YooAssets.LoadAssetAsync<TextAsset>(resPath);
  564. handle.Completed += (operation) =>
  565. {
  566. if (operation.Status == EOperationStatus.Succeed)
  567. {
  568. TextAsset asset = operation.AssetObject as TextAsset;
  569. using (var st = new MemoryStream(asset.bytes))
  570. using (var br = new BinaryReader(st))
  571. {
  572. float tx = br.ReadInt32() / 100f;
  573. float ty = -br.ReadInt32() / 100f;
  574. onComplete?.Invoke(tx, ty);
  575. }
  576. }
  577. else
  578. {
  579. Debug.LogError($"Failed to load position data: {resPath}");
  580. onComplete?.Invoke(0, 0);
  581. }
  582. operation.Release();
  583. };
  584. }
  585. else
  586. {
  587. onComplete?.Invoke(0, 0);
  588. }
  589. }
  590. public static void SetRenderersOrder(GameObject gameObj, int sortingOrder)
  591. {
  592. var meshRenderers = gameObj.transform.GetComponentsInChildren<MeshRenderer>();
  593. for (int i = 0; i < meshRenderers.Length; i++)
  594. {
  595. var renderer = meshRenderers[i].GetComponent<Renderer>();
  596. if (renderer != null)
  597. {
  598. renderer.sortingOrder = sortingOrder;
  599. }
  600. }
  601. ParticleSystem[] particles = gameObj.transform.GetComponentsInChildren<ParticleSystem>();
  602. for (int i = 0; i < particles.Length; i++)
  603. {
  604. var renderer = particles[i].GetComponent<Renderer>();
  605. if (renderer != null)
  606. {
  607. renderer.sortingOrder = sortingOrder;
  608. }
  609. }
  610. var spritesRenderers = gameObj.transform.GetComponentsInChildren<SpriteRenderer>();
  611. for (int i = 0; i < spritesRenderers.Length; i++)
  612. {
  613. var spriteRender = spritesRenderers[i];
  614. spriteRender.sortingOrder = sortingOrder;
  615. }
  616. }
  617. public static List<int> GetSuitItems(int suitId, bool isAction, int[] excludeType = null,
  618. bool showOptional = true, bool CheckOwn = true, bool isDress = false)
  619. {
  620. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(suitId);
  621. if (suitCfg == null)
  622. {
  623. return null;
  624. }
  625. List<int> items = new List<int>(suitCfg.Parts);
  626. if (showOptional)
  627. {
  628. if (suitCfg.PartsOptional != null && suitCfg.PartsOptional.Count > 0)
  629. {
  630. items.AddRange(suitCfg.PartsOptional);
  631. }
  632. }
  633. int subType = 0;
  634. //找到要穿的散件
  635. List<int> targetItemList = new List<int>();
  636. foreach (int itemId in items)
  637. {
  638. if (!CheckOwn || DressUpMenuItemDataManager.CheckHasItem(itemId) || isDress)
  639. {
  640. subType = ItemDataManager.GetItemSubType(itemId);
  641. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  642. if (!isAction || notInAction)
  643. {
  644. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  645. {
  646. targetItemList.Add(itemId);
  647. }
  648. }
  649. }
  650. }
  651. return targetItemList;
  652. }
  653. }
  654. }