CustomRoleForm.cs 2.9 KB

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