CustomManager.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using GameFramework.Event;
  5. using UnityEngine;
  6. using HumanoidEditor;
  7. namespace MetaClient
  8. {
  9. public class CustomManager : MonoBehaviour
  10. {
  11. public static CustomManager Instance;
  12. public RoleCustomData bodyData;
  13. public const float valueFloating = 1f;
  14. public CustomRoleController testPlayer = null;
  15. private void Awake()
  16. {
  17. Instance = this;
  18. }
  19. public void Init()
  20. {
  21. GameEntry.Event.Subscribe(CustomRoleBodyEventArgs.EventId, UpdateBody);
  22. testPlayer = GameObject.Find("biaozhunnv").GetComponent<CustomRoleController>();
  23. bodyData = new RoleCustomData();
  24. for (int i = 0; i < 6; i++)
  25. {
  26. bodyData.bodyList.Add(i, new PartData((EditableBodyPart)i, ModifyType.LengthWidthThick));
  27. }
  28. //初始缩放
  29. testPlayer.GetNormalAniBonesScale(ref bodyData.orginLocalScaleList);
  30. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.Chest);
  31. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperArmUp);
  32. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperArmDown);
  33. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperLegUp);
  34. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperLegDown);
  35. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.LowerLegUp);
  36. testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.LowerLegDown);
  37. //初始位置
  38. testPlayer.GetExtraAniBonesPosition(ref bodyData.orginLocalPositionList, EditableBodyPart.Chest);
  39. //初始旋转
  40. testPlayer.GetExtraAniBonesRotate(ref bodyData.orginLocalRotationList, EditableBodyPart.Chest);
  41. }
  42. public void Clear()
  43. {
  44. GameEntry.Event.Unsubscribe(CustomRoleBodyEventArgs.EventId, UpdateBody);
  45. }
  46. private void UpdateBody(object sender, GameEventArgs e)
  47. {
  48. CustomRoleBodyEventArgs crf = (CustomRoleBodyEventArgs)e;
  49. if (crf != null)
  50. {
  51. bodyData.bodyList[(int)crf.Part].floatValue = 1 + (crf.ChangeValue.x - 0.5f) * valueFloating;
  52. if (testPlayer != null)
  53. {
  54. testPlayer.UpdateBoneScale(crf.Part, bodyData.bodyList[(int)crf.Part].floatValue);
  55. }
  56. }
  57. }
  58. public float GetBodyBoneValue(EditableBodyPart part)
  59. {
  60. return 0.5f + (bodyData.bodyList[(int)part].floatValue - 1) / valueFloating;
  61. }
  62. /// <summary>
  63. /// 重置角色数据
  64. /// </summary>
  65. public void ResetRole()
  66. {
  67. if(testPlayer == null)
  68. {
  69. Debug.LogError("没有模型存在");
  70. return;
  71. }
  72. Debug.Log("重置模型");
  73. foreach (var item in bodyData.bodyList)
  74. {
  75. var key = item.Key;
  76. var value = item.Value;
  77. value.floatValue = 1;
  78. }
  79. //重置缩放
  80. foreach (var item in bodyData.orginLocalScaleList)
  81. {
  82. var key = item.Key;
  83. var value = item.Value;
  84. testPlayer.SetBoneScale(key, value);
  85. }
  86. //重置旋转
  87. foreach (var item in bodyData.orginLocalRotationList)
  88. {
  89. var key = item.Key;
  90. var value = item.Value;
  91. testPlayer.SetBoneRot(key, value);
  92. }
  93. //重置位置
  94. foreach (var item in bodyData.orginLocalPositionList)
  95. {
  96. var key = item.Key;
  97. var value = item.Value;
  98. testPlayer.SetBonePos(key, value);
  99. }
  100. }
  101. }
  102. }