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. Debug.Log("1111111111111111111111111");
  42. };
  43. }
  44. private void Start()
  45. {
  46. RefreshBtn();
  47. }
  48. private void RefreshBtn()
  49. {
  50. for (int i = 0; i < btnList.Length; i++)
  51. {
  52. var btn = btnList[i];
  53. btn.GetComponentInChildren<Text>().text = ((EditableBodyPart)i).ToString();
  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 ClickFaceChangeBtn(int part)
  65. {
  66. curSelect = (EditableBodyPart)part;
  67. RefreshSliderValue();
  68. }
  69. public void Update()
  70. {
  71. UpdateCustomBodyBoneTransShow();
  72. }
  73. private void RefreshSliderValue()
  74. {
  75. curShow.text = curSelect.ToString();
  76. curSlider.value = CustomManager.Instance.GetBodyBoneValue(curSelect);
  77. }
  78. public void OnSliderValueChange(float value)
  79. {
  80. if(curSelect == EditableBodyPart.None)
  81. {
  82. return;
  83. }
  84. GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(curSelect, new Vector3(value, 0, 0)));
  85. }
  86. private void UpdateCustomBodyBoneTransShow()
  87. {
  88. for (int i = 0; i < bonesTrans.Count; i++)
  89. {
  90. var point = pointList[i];
  91. var pos = Camera.main.WorldToScreenPoint(bonesTrans[i].position);
  92. point.transform.position = pos;
  93. }
  94. }
  95. }
  96. }