UICustom.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. using GameFramework;
  7. using GameFramework.DataTable;
  8. using GameFramework.Sound;
  9. using GameFramework.Download;
  10. using GameFramework.FileSystem;
  11. using GameFramework.ObjectPool;
  12. using GameFramework.Resource;
  13. using System;
  14. using DG.Tweening;
  15. namespace MetaClient
  16. {
  17. public class UICustom : UGuiForm
  18. {
  19. // Start is called before the first frame update
  20. [Header("初始界面")]
  21. public GameObject toolView;
  22. [Header("基础按钮界面")]
  23. public GameObject baseView;
  24. [Header("保存按钮")]
  25. public GameObject saveBtn;
  26. [Header("捏脸界面")]
  27. public GameObject nieLianView;
  28. [Header("身体界面")]
  29. public GameObject bodyView;
  30. [Header("自定义")]
  31. public GameObject ziDingYiBtn;
  32. [Header("衣服界面")]
  33. public GameObject clothView;
  34. [Header("饰品界面")]
  35. public GameObject ornamentsView;
  36. [Header("左边界面")]
  37. public GameObject leftView;
  38. [Header("右边界面")]
  39. public GameObject rightView;
  40. //[Header("点击后生成的按钮列表")]
  41. //public GameObject buttonList;
  42. [Header("白底背景")]
  43. public GameObject whitebg;
  44. [Header("按钮预制体")]
  45. public GameObject buttonItem;
  46. [Header("滑块")]
  47. public Scrollbar scrollbar;
  48. [Header("颜色选择界面")]
  49. public GameObject colorView;
  50. [Header("调色版界面")]
  51. public GameObject tiaoSeBanView;
  52. // [Header("顺序")]
  53. private EButtonShunXu eButtonShunXu = EButtonShunXu.None;
  54. [Header("颜色演示预制体")]
  55. public GameObject colItem;
  56. public bool hasColorChoose = false;
  57. public float tween_leftMax = 0;
  58. public float tween_leftMin = -250;
  59. public float tween_rightMin = 0;
  60. public float tween_rightMax = 223;
  61. //private float tween_saveBtnMax = 119;
  62. //private float tween_saveBtnMin = -108;
  63. private float tweenTime = 0.5f;
  64. //private float tweenTime = 10;
  65. //private float tweenLeastTime = 0;
  66. private GameObject nowChooseColorObj;
  67. public bool isTween = false;
  68. [Header("选择界面分支")]
  69. [SerializeField]
  70. private ECustomStyple eCustomStyple = ECustomStyple.None;
  71. [Header("历史记录用于回退")]
  72. [SerializeField]
  73. private List<string> histroy;
  74. //用来判断是否是例如颜色框 调色板等额外的弹窗;
  75. private bool histroyextra;
  76. private int part = 0;
  77. private int id = -1;
  78. private GameObject nowPickOnImg=null;
  79. private Vector3 colorV3 = new Vector3(0, 0, 0);
  80. //[Header("接受到的数据")]
  81. //[SerializeField]
  82. private IDataTable<DRCustomBody> _bodydata;
  83. private IDataTable<DRCustomFace> _facedata;
  84. public void ChangeECustomStyple(ECustomStyple ec) {
  85. eCustomStyple = ec;
  86. }
  87. protected override void OnOpen(object userData)
  88. {
  89. base.OnOpen(userData);
  90. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  91. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  92. _facedata = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  93. }
  94. public void ColorChange(Vector3 _v3) {
  95. colorV3 = _v3;
  96. }
  97. public void SaveColorChange()
  98. {
  99. var a = new UIColorData(eCustomStyple,id,colorV3);
  100. String str = JsonUtility.ToJson(a);
  101. // var obj = JsonUtility.FromJson<PartData>(str);
  102. SaveColorAdd(3);
  103. SaveColorAdd(2);
  104. GameEntry.Setting.SetString("savecolor"+eCustomStyple+"/"+id+"/"+1, str);
  105. GameEntry.Setting.Save();
  106. ChooseColorChange();
  107. //GameEntry.Setting.HasSetting("savecolor");
  108. //GameEntry.Setting.GetString("");
  109. }
  110. public void SaveColorAdd(int _Index)
  111. {
  112. if (GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/"+_Index))
  113. {
  114. String _saveStr=GameEntry.Setting.GetString("savecolor" + eCustomStyple + "/" + id + "/" + (_Index-1));
  115. GameEntry.Setting.SetString("savecolor" + eCustomStyple + "/" + id + "/" +_Index, _saveStr);
  116. }
  117. }
  118. public void ColorHuaDong(Vector3 _v3)
  119. {
  120. colorV3 = _v3;
  121. }
  122. public void ChooseColorChange()
  123. {
  124. Debug.Log(nowChooseColorObj.transform.parent.name);
  125. if (nowChooseColorObj!=null)
  126. {
  127. Image _img=nowChooseColorObj.transform.GetComponent<Image>();
  128. _img.color = new Color(colorV3.x,colorV3.y,colorV3.z);
  129. }
  130. }
  131. protected override void OnClose(bool isShutdown, object userData)
  132. {
  133. base.OnClose(isShutdown, userData);
  134. }
  135. public void ClickBotton(ECustomStyple eCustomStyple,int id,bool ziDingYi,bool isColor)
  136. {
  137. if (isTween)
  138. {
  139. return;
  140. }
  141. isTween = true;
  142. leftView.transform.DOLocalMoveX(tween_leftMin, tweenTime).SetEase(Ease.InOutBack).OnComplete(()=> {
  143. //whitebg.SetActive(bg);
  144. ClickBtnFun(eCustomStyple,id,ziDingYi,isColor);
  145. leftView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  146. isTween = false;
  147. Debug.Log("222");
  148. });
  149. });
  150. Debug.Log("333");
  151. rightView.transform.DOLocalMoveX(tween_rightMax, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  152. rightView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  153. });
  154. });
  155. }
  156. /// <summary>
  157. /// 调色界面打开
  158. /// </summary>
  159. public void TiaoSeViewOpenFun() {
  160. HistoryAdd("Color");
  161. rightView.SetActive(false);
  162. colorView.SetActive(true);
  163. }
  164. /// <summary>
  165. /// 调色板的调色板打开或关闭
  166. /// </summary>
  167. public void TiaoSeBanOpenStyple(bool _bo)
  168. {
  169. colorView.SetActive(!_bo);
  170. tiaoSeBanView.SetActive(_bo);
  171. }
  172. /// <summary>
  173. /// 调色板确认按钮
  174. /// </summary>
  175. public void TiaoSeSure()
  176. {
  177. SaveColorChange();
  178. TiaoSeBanOpenStyple(false);
  179. }
  180. /// <summary>
  181. /// 调色板取消按钮
  182. /// </summary>
  183. public void TiaoSeBanCloseFun() {
  184. }
  185. /// <summary>
  186. /// 自定义调色板
  187. /// </summary>
  188. public void TiaoSeBanCustom() {
  189. }
  190. public void TiaoSeViewRefesh() {
  191. GameObject _obj = tiaoSeBanView.transform.GetChild(0).GetChild(0).gameObject;
  192. RemoveAllChildren(_obj, 1);
  193. }
  194. public void TiaoSeAddItem(GameObject _par) {
  195. if (GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/" + 3))
  196. {
  197. }
  198. GameObject _clone = GameObject.Instantiate(colItem);
  199. _clone.transform.SetParent(_par.transform);
  200. }
  201. public bool HasCustomColor(int _index)
  202. {
  203. bool _has = GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/" + _index+"");
  204. return _has;
  205. }
  206. //public UIColorData GetUIColorData(int _index) {
  207. // String _str= GameEntry.Setting.GetString("savecolor" + eCustomStyple + "/" + id + "/" + _index+"");
  208. // return
  209. //}
  210. /// <summary>
  211. /// 设置是否已在缓动
  212. /// </summary>
  213. public void SetTween(bool _bo) {
  214. isTween = _bo;
  215. }
  216. /// <summary>
  217. /// 获取是否缓动
  218. /// </summary>
  219. public bool GetTween()
  220. {
  221. return isTween;
  222. }
  223. public void HistoryAdd(string _str) {
  224. histroy.Add(_str);
  225. }
  226. /// <summary>
  227. /// 滑块改变
  228. /// </summary>
  229. public void ScrollValueChange()
  230. {
  231. //Debug.Log(scrollbar.value);
  232. //switch (eCustomStyple)
  233. //{
  234. // case ECustomStyple.None:
  235. // break;
  236. // case ECustomStyple.Body:
  237. // GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(part, new Vector3(scrollbar.value, 0, 0)));
  238. // break;
  239. // case ECustomStyple.NieLian:
  240. // break;
  241. // case ECustomStyple.Cloth:
  242. // break;
  243. //}
  244. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(eCustomStyple,part, new Vector3(scrollbar.value, 0, 0)));
  245. // GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(part, new Vector3(scrollbar.value, 0, 0)));
  246. }
  247. public void BackBtn_Fun()
  248. {
  249. if (histroyextra)
  250. {
  251. BackExtraFun();
  252. histroyextra = false;
  253. return;
  254. }
  255. int index = this.histroy.Count;
  256. index = eCustomStyple == ECustomStyple.Ornament ? index - 1 : index;
  257. switch (this.histroy.Count)
  258. {
  259. case 0:
  260. Debug.Log("返回上一层");
  261. //GameEntry.UI.CloseUIForm(104);
  262. GameEntry.UI.OpenUIForm(UIFormId.GameMenuForm);
  263. // Close();
  264. break;
  265. case 1:
  266. Debug.Log("返回选择捏脸/身体/服装");
  267. histroy.RemoveAt(histroy.Count - 1);
  268. Back_OneFun();
  269. break;
  270. case 2:
  271. Debug.Log("进入选择界面");
  272. scrollbar.gameObject.SetActive(false);
  273. histroy.RemoveAt(histroy.Count - 1);
  274. Back_TwoFun(true);
  275. break;
  276. default:
  277. Debug.Log("进入自定义或颜色");
  278. // histroy.RemoveAt(histroy.Count - 1);
  279. Back_ThreeFun();
  280. histroy.RemoveAt(histroy.Count - 1);
  281. break;
  282. }
  283. }
  284. public void BackBtnFun()
  285. {
  286. if (isTween)
  287. {
  288. return;
  289. }
  290. //if (histroy.Count == 0)
  291. //{
  292. // GameEntry.UI.OpenUIForm(UIFormId.GameMenuForm);
  293. // Close();
  294. // return;
  295. //}
  296. isTween = true;
  297. leftView.transform.DOLocalMoveX(tween_leftMin, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  298. //whitebg.SetActive(bg);
  299. BackBtn_Fun();
  300. leftView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  301. isTween = false;
  302. Debug.Log("222");
  303. });
  304. });
  305. Debug.Log("333");
  306. rightView.transform.DOLocalMoveX(tween_rightMax, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  307. rightView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  308. });
  309. });
  310. }
  311. /// <summary>
  312. /// 返回的方法一
  313. /// </summary>
  314. void Back_OneFun() {
  315. ViewSetFalse();
  316. toolView.SetActive(true);
  317. //toolView.SetActive(true);
  318. //bodyView.SetActive(false);
  319. //nieLianView.SetActive(false);
  320. //clothView.SetActive(false);
  321. }
  322. /// <summary>
  323. /// 返回的方法extra
  324. /// </summary>
  325. void BackExtraFun()
  326. {
  327. rightView.SetActive(true);
  328. scrollbar.gameObject.SetActive(false);
  329. }
  330. /// <summary>
  331. /// 面板全部隐藏
  332. /// </summary>
  333. void ViewSetFalse()
  334. {
  335. toolView.SetActive(false);
  336. bodyView.SetActive(false);
  337. nieLianView.SetActive(false);
  338. clothView.SetActive(false);
  339. }
  340. void BackView_Extra(GameObject _obj,bool _bo) {
  341. ViewSetFalse();
  342. _obj.SetActive(_bo);
  343. ViewSetChildTrue(_obj,_bo);
  344. }
  345. void ViewSetChildTrue(GameObject _obj,bool _bo)
  346. {
  347. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  348. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  349. _obj.transform.GetChild(2).gameObject.SetActive(!_bo);
  350. }
  351. /// <summary>
  352. /// 返回的方法二
  353. /// </summary>
  354. void Back_TwoFun(bool _bo)
  355. {
  356. // int _choose = int.Parse(histroy[1]);
  357. // switch ((ECustomStyple)_choose)
  358. whitebg.SetActive(false);
  359. switch(eCustomStyple)
  360. {
  361. case ECustomStyple.Body:
  362. BackView_Extra(bodyView,_bo);
  363. break;
  364. case ECustomStyple.Cloth:
  365. BackView_Extra(clothView, _bo);
  366. break;
  367. case ECustomStyple.None:
  368. break;
  369. case ECustomStyple.NieLian:
  370. BackView_Extra(nieLianView, _bo);
  371. break;
  372. case ECustomStyple.Ornament:
  373. // BackView_Extra(ornamentsView, _bo);
  374. BackView_Extra(clothView, _bo);
  375. ornamentsView.SetActive(false);
  376. break;
  377. }
  378. //toolView.SetActive(true);
  379. //bodyView.SetActive(false);
  380. //nieLianView.SetActive(false);
  381. //clothView.SetActive(false);
  382. }
  383. /// <summary>
  384. /// 返回的方法三
  385. /// </summary>
  386. void Back_ThreeFun()
  387. {
  388. string[] _strArrary = histroy[histroy.Count - 1].Split(',');
  389. if (_strArrary[0] == "Color")
  390. {
  391. colorView.SetActive(false);
  392. rightView.SetActive(true);
  393. }
  394. else if (_strArrary[0] == "ziDingyi")
  395. {
  396. scrollbar.gameObject.SetActive(false);
  397. int _chooseId = int.Parse(_strArrary[2]);
  398. hasColorChoose = int.Parse(_strArrary[1]) == 1 ? true : false;
  399. ClickBtnFun(eCustomStyple, _chooseId, true,hasColorChoose);
  400. }
  401. else
  402. {
  403. Debug.Log("缺少当前情况需要添加>>>>");
  404. }
  405. //toolView.SetActive(true);
  406. //bodyView.SetActive(false);
  407. //nieLianView.SetActive(false);
  408. //clothView.SetActive(false);
  409. }
  410. public void PickOnButton(GameObject _obj,int _id) {
  411. if (_obj.transform.childCount <= 0)
  412. {
  413. return;
  414. }
  415. GameObject _nowPickOnImg = _obj.transform.GetChild(0).gameObject;
  416. if (nowPickOnImg==null)
  417. {
  418. nowPickOnImg = _nowPickOnImg;
  419. id = _id;
  420. nowPickOnImg.SetActive(true);
  421. }
  422. else
  423. {
  424. if (_id != id)
  425. {
  426. nowPickOnImg.SetActive(false);
  427. id = _id;
  428. nowPickOnImg = _nowPickOnImg;
  429. _nowPickOnImg.SetActive(true);
  430. }
  431. else
  432. {
  433. nowPickOnImg = _nowPickOnImg;
  434. _nowPickOnImg.SetActive(!_nowPickOnImg.activeSelf);
  435. }
  436. }
  437. scrollbar.gameObject.SetActive(nowPickOnImg.activeSelf);
  438. }
  439. /// <summary>
  440. /// 修改滑块
  441. /// </summary>
  442. public void SetValue(int _part,ECustomStyple eCustomStyple)
  443. {
  444. //scrollbar.value = _value;
  445. part = _part;
  446. Debug.Log(eCustomStyple.ToString());
  447. scrollbar.value = CustomManager.Instance.GetBodyBoneValue(eCustomStyple,part);
  448. }
  449. /// <summary>
  450. /// 获得滑块值
  451. /// </summary>
  452. public float GetValue()
  453. {
  454. return scrollbar.value;
  455. }
  456. /// <summary>
  457. /// 修改颜色
  458. /// </summary>
  459. public void SetColor(int _part, ECustomStyple eCustomStyple)
  460. {
  461. //scrollbar.value = _value;
  462. part = _part;
  463. }
  464. /// <summary>
  465. /// 按钮点击事件
  466. /// </summary>
  467. public void ClickBtnFun(ECustomStyple eCustomStyple,int id,bool zidingyi,bool isColor) {
  468. //if (isTween)
  469. //{
  470. // return;
  471. //}
  472. hasColorChoose = isColor;
  473. whitebg.SetActive(true);
  474. scrollbar.gameObject.SetActive(false);
  475. this.eCustomStyple = eCustomStyple;
  476. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  477. switch (eCustomStyple)
  478. {
  479. case ECustomStyple.None:
  480. break;
  481. case ECustomStyple.NieLian:
  482. XXListShow(nieLianView);
  483. //GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  484. //_nieLianList.SetActive(false);
  485. //GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  486. //_nieLianXX.SetActive(true);
  487. //if (!zidingyi)
  488. //{
  489. // ZiDingYiNeiLian(eCustomStyple, id, _nieLianXX.transform.GetChild(0).gameObject);
  490. // return;
  491. //}
  492. eCustomStyple = ECustomStyple.Cloth;
  493. CreateNieLianImg(id, zidingyi,isColor);
  494. break;
  495. case ECustomStyple.Body:
  496. XXListShow(bodyView);
  497. //GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  498. //_bodyList.SetActive(false);
  499. //GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  500. //_bodyListXX.SetActive(true);
  501. //if (!zidingyi)
  502. //{
  503. // ZiDingYiBody(eCustomStyple, id, _bodyListXX.transform.GetChild(0).gameObject);
  504. // return;
  505. //}
  506. CreateBodyImg(id, zidingyi,isColor);
  507. break;
  508. case ECustomStyple.Cloth:
  509. XXListShow(clothView);
  510. //GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  511. //_clothList.SetActive(false);
  512. //GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  513. //_clothListXX.SetActive(true);
  514. //if (!zidingyi)
  515. //{
  516. // ZiDingYiCloth(eCustomStyple, id, _clothListXX.transform.GetChild(0).gameObject);
  517. // return;
  518. //}
  519. CreateClothImg(id, zidingyi,isColor);
  520. break;
  521. case ECustomStyple.Ornament:
  522. XXListShow(ornamentsView);
  523. //GameObject _Ornament = ornamentsView.transform.GetChild(0).gameObject;
  524. //_Ornament.SetActive(false);
  525. //GameObject _OrnamentXX = ornamentsView.transform.GetChild(2).gameObject;
  526. //_OrnamentXX.SetActive(true);
  527. break;
  528. }
  529. }
  530. public void XXListShow(GameObject obj)
  531. {
  532. obj.transform.GetChild(0).gameObject.SetActive(false);
  533. obj.transform.GetChild(2).gameObject.SetActive(true);
  534. }
  535. //public Action ActionFun() {
  536. // return null;
  537. //}
  538. public void ModelMove(Vector2 v2)
  539. {
  540. Debug.Log(v2.x);
  541. //CustomManaget.Instance.RotateModel(v2.x);
  542. }
  543. private void RemoveAllChildren(GameObject parent,int _index=0)
  544. {
  545. Transform transform;
  546. for (int i = _index; i < parent.transform.childCount; i++)
  547. {
  548. transform = parent.transform.GetChild(i);
  549. GameObject.Destroy(transform.gameObject);
  550. }
  551. }
  552. //public void ZiDingYiNeiLian(ECustomStyple eCustomStyple, int id,GameObject _objPar) {
  553. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  554. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  555. // _obj.transform.SetParent(_objPar.transform);
  556. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  557. // _uICustomBtn.id = id;
  558. // _uICustomBtn.eCustomStyple = eCustomStyple;
  559. // _obj.SetActive(true);
  560. //}
  561. //public void ZiDingYiBody(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  562. //{
  563. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  564. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  565. // _obj.transform.SetParent(_objPar.transform);
  566. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  567. // _uICustomBtn.id = id;
  568. // _uICustomBtn.eCustomStyple = eCustomStyple;
  569. // _obj.SetActive(true);
  570. //}
  571. //public void ZiDingYiCloth(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  572. //{
  573. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  574. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  575. // _obj.transform.SetParent(_objPar.transform);
  576. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  577. // _uICustomBtn.id = id;
  578. // _uICustomBtn.eCustomStyple = eCustomStyple;
  579. // _obj.SetActive(true);
  580. //}
  581. public void CreateNieLianImg(int parentid, bool ziDingYi, bool isColor)
  582. {
  583. GameObject _objPar = nieLianView.transform.GetChild(2).GetChild(0).gameObject;
  584. RemoveAllChildren(_objPar);
  585. //等有捏脸表时改为捏脸
  586. IDataTable<DRCustomFace> _data = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  587. _facedata = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  588. int cengji = ziDingYi ? 0 : 1;
  589. if (ziDingYi)
  590. {
  591. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  592. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  593. //_obj.transform.SetParent(_objPar.transform);
  594. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  595. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  596. //_uICustomBtn.id =parentid;
  597. //_uICustomBtn.eCustomStyple = eCustomStyple;
  598. //_obj.SetActive(true);
  599. }
  600. if (isColor)
  601. {
  602. CreateColFun(parentid, _objPar,colItem);
  603. }
  604. GridLayoutGroupChange(_objPar);
  605. DRCustomFace[] dRCustomBodies = _facedata.GetAllDataRows();
  606. for (int i = 0; i < dRCustomBodies.Length; i++)
  607. {
  608. Debug.Log(dRCustomBodies[i].Id);
  609. if (dRCustomBodies[i].ParentStyple == parentid&&dRCustomBodies[i].Cengji==cengji&& dRCustomBodies[i].IsActive == 1)
  610. {
  611. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.NieLian, dRCustomBodies[i].IsActive);
  612. }
  613. }
  614. ChangeListBotton(_objPar);
  615. }
  616. public void CreateClothImg(int parentid,bool ziDingYi, bool isColor)
  617. {
  618. GameObject _objPar = clothView.transform.GetChild(2).GetChild(0).gameObject;
  619. RemoveAllChildren(_objPar);
  620. //if (parentid == 8)
  621. //{
  622. //}
  623. //等有服装时改为服装
  624. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  625. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  626. int cengji = ziDingYi ? 0 : 1;
  627. if (ziDingYi)
  628. {
  629. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  630. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  631. //_obj.transform.SetParent(_objPar.transform);
  632. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  633. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  634. //_uICustomBtn.id = parentid;
  635. //_uICustomBtn.eCustomStyple = eCustomStyple;
  636. //_obj.SetActive(true);
  637. }
  638. if (isColor)
  639. {
  640. CreateColFun(parentid, _objPar, colItem);
  641. }
  642. GridLayoutGroupChange(_objPar);
  643. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  644. for (int i = 0; i < dRCustomBodies.Length; i++)
  645. {
  646. Debug.Log(dRCustomBodies[i].Id);
  647. if (dRCustomBodies[i].ParentStyple == parentid && dRCustomBodies[i].Cengji == cengji&& dRCustomBodies[i].IsActive==1)
  648. {
  649. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Cloth, dRCustomBodies[i].IsActive);
  650. }
  651. }
  652. ChangeListBotton(_objPar);
  653. }
  654. public void CreateOrnamentImg(int parentid, bool ziDingYi, bool isColor)
  655. {
  656. GameObject _objPar = ornamentsView.transform.GetChild(2).GetChild(0).gameObject;
  657. RemoveAllChildren(_objPar);
  658. //if (parentid == 8)
  659. //{
  660. //}
  661. //等有服装时改为服装
  662. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  663. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  664. int cengji = ziDingYi ? 0 : 1;
  665. //if (ziDingYi)
  666. //{
  667. // CreateZDYFun(parentid, _objPar, ziDingYiBtn);
  668. // //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  669. // //_obj.transform.SetParent(_objPar.transform);
  670. // //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  671. // //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  672. // //_uICustomBtn.id = parentid;
  673. // //_uICustomBtn.eCustomStyple = eCustomStyple;
  674. // //_obj.SetActive(true);
  675. //}
  676. //if (isColor)
  677. //{
  678. // CreateColFun(parentid, _objPar, colItem);
  679. //}
  680. GridLayoutGroupChange(_objPar);
  681. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  682. for (int i = 0; i < dRCustomBodies.Length; i++)
  683. {
  684. Debug.Log(dRCustomBodies[i].Id);
  685. if (dRCustomBodies[i].ParentStyple == parentid && dRCustomBodies[i].Cengji == cengji)
  686. {
  687. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Ornament, dRCustomBodies[i].IsActive);
  688. }
  689. }
  690. ChangeListBotton(_objPar);
  691. }
  692. private void CreateZDYFun(int parentid,GameObject _objPar,GameObject _clone)
  693. {
  694. GameObject _obj = GameObject.Instantiate(_clone);
  695. _obj.transform.SetParent(_objPar.transform);
  696. _obj.transform.localScale = new Vector3(1, 1, 1);
  697. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  698. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  699. }
  700. private void CreateColFun(int parentid, GameObject _objPar, GameObject _clone)
  701. {
  702. GameObject _obj = GameObject.Instantiate(_clone);
  703. _obj.transform.SetParent(_objPar.transform);
  704. _obj.transform.localScale = new Vector3(1, 1, 1);
  705. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  706. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  707. nowChooseColorObj = _obj;
  708. }
  709. //private void CreateColorFun(int parentid, GameObject _objPar, GameObject _clone)
  710. //{
  711. // GameObject _obj = GameObject.Instantiate(_clone);
  712. // _obj.transform.SetParent(_objPar.transform);
  713. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  714. // ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  715. //}
  716. public void ChangeUICustom(UICustomBtn uICustomBtn,int id, ECustomStyple eCustomStyple)
  717. {
  718. uICustomBtn.id = id;
  719. uICustomBtn.eCustomStyple = eCustomStyple;
  720. uICustomBtn.gameObject.SetActive(true);
  721. }
  722. public void CreateBodyImg(int parentid,bool ziDingYi, bool isColor) {
  723. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  724. RemoveAllChildren(_objPar);
  725. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  726. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  727. int cengji = ziDingYi ?0:1;
  728. if (ziDingYi)
  729. {
  730. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  731. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  732. //_obj.transform.SetParent(_objPar.transform);
  733. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  734. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  735. //_uICustomBtn.id = parentid;
  736. //_uICustomBtn.eCustomStyple = eCustomStyple;
  737. //_obj.SetActive(true);
  738. }
  739. if (isColor)
  740. {
  741. CreateColFun(parentid, _objPar, colItem);
  742. }
  743. GridLayoutGroupChange(_objPar);
  744. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  745. for (int i = 0; i < dRCustomBodies.Length; i++)
  746. {
  747. //Debug.Log(dRCustomBodies[i].Id);
  748. if (dRCustomBodies[i].ParentStyple == parentid && dRCustomBodies[i].Cengji == cengji)
  749. {
  750. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body, dRCustomBodies[i].IsActive);
  751. }
  752. }
  753. ChangeListBotton(_objPar);
  754. }
  755. private void GridLayoutGroupChange(GameObject _objPar)
  756. {
  757. GridLayoutGroup gridLayoutGroup = _objPar.GetComponent<GridLayoutGroup>();
  758. RectTransform _objParRect = _objPar.GetComponent<RectTransform>();
  759. LayoutRebuilder.ForceRebuildLayoutImmediate(_objParRect);
  760. //float _x = _objParRect.rect.width;
  761. //gridLayoutGroup.cellSize = new Vector2(_x, _x / 100 * 144);
  762. gridLayoutGroup.spacing = new Vector2(0, 0);
  763. Debug.Log(gridLayoutGroup.spacing.y);
  764. LayoutRebuilder.ForceRebuildLayoutImmediate(_objParRect);
  765. }
  766. /// <summary>
  767. /// 改变列表长短
  768. /// </summary>
  769. public void ChangeListBotton(GameObject _obj) {
  770. //Debug.Log("改变列表"+ _obj.transform.childCount+"");
  771. float _x = _obj.GetComponent<RectTransform>().offsetMin.x;
  772. int _childNum = _obj.transform.childCount;
  773. float _y = _childNum > 7 ? -240 * (_childNum - 7) : 0;
  774. _obj.GetComponent<RectTransform>().offsetMax = new Vector2(_x, 0);
  775. _obj.GetComponent<RectTransform>().offsetMin = new Vector2(_x, _y);
  776. }
  777. //public void OrnamentListOpen()
  778. //{
  779. // HistoryAdd(ECustomStyple.Ornament+"");
  780. //}
  781. //private IEnumerator Tween(Action _action) {
  782. // for (int i = 0; i < 100; i++)
  783. // {
  784. // float _value = i / 100;
  785. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  786. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  787. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  788. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  789. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  790. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  791. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  792. // }
  793. // yield return null;
  794. //}
  795. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  796. {
  797. base.OnUpdate(elapseSeconds, realElapseSeconds);
  798. }
  799. //private void CreateNieLianFun(object[] _objects) {
  800. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  801. // switch (_eNieLianStyple)
  802. // {
  803. // case ENieLianStyple.faxing:
  804. // break;
  805. // case ENieLianStyple.lianxing:
  806. // break;
  807. // case ENieLianStyple.yankuang:
  808. // break;
  809. // case ENieLianStyple.tongkong:
  810. // break;
  811. // case ENieLianStyple.meimao:
  812. // break;
  813. // case ENieLianStyple.bizi:
  814. // break;
  815. // case ENieLianStyple.erduo:
  816. // break;
  817. // case ENieLianStyple.zuiba:
  818. // break;
  819. // case ENieLianStyple.fuse:
  820. // break;
  821. // }
  822. // //switch()
  823. //}
  824. private void CreateButtonFun(string path,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple,int _isactive) {
  825. //Debug.Log(path);
  826. // Debug.Log(_parent);
  827. path = "CustomRole/" + path;
  828. Debug.Log("图片名称" + _name);
  829. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  830. (assetName, asset, duration, userData) =>
  831. {
  832. // Debug.Log(path);
  833. // Debug.Log(_parent);
  834. Texture2D tex = (Texture2D)asset;
  835. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  836. GameObject _obj = GameObject.Instantiate(buttonItem);
  837. Image _objImg = _obj.transform.GetComponent<Image>();
  838. _obj.SetActive(true);
  839. _objImg.sprite = sprite;
  840. //_objImg.SetNativeSize();
  841. _obj.name = _name+"";
  842. _obj.transform.SetParent(_parent.transform);
  843. _obj.transform.localScale = new Vector3(1, 1, 1);
  844. if (_isactive != 1)
  845. {
  846. _obj.SetActive(false);
  847. }
  848. //RectTransform rect = _parent.GetComponent<RectTransform>();
  849. //LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
  850. //Vector3 vecScale = rect.localScale;
  851. //float width = rect.rect.width;
  852. //float height = rect.rect.height;
  853. //LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
  854. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  855. uICustomBtn.id = _id;
  856. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  857. uICustomBtn.eCustomStyple = eCustomStyple;
  858. uICustomBtn.isCreate = false;
  859. //uICustomBtn.part = _part;
  860. //GameObject
  861. //img.sprite = sprite;
  862. //if (nativeSize)
  863. //{
  864. // img.SetNativeSize();
  865. //}
  866. ChangeListBotton(_parent);
  867. }));
  868. }
  869. //public void NieLian() {
  870. //}
  871. public void ClickFaceChangeBtn()
  872. {
  873. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  874. }
  875. public void ClickResetBtn()
  876. {
  877. CustomManager.Instance.ResetRole();
  878. }
  879. }
  880. public enum ECustomStyple
  881. {
  882. None,
  883. NieLian,
  884. Body,
  885. Cloth,
  886. Ornament,
  887. }
  888. public enum EButtonStyple
  889. {
  890. Button,
  891. Scroll,
  892. TiaoSe,
  893. NorButton,
  894. Back
  895. }
  896. public enum ENieLianStyple {
  897. None,
  898. faxing,
  899. lianxing,
  900. yankuang,
  901. tongkong,
  902. meimao,
  903. bizi,
  904. erduo,
  905. zuiba,
  906. fuse
  907. }
  908. public enum EButtonShunXu {
  909. None,
  910. First,
  911. Second,
  912. Third
  913. }
  914. public enum ETSStyple {
  915. None,
  916. ViewOpen,
  917. Close,
  918. Sure,
  919. Open,
  920. Button
  921. }
  922. }