UICustom.cs 38 KB

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