BodyCtrlData.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. this.PositionWeight = data.BlendWeight;
  108. }
  109. public void SetAllOffset(Vector3 offset)
  110. {
  111. if (!base.IsIKExec)
  112. {
  113. base.PointIK.IsIKExec = true;
  114. this.PositionWeight = 1f;
  115. }
  116. this.DoAllOffset = true;
  117. this.m_AllOffset = offset;
  118. }
  119. public void SetAddOffset(Vector3 offset)
  120. {
  121. if (!base.IsIKExec)
  122. {
  123. base.PointIK.IsIKExec = true;
  124. this.PositionWeight = 1f;
  125. }
  126. this.m_AddOffset = offset;
  127. }
  128. public override void ApplyIKSetting()
  129. {
  130. this.m_AddOffset = Vector3.zero;
  131. this.DoAllOffset = false;
  132. this.m_PosOffset = this.OrijinMaidPos;
  133. this.m_AllOffset = this.OrijinAllPos;
  134. base.ApplyIKSetting();
  135. }
  136. 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)
  137. {
  138. this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
  139. this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
  140. base.SetIKSetting(attachType, is_another, tgt_maid, slot_no, attach_name, axis_bone, target, f_vecOffset, do_animation);
  141. }
  142. public override void Update()
  143. {
  144. if (this.DoAllOffset)
  145. {
  146. GameMain.Instance.CharacterMgr.SetCharaAllPos(this.m_AllOffset);
  147. }
  148. if (!this.CheckDoIK())
  149. {
  150. return;
  151. }
  152. this.MyIKCtrl.TgtMaid.SetPos(this.BodyOffset);
  153. }
  154. public override void Detach(IKCtrlData.IKAttachType attachType)
  155. {
  156. this.m_lastPosOffset = this.m_PosOffset - this.OrijinMaidPos;
  157. base.Detach(attachType);
  158. base.BlendPosRot.Copy(this.PosBaseBone);
  159. this.m_AddOffset = Vector3.zero;
  160. this.HeightFit = BodyCtrlData.HeightFitType.None;
  161. this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
  162. this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
  163. }
  164. [SerializeField]
  165. private Vector3 m_PosOffset = Vector3.zero;
  166. private Vector3 m_AddOffset = Vector3.zero;
  167. private Vector3 m_FirstBonePos = Vector3.zero;
  168. private Vector3 m_lastPosOffset = Vector3.zero;
  169. [SerializeField]
  170. private Vector3 m_AllOffset = Vector3.zero;
  171. public Transform PosBaseBone;
  172. public BodyCtrlData.HeightFitType HeightFit = BodyCtrlData.HeightFitType.None;
  173. public enum HeightFitType
  174. {
  175. Higher,
  176. Lower,
  177. None
  178. }
  179. }