UICustom.cs 30 KB

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