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. private IDataTable<DRClothing> _clothdata;
  85. public void ChangeECustomStyple(ECustomStyple ec) {
  86. eCustomStyple = ec;
  87. }
  88. protected override void OnOpen(object userData)
  89. {
  90. base.OnOpen(userData);
  91. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  92. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  93. _facedata = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  94. _clothdata = GameEntry.DataTable.GetDataTable<DRClothing>();
  95. }
  96. public void ColorChange(Vector3 _v3) {
  97. colorV3 = _v3;
  98. }
  99. public void SaveColorChange()
  100. {
  101. var a = new UIColorData(eCustomStyple,id,colorV3);
  102. String str = JsonUtility.ToJson(a);
  103. // var obj = JsonUtility.FromJson<PartData>(str);
  104. SaveColorAdd(3);
  105. SaveColorAdd(2);
  106. GameEntry.Setting.SetString("savecolor"+eCustomStyple+"/"+id+"/"+1, str);
  107. GameEntry.Setting.Save();
  108. ChooseColorChange();
  109. //GameEntry.Setting.HasSetting("savecolor");
  110. //GameEntry.Setting.GetString("");
  111. }
  112. public void SaveColorAdd(int _Index)
  113. {
  114. if (GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/"+_Index))
  115. {
  116. String _saveStr=GameEntry.Setting.GetString("savecolor" + eCustomStyple + "/" + id + "/" + (_Index-1));
  117. GameEntry.Setting.SetString("savecolor" + eCustomStyple + "/" + id + "/" +_Index, _saveStr);
  118. }
  119. }
  120. public void ColorHuaDong(Vector3 _v3)
  121. {
  122. colorV3 = _v3;
  123. }
  124. public void ChooseColorChange()
  125. {
  126. Debug.Log(nowChooseColorObj.transform.parent.name);
  127. if (nowChooseColorObj!=null)
  128. {
  129. Image _img=nowChooseColorObj.transform.GetComponent<Image>();
  130. _img.color = new Color(colorV3.x,colorV3.y,colorV3.z);
  131. }
  132. }
  133. protected override void OnClose(bool isShutdown, object userData)
  134. {
  135. base.OnClose(isShutdown, userData);
  136. }
  137. public void ClickBotton(ECustomStyple eCustomStyple,int id,bool ziDingYi,bool isColor)
  138. {
  139. if (isTween)
  140. {
  141. return;
  142. }
  143. isTween = true;
  144. leftView.transform.DOLocalMoveX(tween_leftMin, tweenTime).SetEase(Ease.InOutBack).OnComplete(()=> {
  145. //whitebg.SetActive(bg);
  146. ClickBtnFun(eCustomStyple,id,ziDingYi,isColor);
  147. leftView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  148. isTween = false;
  149. Debug.Log("222");
  150. });
  151. });
  152. Debug.Log("333");
  153. rightView.transform.DOLocalMoveX(tween_rightMax, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  154. rightView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  155. });
  156. });
  157. }
  158. /// <summary>
  159. /// 调色界面打开
  160. /// </summary>
  161. public void TiaoSeViewOpenFun() {
  162. HistoryAdd("Color");
  163. rightView.SetActive(false);
  164. colorView.SetActive(true);
  165. }
  166. /// <summary>
  167. /// 调色板的调色板打开或关闭
  168. /// </summary>
  169. public void TiaoSeBanOpenStyple(bool _bo)
  170. {
  171. colorView.SetActive(!_bo);
  172. tiaoSeBanView.SetActive(_bo);
  173. }
  174. /// <summary>
  175. /// 调色板确认按钮
  176. /// </summary>
  177. public void TiaoSeSure()
  178. {
  179. SaveColorChange();
  180. TiaoSeBanOpenStyple(false);
  181. }
  182. /// <summary>
  183. /// 调色板取消按钮
  184. /// </summary>
  185. public void TiaoSeBanCloseFun() {
  186. }
  187. /// <summary>
  188. /// 自定义调色板
  189. /// </summary>
  190. public void TiaoSeBanCustom() {
  191. }
  192. public void TiaoSeViewRefesh() {
  193. GameObject _obj = tiaoSeBanView.transform.GetChild(0).GetChild(0).gameObject;
  194. RemoveAllChildren(_obj, 1);
  195. }
  196. public void TiaoSeAddItem(GameObject _par) {
  197. if (GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/" + 3))
  198. {
  199. }
  200. GameObject _clone = GameObject.Instantiate(colItem);
  201. _clone.transform.SetParent(_par.transform);
  202. }
  203. public bool HasCustomColor(int _index)
  204. {
  205. bool _has = GameEntry.Setting.HasSetting("savecolor" + eCustomStyple + "/" + id + "/" + _index+"");
  206. return _has;
  207. }
  208. //public UIColorData GetUIColorData(int _index) {
  209. // String _str= GameEntry.Setting.GetString("savecolor" + eCustomStyple + "/" + id + "/" + _index+"");
  210. // return
  211. //}
  212. /// <summary>
  213. /// 设置是否已在缓动
  214. /// </summary>
  215. public void SetTween(bool _bo) {
  216. isTween = _bo;
  217. }
  218. /// <summary>
  219. /// 获取是否缓动
  220. /// </summary>
  221. public bool GetTween()
  222. {
  223. return isTween;
  224. }
  225. public void HistoryAdd(string _str) {
  226. histroy.Add(_str);
  227. }
  228. /// <summary>
  229. /// 滑块改变
  230. /// </summary>
  231. public void ScrollValueChange()
  232. {
  233. //Debug.Log(scrollbar.value);
  234. //switch (eCustomStyple)
  235. //{
  236. // case ECustomStyple.None:
  237. // break;
  238. // case ECustomStyple.Body:
  239. // GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(part, new Vector3(scrollbar.value, 0, 0)));
  240. // break;
  241. // case ECustomStyple.NieLian:
  242. // break;
  243. // case ECustomStyple.Cloth:
  244. // break;
  245. //}
  246. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(eCustomStyple,part, new Vector3(scrollbar.value, 0, 0)));
  247. // GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(part, new Vector3(scrollbar.value, 0, 0)));
  248. }
  249. public void BackBtn_Fun()
  250. {
  251. if (histroyextra)
  252. {
  253. BackExtraFun();
  254. histroyextra = false;
  255. return;
  256. }
  257. int index = this.histroy.Count;
  258. index = eCustomStyple == ECustomStyple.Ornament ? index - 1 : index;
  259. switch (this.histroy.Count)
  260. {
  261. case 0:
  262. Debug.Log("返回上一层");
  263. //GameEntry.UI.CloseUIForm(104);
  264. GameEntry.UI.OpenUIForm(UIFormId.GameMenuForm);
  265. // Close();
  266. break;
  267. case 1:
  268. Debug.Log("返回选择捏脸/身体/服装");
  269. histroy.RemoveAt(histroy.Count - 1);
  270. Back_OneFun();
  271. break;
  272. case 2:
  273. Debug.Log("进入选择界面");
  274. scrollbar.gameObject.SetActive(false);
  275. histroy.RemoveAt(histroy.Count - 1);
  276. Back_TwoFun(true);
  277. break;
  278. default:
  279. Debug.Log("进入自定义或颜色");
  280. // histroy.RemoveAt(histroy.Count - 1);
  281. Back_ThreeFun();
  282. histroy.RemoveAt(histroy.Count - 1);
  283. break;
  284. }
  285. }
  286. public void BackBtnFun()
  287. {
  288. if (isTween)
  289. {
  290. return;
  291. }
  292. //if (histroy.Count == 0)
  293. //{
  294. // GameEntry.UI.OpenUIForm(UIFormId.GameMenuForm);
  295. // Close();
  296. // return;
  297. //}
  298. isTween = true;
  299. leftView.transform.DOLocalMoveX(tween_leftMin, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  300. //whitebg.SetActive(bg);
  301. BackBtn_Fun();
  302. leftView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  303. isTween = false;
  304. Debug.Log("222");
  305. });
  306. });
  307. Debug.Log("333");
  308. rightView.transform.DOLocalMoveX(tween_rightMax, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  309. rightView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  310. });
  311. });
  312. }
  313. /// <summary>
  314. /// 返回的方法一
  315. /// </summary>
  316. void Back_OneFun() {
  317. ViewSetFalse();
  318. toolView.SetActive(true);
  319. //toolView.SetActive(true);
  320. //bodyView.SetActive(false);
  321. //nieLianView.SetActive(false);
  322. //clothView.SetActive(false);
  323. }
  324. /// <summary>
  325. /// 返回的方法extra
  326. /// </summary>
  327. void BackExtraFun()
  328. {
  329. rightView.SetActive(true);
  330. scrollbar.gameObject.SetActive(false);
  331. }
  332. /// <summary>
  333. /// 面板全部隐藏
  334. /// </summary>
  335. void ViewSetFalse()
  336. {
  337. toolView.SetActive(false);
  338. bodyView.SetActive(false);
  339. nieLianView.SetActive(false);
  340. clothView.SetActive(false);
  341. }
  342. void BackView_Extra(GameObject _obj,bool _bo) {
  343. ViewSetFalse();
  344. _obj.SetActive(_bo);
  345. ViewSetChildTrue(_obj,_bo);
  346. }
  347. void ViewSetChildTrue(GameObject _obj,bool _bo)
  348. {
  349. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  350. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  351. _obj.transform.GetChild(2).gameObject.SetActive(!_bo);
  352. }
  353. /// <summary>
  354. /// 返回的方法二
  355. /// </summary>
  356. void Back_TwoFun(bool _bo)
  357. {
  358. // int _choose = int.Parse(histroy[1]);
  359. // switch ((ECustomStyple)_choose)
  360. whitebg.SetActive(false);
  361. switch(eCustomStyple)
  362. {
  363. case ECustomStyple.Body:
  364. BackView_Extra(bodyView,_bo);
  365. break;
  366. case ECustomStyple.Cloth:
  367. BackView_Extra(clothView, _bo);
  368. break;
  369. case ECustomStyple.None:
  370. break;
  371. case ECustomStyple.NieLian:
  372. BackView_Extra(nieLianView, _bo);
  373. break;
  374. case ECustomStyple.Ornament:
  375. // BackView_Extra(ornamentsView, _bo);
  376. BackView_Extra(clothView, _bo);
  377. ornamentsView.SetActive(false);
  378. break;
  379. }
  380. //toolView.SetActive(true);
  381. //bodyView.SetActive(false);
  382. //nieLianView.SetActive(false);
  383. //clothView.SetActive(false);
  384. }
  385. /// <summary>
  386. /// 返回的方法三
  387. /// </summary>
  388. void Back_ThreeFun()
  389. {
  390. string[] _strArrary = histroy[histroy.Count - 1].Split(',');
  391. if (_strArrary[0] == "Color")
  392. {
  393. colorView.SetActive(false);
  394. rightView.SetActive(true);
  395. }
  396. else if (_strArrary[0] == "ziDingyi")
  397. {
  398. scrollbar.gameObject.SetActive(false);
  399. int _chooseId = int.Parse(_strArrary[2]);
  400. hasColorChoose = int.Parse(_strArrary[1]) == 1 ? true : false;
  401. ClickBtnFun(eCustomStyple, _chooseId, true,hasColorChoose);
  402. }
  403. else
  404. {
  405. Debug.Log("缺少当前情况需要添加>>>>");
  406. }
  407. //toolView.SetActive(true);
  408. //bodyView.SetActive(false);
  409. //nieLianView.SetActive(false);
  410. //clothView.SetActive(false);
  411. }
  412. public void PickOnButton(GameObject _obj,int _id) {
  413. if (_obj.transform.childCount <= 0)
  414. {
  415. return;
  416. }
  417. GameObject _nowPickOnImg = _obj.transform.GetChild(0).gameObject;
  418. if (nowPickOnImg==null)
  419. {
  420. nowPickOnImg = _nowPickOnImg;
  421. id = _id;
  422. nowPickOnImg.SetActive(true);
  423. }
  424. else
  425. {
  426. if (_id != id)
  427. {
  428. nowPickOnImg.SetActive(false);
  429. id = _id;
  430. nowPickOnImg = _nowPickOnImg;
  431. _nowPickOnImg.SetActive(true);
  432. }
  433. else
  434. {
  435. nowPickOnImg = _nowPickOnImg;
  436. _nowPickOnImg.SetActive(!_nowPickOnImg.activeSelf);
  437. }
  438. }
  439. scrollbar.gameObject.SetActive(nowPickOnImg.activeSelf);
  440. }
  441. /// <summary>
  442. /// 修改滑块
  443. /// </summary>
  444. public void SetValue(int _part,ECustomStyple eCustomStyple)
  445. {
  446. //scrollbar.value = _value;
  447. part = _part;
  448. Debug.Log(eCustomStyple.ToString());
  449. scrollbar.value = CustomManager.Instance.GetBodyBoneValue(eCustomStyple,part);
  450. }
  451. /// <summary>
  452. /// 获得滑块值
  453. /// </summary>
  454. public float GetValue()
  455. {
  456. return scrollbar.value;
  457. }
  458. /// <summary>
  459. /// 修改颜色
  460. /// </summary>
  461. public void SetColor(int _part, ECustomStyple eCustomStyple)
  462. {
  463. //scrollbar.value = _value;
  464. part = _part;
  465. }
  466. /// <summary>
  467. /// 按钮点击事件
  468. /// </summary>
  469. public void ClickBtnFun(ECustomStyple eCustomStyple,int id,bool zidingyi,bool isColor) {
  470. //if (isTween)
  471. //{
  472. // return;
  473. //}
  474. hasColorChoose = isColor;
  475. whitebg.SetActive(true);
  476. scrollbar.gameObject.SetActive(false);
  477. this.eCustomStyple = eCustomStyple;
  478. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  479. switch (eCustomStyple)
  480. {
  481. case ECustomStyple.None:
  482. break;
  483. case ECustomStyple.NieLian:
  484. XXListShow(nieLianView);
  485. //GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  486. //_nieLianList.SetActive(false);
  487. //GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  488. //_nieLianXX.SetActive(true);
  489. //if (!zidingyi)
  490. //{
  491. // ZiDingYiNeiLian(eCustomStyple, id, _nieLianXX.transform.GetChild(0).gameObject);
  492. // return;
  493. //}
  494. eCustomStyple = ECustomStyple.Cloth;
  495. CreateNieLianImg(id, zidingyi,isColor);
  496. break;
  497. case ECustomStyple.Body:
  498. XXListShow(bodyView);
  499. //GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  500. //_bodyList.SetActive(false);
  501. //GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  502. //_bodyListXX.SetActive(true);
  503. //if (!zidingyi)
  504. //{
  505. // ZiDingYiBody(eCustomStyple, id, _bodyListXX.transform.GetChild(0).gameObject);
  506. // return;
  507. //}
  508. CreateBodyImg(id, zidingyi,isColor);
  509. break;
  510. case ECustomStyple.Cloth:
  511. XXListShow(clothView);
  512. //GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  513. //_clothList.SetActive(false);
  514. //GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  515. //_clothListXX.SetActive(true);
  516. //if (!zidingyi)
  517. //{
  518. // ZiDingYiCloth(eCustomStyple, id, _clothListXX.transform.GetChild(0).gameObject);
  519. // return;
  520. //}
  521. CreateClothImg(id, zidingyi,isColor);
  522. break;
  523. case ECustomStyple.Ornament:
  524. XXListShow(ornamentsView);
  525. //GameObject _Ornament = ornamentsView.transform.GetChild(0).gameObject;
  526. //_Ornament.SetActive(false);
  527. //GameObject _OrnamentXX = ornamentsView.transform.GetChild(2).gameObject;
  528. //_OrnamentXX.SetActive(true);
  529. break;
  530. }
  531. }
  532. public void XXListShow(GameObject obj)
  533. {
  534. obj.transform.GetChild(0).gameObject.SetActive(false);
  535. obj.transform.GetChild(2).gameObject.SetActive(true);
  536. }
  537. //public Action ActionFun() {
  538. // return null;
  539. //}
  540. public void ModelMove(Vector2 v2)
  541. {
  542. Debug.Log(v2.x);
  543. //CustomManaget.Instance.RotateModel(v2.x);
  544. }
  545. private void RemoveAllChildren(GameObject parent,int _index=0)
  546. {
  547. Transform transform;
  548. for (int i = _index; i < parent.transform.childCount; i++)
  549. {
  550. transform = parent.transform.GetChild(i);
  551. GameObject.Destroy(transform.gameObject);
  552. }
  553. }
  554. //public void ZiDingYiNeiLian(ECustomStyple eCustomStyple, int id,GameObject _objPar) {
  555. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  556. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  557. // _obj.transform.SetParent(_objPar.transform);
  558. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  559. // _uICustomBtn.id = id;
  560. // _uICustomBtn.eCustomStyple = eCustomStyple;
  561. // _obj.SetActive(true);
  562. //}
  563. //public void ZiDingYiBody(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  564. //{
  565. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  566. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  567. // _obj.transform.SetParent(_objPar.transform);
  568. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  569. // _uICustomBtn.id = id;
  570. // _uICustomBtn.eCustomStyple = eCustomStyple;
  571. // _obj.SetActive(true);
  572. //}
  573. //public void ZiDingYiCloth(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  574. //{
  575. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  576. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  577. // _obj.transform.SetParent(_objPar.transform);
  578. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  579. // _uICustomBtn.id = id;
  580. // _uICustomBtn.eCustomStyple = eCustomStyple;
  581. // _obj.SetActive(true);
  582. //}
  583. public void CreateNieLianImg(int parentid, bool ziDingYi, bool isColor)
  584. {
  585. GameObject _objPar = nieLianView.transform.GetChild(2).GetChild(0).gameObject;
  586. RemoveAllChildren(_objPar);
  587. //等有捏脸表时改为捏脸
  588. IDataTable<DRCustomFace> _data = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  589. _facedata = GameEntry.DataTable.GetDataTable<DRCustomFace>();
  590. int cengji = ziDingYi ? 0 : 1;
  591. if (ziDingYi)
  592. {
  593. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  594. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  595. //_obj.transform.SetParent(_objPar.transform);
  596. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  597. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  598. //_uICustomBtn.id =parentid;
  599. //_uICustomBtn.eCustomStyple = eCustomStyple;
  600. //_obj.SetActive(true);
  601. }
  602. if (isColor)
  603. {
  604. CreateColFun(parentid, _objPar,colItem);
  605. }
  606. GridLayoutGroupChange(_objPar);
  607. DRCustomFace[] dRCustomBodies = _facedata.GetAllDataRows();
  608. for (int i = 0; i < dRCustomBodies.Length; i++)
  609. {
  610. Debug.Log(dRCustomBodies[i].Id);
  611. if (dRCustomBodies[i].ParentStyple == parentid&&dRCustomBodies[i].Cengji==cengji&& dRCustomBodies[i].IsActive == 1)
  612. {
  613. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.NieLian, dRCustomBodies[i].IsActive);
  614. }
  615. }
  616. ChangeListBotton(_objPar);
  617. }
  618. public void CreateClothImg(int parentid,bool ziDingYi, bool isColor)
  619. {
  620. GameObject _objPar = clothView.transform.GetChild(2).GetChild(0).gameObject;
  621. RemoveAllChildren(_objPar);
  622. //if (parentid == 8)
  623. //{
  624. //}
  625. //等有服装时改为服装
  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. DRClothing[] dRClothing = _clothdata.GetAllDataRows();
  644. for (int i = 0; i < dRClothing.Length; i++)
  645. {
  646. Debug.Log(dRClothing[i].Id);
  647. if (dRClothing[i].ParentStyple == parentid && dRClothing[i].Cengji == cengji&& dRClothing[i].IsActive==1)
  648. {
  649. CreateButtonFun(dRClothing[i].Icon, dRClothing[i].Name, _objPar, dRClothing[i].Id, dRClothing[i].ButtonStyple, ECustomStyple.Cloth, dRClothing[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. Text,
  896. }
  897. public enum ENieLianStyple {
  898. None,
  899. faxing,
  900. lianxing,
  901. yankuang,
  902. tongkong,
  903. meimao,
  904. bizi,
  905. erduo,
  906. zuiba,
  907. fuse
  908. }
  909. public enum EButtonShunXu {
  910. None,
  911. First,
  912. Second,
  913. Third
  914. }
  915. public enum ETSStyple {
  916. None,
  917. ViewOpen,
  918. Close,
  919. Sure,
  920. Open,
  921. Button
  922. }
  923. }