UICustom.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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 TiaoSeBanCustom() {
  177. }
  178. /// <summary>
  179. /// 设置是否已在缓动
  180. /// </summary>
  181. public void SetTween(bool _bo) {
  182. isTween = _bo;
  183. }
  184. /// <summary>
  185. /// 获取是否缓动
  186. /// </summary>
  187. public bool GetTween()
  188. {
  189. return isTween;
  190. }
  191. public void HistoryAdd(string _str) {
  192. histroy.Add(_str);
  193. }
  194. /// <summary>
  195. /// 滑块改变
  196. /// </summary>
  197. public void ScrollValueChange()
  198. {
  199. //Debug.Log(scrollbar.value);
  200. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(part, new Vector3(scrollbar.value, 0, 0)));
  201. }
  202. public void BackBtn_Fun()
  203. {
  204. if (histroyextra)
  205. {
  206. BackExtraFun();
  207. histroyextra = false;
  208. return;
  209. }
  210. switch (this.histroy.Count)
  211. {
  212. case 0:
  213. Debug.Log("返回上一层");
  214. break;
  215. case 1:
  216. Debug.Log("返回选择捏脸/身体/服装");
  217. histroy.RemoveAt(histroy.Count - 1);
  218. Back_OneFun();
  219. break;
  220. case 2:
  221. Debug.Log("进入选择界面");
  222. histroy.RemoveAt(histroy.Count - 1);
  223. Back_TwoFun(true);
  224. break;
  225. default:
  226. Debug.Log("进入自定义或颜色");
  227. // histroy.RemoveAt(histroy.Count - 1);
  228. Back_ThreeFun();
  229. histroy.RemoveAt(histroy.Count - 1);
  230. break;
  231. }
  232. }
  233. public void BackBtnFun()
  234. {
  235. if (isTween)
  236. {
  237. return;
  238. }
  239. isTween = true;
  240. leftView.transform.DOLocalMoveX(tween_leftMin, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  241. //whitebg.SetActive(bg);
  242. BackBtn_Fun();
  243. leftView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  244. isTween = false;
  245. Debug.Log("222");
  246. });
  247. });
  248. Debug.Log("333");
  249. rightView.transform.DOLocalMoveX(tween_rightMax, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  250. rightView.transform.DOLocalMoveX(0, tweenTime).SetEase(Ease.InOutBack).OnComplete(() => {
  251. });
  252. });
  253. }
  254. /// <summary>
  255. /// 返回的方法一
  256. /// </summary>
  257. void Back_OneFun() {
  258. ViewSetFalse();
  259. toolView.SetActive(true);
  260. //toolView.SetActive(true);
  261. //bodyView.SetActive(false);
  262. //nieLianView.SetActive(false);
  263. //clothView.SetActive(false);
  264. }
  265. /// <summary>
  266. /// 返回的方法extra
  267. /// </summary>
  268. void BackExtraFun()
  269. {
  270. rightView.SetActive(true);
  271. scrollbar.gameObject.SetActive(false);
  272. }
  273. /// <summary>
  274. /// 面板全部隐藏
  275. /// </summary>
  276. void ViewSetFalse()
  277. {
  278. toolView.SetActive(false);
  279. bodyView.SetActive(false);
  280. nieLianView.SetActive(false);
  281. clothView.SetActive(false);
  282. }
  283. void BackView_Extra(GameObject _obj,bool _bo) {
  284. ViewSetFalse();
  285. _obj.SetActive(_bo);
  286. ViewSetChildTrue(_obj,_bo);
  287. }
  288. void ViewSetChildTrue(GameObject _obj,bool _bo)
  289. {
  290. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  291. _obj.transform.GetChild(0).gameObject.SetActive(_bo);
  292. _obj.transform.GetChild(2).gameObject.SetActive(!_bo);
  293. }
  294. /// <summary>
  295. /// 返回的方法二
  296. /// </summary>
  297. void Back_TwoFun(bool _bo)
  298. {
  299. // int _choose = int.Parse(histroy[1]);
  300. // switch ((ECustomStyple)_choose)
  301. whitebg.SetActive(false);
  302. switch(eCustomStyple)
  303. {
  304. case ECustomStyple.Body:
  305. BackView_Extra(bodyView,_bo);
  306. break;
  307. case ECustomStyple.Cloth:
  308. BackView_Extra(clothView, _bo);
  309. break;
  310. case ECustomStyple.None:
  311. break;
  312. case ECustomStyple.NieLian:
  313. BackView_Extra(nieLianView, _bo);
  314. break;
  315. }
  316. //toolView.SetActive(true);
  317. //bodyView.SetActive(false);
  318. //nieLianView.SetActive(false);
  319. //clothView.SetActive(false);
  320. }
  321. /// <summary>
  322. /// 返回的方法三
  323. /// </summary>
  324. void Back_ThreeFun()
  325. {
  326. string[] _strArrary = histroy[histroy.Count - 1].Split(',');
  327. if (_strArrary[0] == "Color")
  328. {
  329. colorView.SetActive(false);
  330. rightView.SetActive(true);
  331. }
  332. else if (_strArrary[0] == "ziDingyi")
  333. {
  334. int _chooseId = int.Parse(_strArrary[1]);
  335. ClickBtnFun(eCustomStyple, _chooseId, false,hasColorChoose);
  336. }
  337. else
  338. {
  339. Debug.Log("缺少当前情况需要添加>>>>");
  340. }
  341. //toolView.SetActive(true);
  342. //bodyView.SetActive(false);
  343. //nieLianView.SetActive(false);
  344. //clothView.SetActive(false);
  345. }
  346. public void PickOnButton(GameObject _obj,int _id) {
  347. if (_obj.transform.childCount <= 0)
  348. {
  349. return;
  350. }
  351. GameObject _nowPickOnImg = _obj.transform.GetChild(0).gameObject;
  352. if (nowPickOnImg==null)
  353. {
  354. nowPickOnImg = _nowPickOnImg;
  355. id = _id;
  356. nowPickOnImg.SetActive(true);
  357. }
  358. else
  359. {
  360. if (_id != id)
  361. {
  362. nowPickOnImg.SetActive(false);
  363. id = _id;
  364. nowPickOnImg = _nowPickOnImg;
  365. _nowPickOnImg.SetActive(true);
  366. }
  367. else
  368. {
  369. nowPickOnImg = _nowPickOnImg;
  370. _nowPickOnImg.SetActive(!_nowPickOnImg.activeSelf);
  371. }
  372. }
  373. scrollbar.gameObject.SetActive(nowPickOnImg.activeSelf);
  374. }
  375. /// <summary>
  376. /// 修改滑块
  377. /// </summary>
  378. public void SetValue(int _part,ECustomStyple eCustomStyple)
  379. {
  380. //scrollbar.value = _value;
  381. part = _part;
  382. scrollbar.value = CustomManager.Instance.GetBodyBoneValue(part);
  383. }
  384. /// <summary>
  385. /// 获得滑块值
  386. /// </summary>
  387. public float GetValue()
  388. {
  389. return scrollbar.value;
  390. }
  391. /// <summary>
  392. /// 修改颜色
  393. /// </summary>
  394. public void SetColor(int _part, ECustomStyple eCustomStyple)
  395. {
  396. //scrollbar.value = _value;
  397. part = _part;
  398. }
  399. /// <summary>
  400. /// 按钮点击事件
  401. /// </summary>
  402. public void ClickBtnFun(ECustomStyple eCustomStyple,int id,bool zidingyi,bool isColor) {
  403. //if (isTween)
  404. //{
  405. // return;
  406. //}
  407. hasColorChoose = isColor;
  408. whitebg.SetActive(true);
  409. scrollbar.gameObject.SetActive(false);
  410. this.eCustomStyple = eCustomStyple;
  411. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  412. switch (eCustomStyple)
  413. {
  414. case ECustomStyple.None:
  415. break;
  416. case ECustomStyple.NieLian:
  417. GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  418. _nieLianList.SetActive(false);
  419. GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  420. _nieLianXX.SetActive(true);
  421. //if (!zidingyi)
  422. //{
  423. // ZiDingYiNeiLian(eCustomStyple, id, _nieLianXX.transform.GetChild(0).gameObject);
  424. // return;
  425. //}
  426. CreateNieLianImg(id, zidingyi,isColor);
  427. break;
  428. case ECustomStyple.Body:
  429. GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  430. _bodyList.SetActive(false);
  431. GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  432. _bodyListXX.SetActive(true);
  433. //if (!zidingyi)
  434. //{
  435. // ZiDingYiBody(eCustomStyple, id, _bodyListXX.transform.GetChild(0).gameObject);
  436. // return;
  437. //}
  438. CreateBodyImg(id, zidingyi,isColor);
  439. break;
  440. case ECustomStyple.Cloth:
  441. GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  442. _clothList.SetActive(false);
  443. GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  444. _clothListXX.SetActive(true);
  445. //if (!zidingyi)
  446. //{
  447. // ZiDingYiCloth(eCustomStyple, id, _clothListXX.transform.GetChild(0).gameObject);
  448. // return;
  449. //}
  450. CreateClothImg(id, zidingyi,isColor);
  451. break;
  452. }
  453. }
  454. //public Action ActionFun() {
  455. // return null;
  456. //}
  457. private void RemoveAllChildren(GameObject parent)
  458. {
  459. Transform transform;
  460. for (int i = 0; i < parent.transform.childCount; i++)
  461. {
  462. transform = parent.transform.GetChild(i);
  463. GameObject.Destroy(transform.gameObject);
  464. }
  465. }
  466. //public void ZiDingYiNeiLian(ECustomStyple eCustomStyple, int id,GameObject _objPar) {
  467. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  468. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  469. // _obj.transform.SetParent(_objPar.transform);
  470. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  471. // _uICustomBtn.id = id;
  472. // _uICustomBtn.eCustomStyple = eCustomStyple;
  473. // _obj.SetActive(true);
  474. //}
  475. //public void ZiDingYiBody(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  476. //{
  477. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  478. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  479. // _obj.transform.SetParent(_objPar.transform);
  480. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  481. // _uICustomBtn.id = id;
  482. // _uICustomBtn.eCustomStyple = eCustomStyple;
  483. // _obj.SetActive(true);
  484. //}
  485. //public void ZiDingYiCloth(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  486. //{
  487. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  488. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  489. // _obj.transform.SetParent(_objPar.transform);
  490. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  491. // _uICustomBtn.id = id;
  492. // _uICustomBtn.eCustomStyple = eCustomStyple;
  493. // _obj.SetActive(true);
  494. //}
  495. public void CreateNieLianImg(int parentid, bool ziDingYi, bool isColor)
  496. {
  497. GameObject _objPar = nieLianView.transform.GetChild(2).GetChild(0).gameObject;
  498. RemoveAllChildren(_objPar);
  499. //等有捏脸表时改为捏脸
  500. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  501. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  502. int cengji = ziDingYi ? 0 : 1;
  503. if (ziDingYi)
  504. {
  505. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  506. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  507. //_obj.transform.SetParent(_objPar.transform);
  508. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  509. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  510. //_uICustomBtn.id =parentid;
  511. //_uICustomBtn.eCustomStyple = eCustomStyple;
  512. //_obj.SetActive(true);
  513. }
  514. if (isColor)
  515. {
  516. CreateColFun(parentid, _objPar,colItem);
  517. }
  518. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  519. for (int i = 0; i < dRCustomBodies.Length; i++)
  520. {
  521. Debug.Log(dRCustomBodies[i].Id);
  522. if (dRCustomBodies[i].ParentStyple == parentid&&dRCustomBodies[i].Cengji==cengji)
  523. {
  524. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body, dRCustomBodies[i].IsActive);
  525. }
  526. }
  527. ChangeListBotton(_objPar);
  528. }
  529. public void CreateClothImg(int parentid,bool ziDingYi, bool isColor)
  530. {
  531. GameObject _objPar = clothView.transform.GetChild(2).GetChild(0).gameObject;
  532. RemoveAllChildren(_objPar);
  533. //等有服装时改为服装
  534. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  535. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  536. int cengji = ziDingYi ? 0 : 1;
  537. if (ziDingYi)
  538. {
  539. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  540. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  541. //_obj.transform.SetParent(_objPar.transform);
  542. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  543. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  544. //_uICustomBtn.id = parentid;
  545. //_uICustomBtn.eCustomStyple = eCustomStyple;
  546. //_obj.SetActive(true);
  547. }
  548. if (isColor)
  549. {
  550. CreateColFun(parentid, _objPar, colItem);
  551. }
  552. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  553. for (int i = 0; i < dRCustomBodies.Length; i++)
  554. {
  555. Debug.Log(dRCustomBodies[i].Id);
  556. if (dRCustomBodies[i].ParentStyple == parentid && dRCustomBodies[i].Cengji == cengji)
  557. {
  558. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body, dRCustomBodies[i].IsActive);
  559. }
  560. }
  561. ChangeListBotton(_objPar);
  562. }
  563. private void CreateZDYFun(int parentid,GameObject _objPar,GameObject _clone)
  564. {
  565. GameObject _obj = GameObject.Instantiate(_clone);
  566. _obj.transform.SetParent(_objPar.transform);
  567. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  568. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  569. }
  570. private void CreateColFun(int parentid, GameObject _objPar, GameObject _clone)
  571. {
  572. GameObject _obj = GameObject.Instantiate(_clone);
  573. _obj.transform.SetParent(_objPar.transform);
  574. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  575. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  576. nowChooseColorObj = _obj;
  577. }
  578. //private void CreateColorFun(int parentid, GameObject _objPar, GameObject _clone)
  579. //{
  580. // GameObject _obj = GameObject.Instantiate(_clone);
  581. // _obj.transform.SetParent(_objPar.transform);
  582. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  583. // ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  584. //}
  585. public void ChangeUICustom(UICustomBtn uICustomBtn,int id, ECustomStyple eCustomStyple)
  586. {
  587. uICustomBtn.id = id;
  588. uICustomBtn.eCustomStyple = eCustomStyple;
  589. uICustomBtn.gameObject.SetActive(true);
  590. }
  591. public void CreateBodyImg(int parentid,bool ziDingYi, bool isColor) {
  592. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  593. RemoveAllChildren(_objPar);
  594. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  595. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  596. int cengji = ziDingYi ?0:1;
  597. if (ziDingYi)
  598. {
  599. CreateZDYFun(parentid, _objPar,ziDingYiBtn);
  600. //GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  601. //_obj.transform.SetParent(_objPar.transform);
  602. //UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  603. //ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  604. //_uICustomBtn.id = parentid;
  605. //_uICustomBtn.eCustomStyple = eCustomStyple;
  606. //_obj.SetActive(true);
  607. }
  608. if (isColor)
  609. {
  610. CreateColFun(parentid, _objPar, colItem);
  611. }
  612. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  613. for (int i = 0; i < dRCustomBodies.Length; i++)
  614. {
  615. Debug.Log(dRCustomBodies[i].Id);
  616. if (dRCustomBodies[i].ParentStyple == parentid && dRCustomBodies[i].Cengji == cengji)
  617. {
  618. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body, dRCustomBodies[i].IsActive);
  619. }
  620. }
  621. ChangeListBotton(_objPar);
  622. }
  623. /// <summary>
  624. /// 改变列表长短
  625. /// </summary>
  626. public void ChangeListBotton(GameObject _obj) {
  627. //Debug.Log("改变列表"+ _obj.transform.childCount+"");
  628. float _x = _obj.GetComponent<RectTransform>().offsetMin.x;
  629. int _childNum = _obj.transform.childCount;
  630. float _y = _childNum > 7 ? -240 * (_childNum - 7) : 0;
  631. _obj.GetComponent<RectTransform>().offsetMax = new Vector2(_x, 0);
  632. _obj.GetComponent<RectTransform>().offsetMin = new Vector2(_x, _y);
  633. }
  634. //private IEnumerator Tween(Action _action) {
  635. // for (int i = 0; i < 100; i++)
  636. // {
  637. // float _value = i / 100;
  638. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  639. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  640. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  641. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  642. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  643. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  644. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  645. // }
  646. // yield return null;
  647. //}
  648. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  649. {
  650. base.OnUpdate(elapseSeconds, realElapseSeconds);
  651. }
  652. //private void CreateNieLianFun(object[] _objects) {
  653. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  654. // switch (_eNieLianStyple)
  655. // {
  656. // case ENieLianStyple.faxing:
  657. // break;
  658. // case ENieLianStyple.lianxing:
  659. // break;
  660. // case ENieLianStyple.yankuang:
  661. // break;
  662. // case ENieLianStyple.tongkong:
  663. // break;
  664. // case ENieLianStyple.meimao:
  665. // break;
  666. // case ENieLianStyple.bizi:
  667. // break;
  668. // case ENieLianStyple.erduo:
  669. // break;
  670. // case ENieLianStyple.zuiba:
  671. // break;
  672. // case ENieLianStyple.fuse:
  673. // break;
  674. // }
  675. // //switch()
  676. //}
  677. private void CreateButtonFun(string path,int _part,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple,int _isactive) {
  678. //Debug.Log(path);
  679. // Debug.Log(_parent);
  680. path = "CustomRole/" + path;
  681. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  682. (assetName, asset, duration, userData) =>
  683. {
  684. // Debug.Log(path);
  685. // Debug.Log(_parent);
  686. Texture2D tex = (Texture2D)asset;
  687. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  688. GameObject _obj = GameObject.Instantiate(buttonItem);
  689. Image _objImg = _obj.transform.GetComponent<Image>();
  690. _obj.SetActive(true);
  691. _objImg.sprite = sprite;
  692. _obj.name = part+"";
  693. _obj.transform.SetParent(_parent.transform);
  694. if (_isactive != 1)
  695. {
  696. _obj.SetActive(false);
  697. }
  698. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  699. uICustomBtn.id = _id;
  700. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  701. uICustomBtn.eCustomStyple = eCustomStyple;
  702. uICustomBtn.isCreate = false;
  703. uICustomBtn.part = _part;
  704. //GameObject
  705. //img.sprite = sprite;
  706. //if (nativeSize)
  707. //{
  708. // img.SetNativeSize();
  709. //}
  710. ChangeListBotton(_parent);
  711. }));
  712. }
  713. //public void NieLian() {
  714. //}
  715. public void ClickFaceChangeBtn()
  716. {
  717. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  718. }
  719. }
  720. public enum ECustomStyple
  721. {
  722. None,
  723. NieLian,
  724. Body,
  725. Cloth
  726. }
  727. public enum EButtonStyple
  728. {
  729. Button,
  730. Scroll,
  731. TiaoSe,
  732. NorButton,
  733. Back
  734. }
  735. public enum ENieLianStyple {
  736. None,
  737. faxing,
  738. lianxing,
  739. yankuang,
  740. tongkong,
  741. meimao,
  742. bizi,
  743. erduo,
  744. zuiba,
  745. fuse
  746. }
  747. public enum EButtonShunXu {
  748. None,
  749. First,
  750. Second,
  751. Third
  752. }
  753. public enum ETSStyple {
  754. None,
  755. ViewOpen,
  756. Close,
  757. Sure,
  758. Open,
  759. Button
  760. }
  761. }