UICustom.cs 30 KB

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