UICustom.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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);
  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);
  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);
  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 = 0; 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)
  216. {
  217. RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  218. Debug.Log("子对象" + bodyView.transform.GetChild(2).GetChild(0).gameObject.transform.childCount + "");
  219. //等有捏脸表时改为捏脸
  220. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  221. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  222. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  223. for (int i = 0; i < dRCustomBodies.Length; i++)
  224. {
  225. Debug.Log(dRCustomBodies[i].Id);
  226. if (dRCustomBodies[i].ParentStyple == parentid)
  227. {
  228. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, bodyView.transform.GetChild(2).GetChild(0).gameObject, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  229. }
  230. }
  231. }
  232. public void CreateClothImg(int parentid)
  233. {
  234. RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  235. //等有服装时改为服装
  236. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  237. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  238. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  239. for (int i = 0; i < dRCustomBodies.Length; i++)
  240. {
  241. Debug.Log(dRCustomBodies[i].Id);
  242. if (dRCustomBodies[i].ParentStyple == parentid)
  243. {
  244. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, bodyView.transform.GetChild(2).GetChild(0).gameObject, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  245. }
  246. }
  247. }
  248. public void CreateBodyImg(int parentid) {
  249. RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  250. Debug.Log("子对象" + bodyView.transform.GetChild(2).GetChild(0).gameObject.transform.childCount + "");
  251. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  252. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  253. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  254. for (int i = 0; i < dRCustomBodies.Length; i++)
  255. {
  256. Debug.Log(dRCustomBodies[i].Id);
  257. if (dRCustomBodies[i].ParentStyple == parentid)
  258. {
  259. CreateButtonFun(dRCustomBodies[i].Icon, dRCustomBodies[i].Part, dRCustomBodies[i].Name, bodyView.transform.GetChild(2).GetChild(0).gameObject, dRCustomBodies[i].Id, dRCustomBodies[i].ButtonStyple, ECustomStyple.Body);
  260. }
  261. }
  262. }
  263. //private IEnumerator Tween(Action _action) {
  264. // for (int i = 0; i < 100; i++)
  265. // {
  266. // float _value = i / 100;
  267. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  268. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  269. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  270. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  271. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  272. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  273. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  274. // }
  275. // yield return null;
  276. //}
  277. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  278. {
  279. base.OnUpdate(elapseSeconds, realElapseSeconds);
  280. }
  281. //private void CreateNieLianFun(object[] _objects) {
  282. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  283. // switch (_eNieLianStyple)
  284. // {
  285. // case ENieLianStyple.faxing:
  286. // break;
  287. // case ENieLianStyple.lianxing:
  288. // break;
  289. // case ENieLianStyple.yankuang:
  290. // break;
  291. // case ENieLianStyple.tongkong:
  292. // break;
  293. // case ENieLianStyple.meimao:
  294. // break;
  295. // case ENieLianStyple.bizi:
  296. // break;
  297. // case ENieLianStyple.erduo:
  298. // break;
  299. // case ENieLianStyple.zuiba:
  300. // break;
  301. // case ENieLianStyple.fuse:
  302. // break;
  303. // }
  304. // //switch()
  305. //}
  306. private void CreateButtonFun(string path,int _part,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple) {
  307. //Debug.Log(path);
  308. // Debug.Log(_parent);
  309. path = "CustomRole/" + path;
  310. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  311. (assetName, asset, duration, userData) =>
  312. {
  313. // Debug.Log(path);
  314. // Debug.Log(_parent);
  315. Texture2D tex = (Texture2D)asset;
  316. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  317. GameObject _obj = GameObject.Instantiate(buttonItem);
  318. Image _objImg = _obj.transform.GetComponent<Image>();
  319. _obj.SetActive(true);
  320. _objImg.sprite = sprite;
  321. _obj.name = part+"";
  322. _obj.transform.SetParent(_parent.transform);
  323. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  324. uICustomBtn.id = _id;
  325. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  326. uICustomBtn.eCustomStyple = eCustomStyple;
  327. uICustomBtn.isCreate = false;
  328. uICustomBtn.part = _part;
  329. //GameObject
  330. //img.sprite = sprite;
  331. //if (nativeSize)
  332. //{
  333. // img.SetNativeSize();
  334. //}
  335. }));
  336. }
  337. //public void NieLian() {
  338. //}
  339. public void ClickFaceChangeBtn()
  340. {
  341. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  342. }
  343. }
  344. public enum ECustomStyple
  345. {
  346. None,
  347. NieLian,
  348. Body,
  349. Cloth
  350. }
  351. public enum EButtonStyple
  352. {
  353. Button,
  354. Scroll,
  355. TiaoSe,
  356. NorButton,
  357. }
  358. public enum ENieLianStyple {
  359. None,
  360. faxing,
  361. lianxing,
  362. yankuang,
  363. tongkong,
  364. meimao,
  365. bizi,
  366. erduo,
  367. zuiba,
  368. fuse
  369. }
  370. public enum EButtonShunXu {
  371. None,
  372. First,
  373. Second,
  374. Third
  375. }
  376. }