UICustom.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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 ScrollValueChange()
  104. {
  105. Debug.Log(scrollbar.value);
  106. }
  107. /// <summary>
  108. /// 修改滑块
  109. /// </summary>
  110. public void SetValue(int _part,ECustomStyple eCustomStyple)
  111. {
  112. //scrollbar.value = _value;
  113. part = _part;
  114. }
  115. /// <summary>
  116. /// 获得滑块值
  117. /// </summary>
  118. public float GetValue()
  119. {
  120. return scrollbar.value;
  121. }
  122. /// <summary>
  123. /// 按钮点击事件
  124. /// </summary>
  125. public void ClickBtnFun(ECustomStyple eCustomStyple,int id,bool zidingyi) {
  126. //if (isTween)
  127. //{
  128. // return;
  129. //}
  130. whitebg.SetActive(true);
  131. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  132. switch (eCustomStyple)
  133. {
  134. case ECustomStyple.None:
  135. break;
  136. case ECustomStyple.NieLian:
  137. GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  138. _nieLianList.SetActive(false);
  139. GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  140. _nieLianXX.SetActive(true);
  141. //if (!zidingyi)
  142. //{
  143. // ZiDingYiNeiLian(eCustomStyple, id, _nieLianXX.transform.GetChild(0).gameObject);
  144. // return;
  145. //}
  146. CreateNieLianImg(id, zidingyi);
  147. break;
  148. case ECustomStyple.Body:
  149. GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  150. _bodyList.SetActive(false);
  151. GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  152. _bodyListXX.SetActive(true);
  153. //if (!zidingyi)
  154. //{
  155. // ZiDingYiBody(eCustomStyple, id, _bodyListXX.transform.GetChild(0).gameObject);
  156. // return;
  157. //}
  158. CreateBodyImg(id, zidingyi);
  159. break;
  160. case ECustomStyple.Cloth:
  161. GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  162. _clothList.SetActive(false);
  163. GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  164. _clothListXX.SetActive(true);
  165. //if (!zidingyi)
  166. //{
  167. // ZiDingYiCloth(eCustomStyple, id, _clothListXX.transform.GetChild(0).gameObject);
  168. // return;
  169. //}
  170. CreateClothImg(id, zidingyi);
  171. break;
  172. }
  173. }
  174. //public Action ActionFun() {
  175. // return null;
  176. //}
  177. private void RemoveAllChildren(GameObject parent)
  178. {
  179. Transform transform;
  180. for (int i = parent.transform.childCount; i > parent.transform.childCount; i--)
  181. {
  182. transform = parent.transform.GetChild(i);
  183. GameObject.Destroy(transform.gameObject);
  184. }
  185. }
  186. //public void ZiDingYiNeiLian(ECustomStyple eCustomStyple, int id,GameObject _objPar) {
  187. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  188. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  189. // _obj.transform.SetParent(_objPar.transform);
  190. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  191. // _uICustomBtn.id = id;
  192. // _uICustomBtn.eCustomStyple = eCustomStyple;
  193. // _obj.SetActive(true);
  194. //}
  195. //public void ZiDingYiBody(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  196. //{
  197. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  198. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  199. // _obj.transform.SetParent(_objPar.transform);
  200. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  201. // _uICustomBtn.id = id;
  202. // _uICustomBtn.eCustomStyple = eCustomStyple;
  203. // _obj.SetActive(true);
  204. //}
  205. //public void ZiDingYiCloth(ECustomStyple eCustomStyple, int id, GameObject _objPar)
  206. //{
  207. // RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  208. // GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  209. // _obj.transform.SetParent(_objPar.transform);
  210. // UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  211. // _uICustomBtn.id = id;
  212. // _uICustomBtn.eCustomStyple = eCustomStyple;
  213. // _obj.SetActive(true);
  214. //}
  215. public void CreateNieLianImg(int parentid, bool ziDingYi)
  216. {
  217. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  218. RemoveAllChildren(_objPar);
  219. //等有捏脸表时改为捏脸
  220. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  221. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  222. int cengji = ziDingYi ? 0 : 1;
  223. if (ziDingYi)
  224. {
  225. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  226. _obj.transform.SetParent(_objPar.transform);
  227. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  228. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  229. //_uICustomBtn.id =parentid;
  230. //_uICustomBtn.eCustomStyple = eCustomStyple;
  231. //_obj.SetActive(true);
  232. }
  233. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  234. for (int i = 0; i < dRCustomBodies.Length; i++)
  235. {
  236. Debug.Log(dRCustomBodies[i].Id);
  237. if (dRCustomBodies[i].ParentStyple == parentid)
  238. {
  239. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  240. }
  241. }
  242. }
  243. public void CreateClothImg(int parentid,bool ziDingYi)
  244. {
  245. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  246. RemoveAllChildren(_objPar);
  247. //等有服装时改为服装
  248. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  249. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  250. int cengji = ziDingYi ? 0 : 1;
  251. if (ziDingYi)
  252. {
  253. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  254. _obj.transform.SetParent(_objPar.transform);
  255. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  256. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  257. //_uICustomBtn.id = parentid;
  258. //_uICustomBtn.eCustomStyple = eCustomStyple;
  259. //_obj.SetActive(true);
  260. }
  261. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  262. for (int i = 0; i < dRCustomBodies.Length; i++)
  263. {
  264. Debug.Log(dRCustomBodies[i].Id);
  265. if (dRCustomBodies[i].ParentStyple == parentid)
  266. {
  267. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  268. }
  269. }
  270. }
  271. public void ChangeUICustom(UICustomBtn uICustomBtn,int id, ECustomStyple eCustomStyple)
  272. {
  273. uICustomBtn.id = id;
  274. uICustomBtn.eCustomStyple = eCustomStyple;
  275. uICustomBtn.gameObject.SetActive(true);
  276. }
  277. public void CreateBodyImg(int parentid,bool ziDingYi) {
  278. GameObject _objPar = bodyView.transform.GetChild(2).GetChild(0).gameObject;
  279. RemoveAllChildren(_objPar);
  280. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  281. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  282. int cengji = ziDingYi ? 0 : 1;
  283. if (ziDingYi)
  284. {
  285. GameObject _obj = GameObject.Instantiate(ziDingYiBtn);
  286. _obj.transform.SetParent(_objPar.transform);
  287. UICustomBtn _uICustomBtn = _obj.GetComponent<UICustomBtn>();
  288. ChangeUICustom(_uICustomBtn, parentid, eCustomStyple);
  289. //_uICustomBtn.id = parentid;
  290. //_uICustomBtn.eCustomStyple = eCustomStyple;
  291. //_obj.SetActive(true);
  292. }
  293. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  294. for (int i = 0; i < dRCustomBodies.Length; i++)
  295. {
  296. Debug.Log(dRCustomBodies[i].Id);
  297. if (dRCustomBodies[i].ParentStyple == parentid)
  298. {
  299. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, _objPar, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  300. }
  301. }
  302. }
  303. //private IEnumerator Tween(Action _action) {
  304. // for (int i = 0; i < 100; i++)
  305. // {
  306. // float _value = i / 100;
  307. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  308. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  309. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  310. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  311. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  312. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  313. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  314. // }
  315. // yield return null;
  316. //}
  317. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  318. {
  319. base.OnUpdate(elapseSeconds, realElapseSeconds);
  320. }
  321. //private void CreateNieLianFun(object[] _objects) {
  322. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  323. // switch (_eNieLianStyple)
  324. // {
  325. // case ENieLianStyple.faxing:
  326. // break;
  327. // case ENieLianStyple.lianxing:
  328. // break;
  329. // case ENieLianStyple.yankuang:
  330. // break;
  331. // case ENieLianStyple.tongkong:
  332. // break;
  333. // case ENieLianStyple.meimao:
  334. // break;
  335. // case ENieLianStyple.bizi:
  336. // break;
  337. // case ENieLianStyple.erduo:
  338. // break;
  339. // case ENieLianStyple.zuiba:
  340. // break;
  341. // case ENieLianStyple.fuse:
  342. // break;
  343. // }
  344. // //switch()
  345. //}
  346. private void CreateButtonFun(string path,int _part,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple) {
  347. //Debug.Log(path);
  348. // Debug.Log(_parent);
  349. path = "CustomRole/" + path;
  350. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  351. (assetName, asset, duration, userData) =>
  352. {
  353. // Debug.Log(path);
  354. // Debug.Log(_parent);
  355. Texture2D tex = (Texture2D)asset;
  356. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  357. GameObject _obj = GameObject.Instantiate(buttonItem);
  358. Image _objImg = _obj.transform.GetComponent<Image>();
  359. _obj.SetActive(true);
  360. _objImg.sprite = sprite;
  361. _obj.name = part+"";
  362. _obj.transform.SetParent(_parent.transform);
  363. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  364. uICustomBtn.id = _id;
  365. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  366. uICustomBtn.eCustomStyple = eCustomStyple;
  367. uICustomBtn.isCreate = false;
  368. uICustomBtn.part = _part;
  369. //GameObject
  370. //img.sprite = sprite;
  371. //if (nativeSize)
  372. //{
  373. // img.SetNativeSize();
  374. //}
  375. }));
  376. }
  377. //public void NieLian() {
  378. //}
  379. public void ClickFaceChangeBtn()
  380. {
  381. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  382. }
  383. }
  384. public enum ECustomStyple
  385. {
  386. None,
  387. NieLian,
  388. Body,
  389. Cloth
  390. }
  391. public enum EButtonStyple
  392. {
  393. Button,
  394. Scroll,
  395. TiaoSe,
  396. NorButton,
  397. }
  398. public enum ENieLianStyple {
  399. None,
  400. faxing,
  401. lianxing,
  402. yankuang,
  403. tongkong,
  404. meimao,
  405. bizi,
  406. erduo,
  407. zuiba,
  408. fuse
  409. }
  410. public enum EButtonShunXu {
  411. None,
  412. First,
  413. Second,
  414. Third
  415. }
  416. }