UICustom.cs 18 KB

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