UICustom.cs 32 KB

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