CustomManager.cs 4.3 KB

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