CustomRoleForm.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using UnityGameFramework.Runtime;
  11. using DG.Tweening;
  12. using GameFramework.DataTable;
  13. namespace MetaClient
  14. {
  15. public class CustomRoleForm : UGuiForm
  16. {
  17. public Text curShow;
  18. public RectTransform Scroll;
  19. public Slider curSlider;
  20. public Button[] btnList;
  21. public GameObject point;
  22. public RectTransform listContent;
  23. public GameObject listgo;
  24. private List<Transform> bonesTrans = new List<Transform>();
  25. private List<GameObject> pointList = new List<GameObject>();
  26. private DRCustomBody selectData = null;
  27. #if UNITY_2017_3_OR_NEWER
  28. protected override void OnOpen(object userData)
  29. #else
  30. protected internal override void OnOpen(object userData)
  31. #endif
  32. {
  33. base.OnOpen(userData);
  34. //初始化
  35. IDataTable<DRCustomBody> drCB = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  36. DRCustomBody[] dtCB = drCB.GetAllDataRows();
  37. for (int i = 0; i < dtCB.Length; i++)
  38. {
  39. var go = Instantiate(listgo, listContent);
  40. go.GetComponent<CustomRoleListCell>().Init(dtCB[i],this);
  41. }
  42. bonesTrans = CustomManager.Instance.testPlayer.GetBonesTrans();
  43. for (int i = 0; i < bonesTrans.Count; i++)
  44. {
  45. var newpoint = GameObject.Instantiate(point,transform);
  46. pointList.Add(newpoint);
  47. }
  48. Scroll.anchoredPosition = new Vector2(82, Scroll.anchoredPosition.y);
  49. Scroll.DOAnchorPosX(-85, 0.5f).SetEase(Ease.InOutCubic).onComplete = () =>
  50. {
  51. };
  52. }
  53. private void Start()
  54. {
  55. }
  56. #if UNITY_2017_3_OR_NEWER
  57. protected override void OnClose(bool isShutdown, object userData)
  58. #else
  59. protected internal override void OnClose(bool isShutdown, object userData)
  60. #endif
  61. {
  62. base.OnClose(isShutdown, userData);
  63. }
  64. public void Update()
  65. {
  66. UpdateCustomBodyBoneTransShow();
  67. }
  68. private void RefreshSliderValue()
  69. {
  70. curShow.text = selectData.Name;
  71. curSlider.value = CustomManager.Instance.GetBodyBoneValue(ECustomStyple.Body,selectData.Id);
  72. }
  73. public void OnSliderValueChange(float value)
  74. {
  75. if(selectData == null || selectData.Part == (int)EditableBodyPart.None)
  76. {
  77. return;
  78. }
  79. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(ECustomStyple.Body,selectData.Id, new Vector3(value, 0, 0)));
  80. }
  81. private void UpdateCustomBodyBoneTransShow()
  82. {
  83. for (int i = 0; i < bonesTrans.Count; i++)
  84. {
  85. var point = pointList[i];
  86. var pos = Camera.main.WorldToScreenPoint(bonesTrans[i].position);
  87. point.transform.position = pos;
  88. }
  89. }
  90. public void ClickListCell(DRCustomBody select)
  91. {
  92. selectData = select;
  93. RefreshSliderValue();
  94. }
  95. public void ClickReset()
  96. {
  97. CustomManager.Instance.ResetRole();
  98. }
  99. }
  100. }