UICustom.cs 37 KB

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