UICustom.cs 32 KB

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