UICustom.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. private EButtonShunXu eButtonShunXu = EButtonShunXu.None;
  48. [Header("颜色演示预制体")]
  49. public GameObject colItem;
  50. public float tween_leftMax = 0;
  51. public float tween_leftMin = -250;
  52. public float tween_rightMin = 0;
  53. public float tween_rightMax = 223;
  54. private float tween_saveBtnMax = 119;
  55. private float tween_saveBtnMin = -108;
  56. //private float tweenTime = 10;
  57. //private float tweenLeastTime = 0;
  58. public bool isTween = false;
  59. [Header("选择界面分支")]
  60. [SerializeField]
  61. private ECustomStyple eCustomStyple = ECustomStyple.None;
  62. [Header("历史记录用于回退")]
  63. [SerializeField]
  64. private List<string> histroy;
  65. private int part = 0;
  66. //[Header("接受到的数据")]
  67. //[SerializeField]
  68. private IDataTable<DRCustomBody> _bodydata;
  69. protected override void OnOpen(object userData)
  70. {
  71. base.OnOpen(userData);
  72. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  73. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  74. }
  75. protected override void OnClose(bool isShutdown, object userData)
  76. {
  77. base.OnClose(isShutdown, userData);
  78. }
  79. public void ClickBotton(ECustomStyple eCustomStyple,int id,bool ziDingYi)
  80. {
  81. if (isTween)
  82. {
  83. return;
  84. }
  85. isTween = true;
  86. leftView.transform.DOLocalMoveX(tween_leftMin, 2f).SetEase(Ease.InOutBack).OnComplete(()=> {
  87. //whitebg.SetActive(bg);
  88. ClickBtnFun(eCustomStyple,id,ziDingYi);
  89. leftView.transform.DOLocalMoveX(0, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  90. isTween = false;
  91. Debug.Log("222");
  92. });
  93. });
  94. Debug.Log("333");
  95. rightView.transform.DOLocalMoveX(tween_rightMax, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  96. rightView.transform.DOLocalMoveX(0, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  97. });
  98. });
  99. }
  100. /// <summary>
  101. /// 设置是否已在缓动
  102. /// </summary>
  103. public void SetTween(bool _bo) {
  104. isTween = _bo;
  105. }
  106. /// <summary>
  107. /// 获取是否缓动
  108. /// </summary>
  109. public bool GetTween()
  110. {
  111. return isTween;
  112. }
  113. public void HistoryAdd(string _str) {
  114. histroy.Add(_str);
  115. }
  116. /// <summary>
  117. /// 滑块改变
  118. /// </summary>
  119. public void ScrollValueChange()
  120. {
  121. Debug.Log(scrollbar.value);
  122. }
  123. /// <summary>
  124. /// 修改滑块
  125. /// </summary>
  126. public void SetValue(int _part,ECustomStyple eCustomStyple)
  127. {
  128. //scrollbar.value = _value;
  129. part = _part;
  130. }
  131. /// <summary>
  132. /// 获得滑块值
  133. /// </summary>
  134. public float GetValue()
  135. {
  136. return scrollbar.value;
  137. }
  138. /// <summary>
  139. /// 按钮点击事件
  140. /// </summary>
  141. public void ClickBtnFun(ECustomStyple eCustomStyple,int id,bool zidingyi) {
  142. //if (isTween)
  143. //{
  144. // return;
  145. //}
  146. whitebg.SetActive(true);
  147. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  148. switch (eCustomStyple)
  149. {
  150. case ECustomStyple.None:
  151. break;
  152. case ECustomStyple.NieLian:
  153. GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  154. _nieLianList.SetActive(false);
  155. GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  156. _nieLianXX.SetActive(true);
  157. //if (!zidingyi)
  158. //{
  159. // ZiDingYiNeiLian(eCustomStyple, id, _nieLianXX.transform.GetChild(0).gameObject);
  160. // return;
  161. //}
  162. CreateNieLianImg(id, zidingyi);
  163. break;
  164. case ECustomStyple.Body:
  165. GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  166. _bodyList.SetActive(false);
  167. GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  168. _bodyListXX.SetActive(true);
  169. //if (!zidingyi)
  170. //{
  171. // ZiDingYiBody(eCustomStyple, id, _bodyListXX.transform.GetChild(0).gameObject);
  172. // return;
  173. //}
  174. CreateBodyImg(id, zidingyi);
  175. break;
  176. case ECustomStyple.Cloth:
  177. GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  178. _clothList.SetActive(false);
  179. GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  180. _clothListXX.SetActive(true);
  181. //if (!zidingyi)
  182. //{
  183. // ZiDingYiCloth(eCustomStyple, id, _clothListXX.transform.GetChild(0).gameObject);
  184. // return;
  185. //}
  186. CreateClothImg(id, zidingyi);
  187. break;
  188. }
  189. }
  190. //public Action ActionFun() {
  191. // return null;
  192. //}
  193. private void RemoveAllChildren(GameObject parent)
  194. {
  195. Transform transform;
  196. for (int i = 0; i < parent.transform.childCount; i++)
  197. {
  198. transform = parent.transform.GetChild(i);
  199. GameObject.Destroy(transform.gameObject);
  200. }
  201. }
  202. //public void ZiDingYiNeiLian(ECustomStyple eCustomStyple, int id,GameObject _objPar) {
  203. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  204. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  205. // _obj.transform.SetParent(_objPar.transform);
  206. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  207. // _uICustomBtn.id = id;
  208. // _uICustomBtn.eCustomStyple = eCustomStyple;
  209. // _obj.SetActive(true);
  210. //}
  211. //public void ZiDingYiBody(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  212. //{
  213. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  214. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  215. // _obj.transform.SetParent(_objPar.transform);
  216. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  217. // _uICustomBtn.id = id;
  218. // _uICustomBtn.eCustomStyple = eCustomStyple;
  219. // _obj.SetActive(true);
  220. //}
  221. //public void ZiDingYiCloth(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  222. //{
  223. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  224. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  225. // _obj.transform.SetParent(_objPar.transform);
  226. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  227. // _uICustomBtn.id = id;
  228. // _uICustomBtn.eCustomStyple = eCustomStyple;
  229. // _obj.SetActive(true);
  230. //}
  231. public void CreateNieLianImg(int parentid, bool ziDingYi)
  232. {
  233. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  234. RemoveAllChildren(_objPar);
  235. //等有捏脸表时改为捏脸
  236. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  237. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  238. int cengji = ziDingYi ? 0 : 1;
  239. if (ziDingYi)
  240. {
  241. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  242. _obj.transform.SetParent(_objPar.transform);
  243. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  244. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  245. //_uICustomBtn.id =parentid;
  246. //_uICustomBtn.eCustomStyple = eCustomStyple;
  247. //_obj.SetActive(true);
  248. }
  249. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  250. for (int i = 0; i < dRCustomBodies.Length; i++)
  251. {
  252. Debug.Log(dRCustomBodies[i].Id);
  253. if (dRCustomBodies[i].ParentStyple == parentid)
  254. {
  255. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  256. }
  257. }
  258. // ChangeListBotton(_objPar);
  259. }
  260. public void CreateClothImg(int parentid,bool ziDingYi)
  261. {
  262. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  263. RemoveAllChildren(_objPar);
  264. //等有服装时改为服装
  265. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  266. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  267. int cengji = ziDingYi ? 0 : 1;
  268. if (ziDingYi)
  269. {
  270. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  271. _obj.transform.SetParent(_objPar.transform);
  272. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  273. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  274. //_uICustomBtn.id = parentid;
  275. //_uICustomBtn.eCustomStyple = eCustomStyple;
  276. //_obj.SetActive(true);
  277. }
  278. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  279. for (int i = 0; i < dRCustomBodies.Length; i++)
  280. {
  281. Debug.Log(dRCustomBodies[i].Id);
  282. if (dRCustomBodies[i].ParentStyple == parentid)
  283. {
  284. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  285. }
  286. }
  287. // ChangeListBotton(_objPar);
  288. }
  289. public void ChangeUICustom(UICustomBtn uICustomBtn,int id, ECustomStyple eCustomStyple)
  290. {
  291. uICustomBtn.id = id;
  292. uICustomBtn.eCustomStyple = eCustomStyple;
  293. uICustomBtn.gameObject.SetActive(true);
  294. }
  295. public void CreateBodyImg(int parentid,bool ziDingYi) {
  296. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  297. RemoveAllChildren(_objPar);
  298. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  299. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  300. int cengji = ziDingYi ? 0 : 1;
  301. if (ziDingYi)
  302. {
  303. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  304. _obj.transform.SetParent(_objPar.transform);
  305. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  306. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  307. //_uICustomBtn.id = parentid;
  308. //_uICustomBtn.eCustomStyple = eCustomStyple;
  309. //_obj.SetActive(true);
  310. }
  311. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  312. for (int i = 0; i < dRCustomBodies.Length; i++)
  313. {
  314. Debug.Log(dRCustomBodies[i].Id);
  315. if (dRCustomBodies[i].ParentStyple == parentid)
  316. {
  317. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  318. }
  319. }
  320. // ChangeListBotton(_objPar);
  321. }
  322. /// <summary>
  323. /// 改变列表长短
  324. /// </summary>
  325. public void ChangeListBotton(GameObject _obj) {
  326. //Debug.Log("改变列表"+ _obj.transform.childCount+"");
  327. float _x = _obj.GetComponent<RectTransform>().offsetMin.x;
  328. int _childNum = _obj.transform.childCount;
  329. float _y = _childNum > 8 ? -240 * (_childNum - 8) : 0;
  330. _obj.GetComponent<RectTransform>().offsetMin = new Vector2(_x, _y);
  331. }
  332. //private IEnumerator Tween(Action _action) {
  333. // for (int i = 0; i < 100; i++)
  334. // {
  335. // float _value = i / 100;
  336. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  337. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  338. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  339. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  340. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  341. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  342. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  343. // }
  344. // yield return null;
  345. //}
  346. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  347. {
  348. base.OnUpdate(elapseSeconds, realElapseSeconds);
  349. }
  350. //private void CreateNieLianFun(object[] _objects) {
  351. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  352. // switch (_eNieLianStyple)
  353. // {
  354. // case ENieLianStyple.faxing:
  355. // break;
  356. // case ENieLianStyple.lianxing:
  357. // break;
  358. // case ENieLianStyple.yankuang:
  359. // break;
  360. // case ENieLianStyple.tongkong:
  361. // break;
  362. // case ENieLianStyple.meimao:
  363. // break;
  364. // case ENieLianStyple.bizi:
  365. // break;
  366. // case ENieLianStyple.erduo:
  367. // break;
  368. // case ENieLianStyple.zuiba:
  369. // break;
  370. // case ENieLianStyple.fuse:
  371. // break;
  372. // }
  373. // //switch()
  374. //}
  375. private void CreateButtonFun(string path,int _part,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple) {
  376. //Debug.Log(path);
  377. // Debug.Log(_parent);
  378. path = "CustomRole/" + path;
  379. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  380. (assetName, asset, duration, userData) =>
  381. {
  382. // Debug.Log(path);
  383. // Debug.Log(_parent);
  384. Texture2D tex = (Texture2D)asset;
  385. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  386. GameObject _obj = GameObject.Instantiate(buttonItem);
  387. Image _objImg = _obj.transform.GetComponent<Image>();
  388. _obj.SetActive(true);
  389. _objImg.sprite = sprite;
  390. _obj.name = part+"";
  391. _obj.transform.SetParent(_parent.transform);
  392. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  393. uICustomBtn.id = _id;
  394. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  395. uICustomBtn.eCustomStyple = eCustomStyple;
  396. uICustomBtn.isCreate = false;
  397. uICustomBtn.part = _part;
  398. //GameObject
  399. //img.sprite = sprite;
  400. //if (nativeSize)
  401. //{
  402. // img.SetNativeSize();
  403. //}
  404. ChangeListBotton(_parent);
  405. }));
  406. }
  407. //public void NieLian() {
  408. //}
  409. public void ClickFaceChangeBtn()
  410. {
  411. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  412. }
  413. }
  414. public enum ECustomStyple
  415. {
  416. None,
  417. NieLian,
  418. Body,
  419. Cloth
  420. }
  421. public enum EButtonStyple
  422. {
  423. Button,
  424. Scroll,
  425. TiaoSe,
  426. NorButton,
  427. }
  428. public enum ENieLianStyple {
  429. None,
  430. faxing,
  431. lianxing,
  432. yankuang,
  433. tongkong,
  434. meimao,
  435. bizi,
  436. erduo,
  437. zuiba,
  438. fuse
  439. }
  440. public enum EButtonShunXu {
  441. None,
  442. First,
  443. Second,
  444. Third
  445. }
  446. }