UICustom.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 clothView;
  32. [Header("左边界面")]
  33. public GameObject leftView;
  34. [Header("右边界面")]
  35. public GameObject rightView;
  36. //[Header("点击后生成的按钮列表")]
  37. //public GameObject buttonList;
  38. [Header("按钮预制体")]
  39. public GameObject buttonItem;
  40. [Header("滑块")]
  41. public Scrollbar scrollbar;
  42. [Header("颜色演示预制体")]
  43. public GameObject colItem;
  44. public float tween_leftMax = 0;
  45. public float tween_leftMin = -250;
  46. public float tween_rightMin = 0;
  47. public float tween_rightMax = 223;
  48. private float tween_saveBtnMax = 119;
  49. private float tween_saveBtnMin = -108;
  50. //private float tweenTime = 10;
  51. //private float tweenLeastTime = 0;
  52. public bool isTween = false;
  53. [Header("选择界面分支")]
  54. [SerializeField]
  55. private ECustomStyple eCustomStyple = ECustomStyple.None;
  56. [Header("历史记录用于回退")]
  57. [SerializeField]
  58. private List<string> histroy;
  59. private int part = 0;
  60. //[Header("接受到的数据")]
  61. //[SerializeField]
  62. private IDataTable<DRCustomBody> _bodydata;
  63. protected override void OnOpen(object userData)
  64. {
  65. base.OnOpen(userData);
  66. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  67. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  68. }
  69. protected override void OnClose(bool isShutdown, object userData)
  70. {
  71. base.OnClose(isShutdown, userData);
  72. }
  73. public void ClickBotton(ECustomStyple eCustomStyple,int id)
  74. {
  75. if (isTween)
  76. {
  77. return;
  78. }
  79. isTween = true;
  80. leftView.transform.DOLocalMoveX(tween_leftMin, 2f).SetEase(Ease.InOutBack).OnComplete(()=> {
  81. ClickBtnFun(eCustomStyple,id);
  82. leftView.transform.DOLocalMoveX(0, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  83. isTween = false;
  84. Debug.Log("222");
  85. });
  86. });
  87. Debug.Log("333");
  88. rightView.transform.DOLocalMoveX(tween_rightMax, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  89. rightView.transform.DOLocalMoveX(0, 2f).SetEase(Ease.InOutBack).OnComplete(() => {
  90. });
  91. });
  92. }
  93. /// <summary>
  94. /// 滑块改变
  95. /// </summary>
  96. public void ScrollValueChange()
  97. {
  98. Debug.Log(scrollbar.value);
  99. }
  100. /// <summary>
  101. /// 修改滑块
  102. /// </summary>
  103. public void SetValue(int _part,ECustomStyple eCustomStyple)
  104. {
  105. //scrollbar.value = _value;
  106. part = _part;
  107. }
  108. /// <summary>
  109. /// 获得滑块值
  110. /// </summary>
  111. public float GetValue()
  112. {
  113. return scrollbar.value;
  114. }
  115. /// <summary>
  116. /// 按钮点击事件
  117. /// </summary>
  118. public void ClickBtnFun(ECustomStyple eCustomStyple,int id) {
  119. //if (isTween)
  120. //{
  121. // return;
  122. //}
  123. //ECustomStyple _eCustomStyple = (ECustomStyple)int.Parse(_objects[0].ToString());
  124. switch (eCustomStyple)
  125. {
  126. case ECustomStyple.None:
  127. break;
  128. case ECustomStyple.NieLian:
  129. GameObject _nieLianList = nieLianView.transform.GetChild(0).gameObject;
  130. _nieLianList.SetActive(false);
  131. GameObject _nieLianXX = nieLianView.transform.GetChild(2).gameObject;
  132. _nieLianXX.SetActive(true);
  133. CreateBodyImg(id);
  134. break;
  135. case ECustomStyple.Body:
  136. GameObject _bodyList = bodyView.transform.GetChild(0).gameObject;
  137. _bodyList.SetActive(false);
  138. GameObject _bodyListXX =bodyView.transform.GetChild(2).gameObject;
  139. _bodyListXX.SetActive(true);
  140. CreateBodyImg(id);
  141. break;
  142. case ECustomStyple.Cloth:
  143. GameObject _clothList = clothView.transform.GetChild(0).gameObject;
  144. _clothList.SetActive(false);
  145. GameObject _clothListXX = clothView.transform.GetChild(2).gameObject;
  146. _clothListXX.SetActive(true);
  147. CreateBodyImg(id);
  148. break;
  149. }
  150. }
  151. //public Action ActionFun() {
  152. // return null;
  153. //}
  154. private void RemoveAllChildren(GameObject parent)
  155. {
  156. Transform transform;
  157. for (int i = 0; i < parent.transform.childCount; i++)
  158. {
  159. transform = parent.transform.GetChild(i);
  160. GameObject.Destroy(transform.gameObject);
  161. }
  162. }
  163. public void CreateBodyImg(int parentid) {
  164. RemoveAllChildren(bodyView.transform.GetChild(2).GetChild(0).gameObject);
  165. IDataTable<DRCustomBody> _data = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  166. _bodydata = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  167. DRCustomBody[] dRCustomBodies = _bodydata.GetAllDataRows();
  168. for (int i = 0; i < dRCustomBodies.Length; i++)
  169. {
  170. Debug.Log(dRCustomBodies[i].Id);
  171. if (dRCustomBodies[i].ParentStyple == parentid)
  172. {
  173. 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);
  174. }
  175. }
  176. }
  177. //private IEnumerator Tween(Action _action) {
  178. // for (int i = 0; i < 100; i++)
  179. // {
  180. // float _value = i / 100;
  181. // float _right=Mathf.Lerp(tween_rightMax, tween_rightMin, _value);
  182. // float _left= Mathf.Lerp(tween_leftMix, tween_rightMax, _value);
  183. // clothView.GetComponent<RectTransform>().SetPositionX(_right);
  184. // toolView.GetComponent<RectTransform>().SetPositionX(_right);
  185. // bodyView.GetComponent<RectTransform>().SetPositionX(_right);
  186. // nieLianView.GetComponent<RectTransform>().SetPositionX(_right);
  187. // baseView.GetComponent<RectTransform>().SetPositionX(_left);
  188. // }
  189. // yield return null;
  190. //}
  191. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  192. {
  193. base.OnUpdate(elapseSeconds, realElapseSeconds);
  194. }
  195. //private void CreateNieLianFun(object[] _objects) {
  196. // ENieLianStyple _eNieLianStyple = (ENieLianStyple)int.Parse(_objects[1].ToString());
  197. // switch (_eNieLianStyple)
  198. // {
  199. // case ENieLianStyple.faxing:
  200. // break;
  201. // case ENieLianStyple.lianxing:
  202. // break;
  203. // case ENieLianStyple.yankuang:
  204. // break;
  205. // case ENieLianStyple.tongkong:
  206. // break;
  207. // case ENieLianStyple.meimao:
  208. // break;
  209. // case ENieLianStyple.bizi:
  210. // break;
  211. // case ENieLianStyple.erduo:
  212. // break;
  213. // case ENieLianStyple.zuiba:
  214. // break;
  215. // case ENieLianStyple.fuse:
  216. // break;
  217. // }
  218. // //switch()
  219. //}
  220. private void CreateButtonFun(string path,int _part,string _name, GameObject _parent,int _id,int buttonstyple,ECustomStyple eCustomStyple) {
  221. //Debug.Log(path);
  222. // Debug.Log(_parent);
  223. path = "CustomRole/" + path;
  224. GameEntry.Resource.LoadAsset(AssetUtility.GetUISpriteAsset(path), new LoadAssetCallbacks(
  225. (assetName, asset, duration, userData) =>
  226. {
  227. // Debug.Log(path);
  228. // Debug.Log(_parent);
  229. Texture2D tex = (Texture2D)asset;
  230. var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
  231. GameObject _obj = GameObject.Instantiate(buttonItem);
  232. Image _objImg = _obj.transform.GetComponent<Image>();
  233. _obj.SetActive(true);
  234. _objImg.sprite = sprite;
  235. _obj.name = part+"";
  236. _obj.transform.SetParent(_parent.transform);
  237. UICustomBtn uICustomBtn = _obj.GetComponent<UICustomBtn>();
  238. uICustomBtn.id = _id;
  239. uICustomBtn.eButtonStyple = (EButtonStyple)buttonstyple;
  240. uICustomBtn.eCustomStyple = eCustomStyple;
  241. uICustomBtn.isCreate = false;
  242. uICustomBtn.part = _part;
  243. //GameObject
  244. //img.sprite = sprite;
  245. //if (nativeSize)
  246. //{
  247. // img.SetNativeSize();
  248. //}
  249. }));
  250. }
  251. //public void NieLian() {
  252. //}
  253. public void ClickFaceChangeBtn()
  254. {
  255. GameEntry.Event.Fire(this, CustomRoleFaceEventArgs.Create(EditableFacePart.eye, new Vector3(1, 0, 0)));
  256. }
  257. }
  258. public enum ECustomStyple
  259. {
  260. None,
  261. NieLian,
  262. Body,
  263. Cloth
  264. }
  265. public enum EButtonStyple
  266. {
  267. Button,
  268. Scroll,
  269. TiaoSe,
  270. NorButton,
  271. }
  272. public enum ENieLianStyple {
  273. None,
  274. faxing,
  275. lianxing,
  276. yankuang,
  277. tongkong,
  278. meimao,
  279. bizi,
  280. erduo,
  281. zuiba,
  282. fuse
  283. }
  284. }