CustomRoleForm.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. namespace MetaClient
  13. {
  14. public class CustomRoleForm : UGuiForm
  15. {
  16. public Text curShow;
  17. public RectTransform Scroll;
  18. public Slider curSlider;
  19. public Button[] btnList;
  20. public GameObject point;
  21. private EditableBodyPart curSelect = EditableBodyPart.None;
  22. private List<Transform> bonesTrans = new List<Transform>();
  23. private List<GameObject> pointList = new List<GameObject>();
  24. #if UNITY_2017_3_OR_NEWER
  25. protected override void OnOpen(object userData)
  26. #else
  27. protected internal override void OnOpen(object userData)
  28. #endif
  29. {
  30. base.OnOpen(userData);
  31. RefreshBtn();
  32. bonesTrans = CustomManager.Instance.testPlayer.GetBonesTrans();
  33. for (int i = 0; i < bonesTrans.Count; i++)
  34. {
  35. var newpoint = GameObject.Instantiate(point,transform);
  36. pointList.Add(newpoint);
  37. }
  38. Scroll.anchoredPosition = new Vector2(82, Scroll.anchoredPosition.y);
  39. Scroll.DOAnchorPosX(-85, 0.5f).SetEase(Ease.InOutCubic).onComplete = () =>
  40. {
  41. };
  42. }
  43. private void Start()
  44. {
  45. RefreshBtn();
  46. }
  47. private void RefreshBtn()
  48. {
  49. for (int i = 0; i < btnList.Length; i++)
  50. {
  51. var btn = btnList[i];
  52. btn.GetComponentInChildren<Text>().text = ((EditableBodyPart)i).ToString();
  53. }
  54. }
  55. #if UNITY_2017_3_OR_NEWER
  56. protected override void OnClose(bool isShutdown, object userData)
  57. #else
  58. protected internal override void OnClose(bool isShutdown, object userData)
  59. #endif
  60. {
  61. base.OnClose(isShutdown, userData);
  62. }
  63. public void ClickFaceChangeBtn(int part)
  64. {
  65. curSelect = (EditableBodyPart)part;
  66. RefreshSliderValue();
  67. }
  68. public void Update()
  69. {
  70. UpdateCustomBodyBoneTransShow();
  71. }
  72. private void RefreshSliderValue()
  73. {
  74. curShow.text = curSelect.ToString();
  75. curSlider.value = CustomManager.Instance.GetBodyBoneValue(curSelect);
  76. }
  77. public void OnSliderValueChange(float value)
  78. {
  79. if(curSelect == EditableBodyPart.None)
  80. {
  81. return;
  82. }
  83. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(curSelect, new Vector3(value, 0, 0)));
  84. }
  85. private void UpdateCustomBodyBoneTransShow()
  86. {
  87. for (int i = 0; i < bonesTrans.Count; i++)
  88. {
  89. var point = pointList[i];
  90. var pos = Camera.main.WorldToScreenPoint(bonesTrans[i].position);
  91. point.transform.position = pos;
  92. }
  93. }
  94. }
  95. }