BodyCtrlData.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public class BodyCtrlData : IKCtrlData
  5. {
  6. public BodyCtrlData(FullBodyIKCtrl ik_ctrl) : base(ik_ctrl, ik_ctrl.GetIKBone(IKManager.BoneType.Root), false, false)
  7. {
  8. this.PosBaseBone = this.TargetBone;
  9. this.m_ForceIKEnable = false;
  10. }
  11. public Vector3 OrijinMaidPos { get; private set; }
  12. public Vector3 OrijinAllPos { get; private set; }
  13. public bool DoAllOffset { get; private set; }
  14. public Vector3 BodyOffset
  15. {
  16. get
  17. {
  18. return this.m_PosOffset + this.m_AddOffset;
  19. }
  20. }
  21. public Vector3 AllOffset
  22. {
  23. get
  24. {
  25. return this.m_AllOffset;
  26. }
  27. }
  28. public Vector3 AddOffset
  29. {
  30. get
  31. {
  32. return this.m_AddOffset;
  33. }
  34. }
  35. public override Transform[] ChainBones
  36. {
  37. get
  38. {
  39. return new Transform[]
  40. {
  41. this.MyIKCtrl.GetIKBone(IKManager.BoneType.Root)
  42. };
  43. }
  44. }
  45. public override float PositionWeight { get; set; }
  46. public override float RotationWeight { get; set; }
  47. private bool CheckDoIK()
  48. {
  49. if (!base.IsIKExec)
  50. {
  51. return false;
  52. }
  53. if (this.HeightFit == BodyCtrlData.HeightFitType.None)
  54. {
  55. return true;
  56. }
  57. int value = this.MyIKCtrl.TgtMaid.GetProp(MPN.sintyou).value;
  58. int value2 = base.PointIK.TgtMaid.GetProp(MPN.sintyou).value;
  59. if (this.HeightFit == BodyCtrlData.HeightFitType.Higher)
  60. {
  61. return value < value2;
  62. }
  63. return value > value2;
  64. }
  65. protected override void SetTargetTransform(IKCtrlData.IKParam data, Vector3 pos, Quaternion rot)
  66. {
  67. if (!data.IsPointAttach || !this.CheckDoIK())
  68. {
  69. return;
  70. }
  71. if (data.FirstFrame && !data.BlendNow)
  72. {
  73. this.m_FirstBonePos = this.PosBaseBone.position;
  74. }
  75. Vector3 b = (!data.BlendNow) ? this.m_FirstBonePos : this.PosBaseBone.position;
  76. pos = ((!data.BlendNow) ? this.m_FirstTgtPosRot.pos : pos);
  77. if (!data.DoSetOffset)
  78. {
  79. if (this.OffsetWorld)
  80. {
  81. base.IKTarget.position = pos + data.TgtOffset;
  82. }
  83. else if (this.OffsetBone)
  84. {
  85. KasaiUtility.DrawAxis(pos, this.TargetBone.rotation, 0.0625f);
  86. base.IKTarget.position = pos + this.TargetBone.rotation * data.TgtOffset;
  87. }
  88. else
  89. {
  90. base.IKTarget.position = pos + rot * data.TgtOffset;
  91. }
  92. Debug.DrawLine(pos, base.IKTarget.position, Color.white);
  93. }
  94. Vector3 enable = this.m_OffsetEnable.GetEnable(base.IKTarget.position - b, false);
  95. if (data.BlendType == IKCtrlData.IKBlendType.IK_To_IK)
  96. {
  97. this.m_PosOffset += Vector3.Lerp(this.m_lastPosOffset, enable, data.BlendWeight);
  98. }
  99. else if (data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
  100. {
  101. this.m_PosOffset += Vector3.Lerp(Vector3.zero, enable, 1f - data.BlendWeight);
  102. }
  103. else
  104. {
  105. this.m_PosOffset += Vector3.Lerp(Vector3.zero, enable, data.BlendWeight);
  106. }
  107. }
  108. public void SetAllOffset(Vector3 offset)
  109. {
  110. if (!base.IsIKExec)
  111. {
  112. base.PointIK.IsIKExec = true;
  113. }
  114. this.DoAllOffset = true;
  115. this.m_AllOffset = offset;
  116. }
  117. public void SetAddOffset(Vector3 offset)
  118. {
  119. if (!base.IsIKExec)
  120. {
  121. base.PointIK.IsIKExec = true;
  122. }
  123. this.m_AddOffset = offset;
  124. }
  125. public override void ApplyIKSetting()
  126. {
  127. this.m_AddOffset = Vector3.zero;
  128. this.DoAllOffset = false;
  129. this.m_PosOffset = this.OrijinMaidPos;
  130. this.m_AllOffset = this.OrijinAllPos;
  131. base.ApplyIKSetting();
  132. }
  133. public override void SetIKSetting(IKCtrlData.IKAttachType attachType, bool is_another, Maid tgt_maid, int slot_no, string attach_name, Transform axis_bone, Transform target, Vector3 f_vecOffset, bool do_animation, float blend_time)
  134. {
  135. this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
  136. this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
  137. base.SetIKSetting(attachType, is_another, tgt_maid, slot_no, attach_name, axis_bone, target, f_vecOffset, do_animation, blend_time);
  138. }
  139. public override void Update()
  140. {
  141. if (this.DoAllOffset)
  142. {
  143. GameMain.Instance.CharacterMgr.SetCharaAllPos(this.m_AllOffset);
  144. }
  145. if (!this.CheckDoIK())
  146. {
  147. return;
  148. }
  149. this.MyIKCtrl.TgtMaid.SetPos(this.BodyOffset);
  150. }
  151. public override void Detach(IKCtrlData.IKAttachType attachType, float blend_time = 0f)
  152. {
  153. this.m_lastPosOffset = this.m_PosOffset - this.OrijinMaidPos;
  154. base.Detach(attachType, blend_time);
  155. base.BlendPosRot.Copy(this.PosBaseBone);
  156. this.m_AddOffset = Vector3.zero;
  157. this.HeightFit = BodyCtrlData.HeightFitType.None;
  158. this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
  159. this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
  160. }
  161. [SerializeField]
  162. private Vector3 m_PosOffset = Vector3.zero;
  163. private Vector3 m_AddOffset = Vector3.zero;
  164. private Vector3 m_FirstBonePos = Vector3.zero;
  165. private Vector3 m_lastPosOffset = Vector3.zero;
  166. [SerializeField]
  167. private Vector3 m_AllOffset = Vector3.zero;
  168. public Transform PosBaseBone;
  169. public BodyCtrlData.HeightFitType HeightFit = BodyCtrlData.HeightFitType.None;
  170. public enum HeightFitType
  171. {
  172. Higher,
  173. Lower,
  174. None
  175. }
  176. }