CustomManager.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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("标准女").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(dtCB[i].Id, 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. //更新数据
  56. IDataTable<DRCustomBody> drCB = GameEntry.DataTable.GetDataTable<DRCustomBody>();
  57. var formData = drCB.GetDataRow(crf.Part);
  58. if(formData == null)
  59. {
  60. Debug.LogError(crf.Part + ": 表里不存在此行数据");
  61. return;
  62. }
  63. bodyData.bodyList[crf.Part].floatValue = 1 + (crf.ChangeValue.x - 0.5f) * valueFloating;
  64. //通过更新的数据更新骨骼缩放
  65. if (testPlayer != null)
  66. {
  67. switch ((ModifyType)formData.ModifyType)
  68. {
  69. case ModifyType.Length:
  70. testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(0, 0, 1), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue);
  71. break;
  72. case ModifyType.Width:
  73. testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(0, 1, 0), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue);
  74. break;
  75. case ModifyType.Thick:
  76. testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(1, 0, 0), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue);
  77. break;
  78. case ModifyType.LengthWidthThick:
  79. testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(1, 1, 1), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue);
  80. break;
  81. case ModifyType.Angle:
  82. break;
  83. case ModifyType.UpDown:
  84. break;
  85. case ModifyType.LeftRight:
  86. break;
  87. case ModifyType.ForwardBehind:
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. public float GetBodyBoneValue(int id)
  96. {
  97. return 0.5f + (bodyData.bodyList[id].floatValue - 1) / valueFloating;
  98. }
  99. /// <summary>
  100. /// 重置角色数据
  101. /// </summary>
  102. public void ResetRole()
  103. {
  104. if(testPlayer == null)
  105. {
  106. Debug.LogError("没有模型存在");
  107. return;
  108. }
  109. Debug.Log("重置模型");
  110. foreach (var item in bodyData.bodyList)
  111. {
  112. var key = item.Key;
  113. var value = item.Value;
  114. value.floatValue = 1;
  115. }
  116. //重置缩放
  117. foreach (var item in bodyData.orginLocalScaleList)
  118. {
  119. var key = item.Key;
  120. var value = item.Value;
  121. testPlayer.SetBoneScale(key, value);
  122. }
  123. //重置旋转
  124. foreach (var item in bodyData.orginLocalRotationList)
  125. {
  126. var key = item.Key;
  127. var value = item.Value;
  128. testPlayer.SetBoneRot(key, value);
  129. }
  130. //重置位置
  131. foreach (var item in bodyData.orginLocalPositionList)
  132. {
  133. var key = item.Key;
  134. var value = item.Value;
  135. testPlayer.SetBonePos(key, value);
  136. }
  137. }
  138. }
  139. }