UICustom.cs 30 KB

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