123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using UnityEngine;
- [Serializable]
- public class BodyCtrlData : IKCtrlData
- {
- public BodyCtrlData(FullBodyIKCtrl ik_ctrl) : base(ik_ctrl, ik_ctrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Root), false, false)
- {
- this.PosBaseBone = this.TargetBone;
- this.m_ChainBones = new Transform[]
- {
- this.TargetBone
- };
- this.m_ForceIKEnable = false;
- }
- public bool IsDoSetCharaPos { get; private set; }
- public Vector3 OrijinMaidPos { get; private set; }
- public override void ApplyIKSetting()
- {
- this.OrijinMaidPos = this.MyIKCtrl.TgtChara.GetPos();
- this.m_PosOffset = Vector3.zero;
- base.ApplyIKSetting();
- }
- private bool CheckDoIK()
- {
- if (!base.IsIKExec)
- {
- return false;
- }
- if (this.HeightFit == BodyCtrlData.HeightFitType.None)
- {
- return true;
- }
- int num = this.MyIKCtrl.TgtChara.GetProp(MPN.sintyou).value + this.MyIKCtrl.TgtChara.GetProp(MPN.DouPer).value;
- Maid tgtChara = base.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).curTargetData.TgtChara;
- int num2 = tgtChara.GetProp(MPN.sintyou).value + tgtChara.GetProp(MPN.DouPer).value;
- if (this.HeightFit == BodyCtrlData.HeightFitType.Higher)
- {
- return num > num2;
- }
- return num < num2;
- }
- protected override void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
- {
- if (!data.IsPointAttach || !this.CheckDoIK())
- {
- return;
- }
- if (data.FirstFrame && !data.BlendNow)
- {
- this.m_FirstBonePos = this.PosBaseBone.position;
- }
- Vector3 b = (!data.BlendNow) ? this.m_FirstBonePos : this.PosBaseBone.position;
- pos = ((!data.BlendNow) ? this.m_FirstTgtPosRot.pos : pos);
- base.SetTargetTransform(data, pos, rot);
- Vector3 enable = this.m_OffsetEnable.GetEnable(base.IKTarget.position - b, false);
- if (data.BlendType == IKCtrlData.IKBlendType.IK_To_IK)
- {
- this.m_PosOffset = Vector3.Lerp(this.m_lastPosOffset, enable, data.BlendWeight);
- }
- else if (data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
- {
- this.m_PosOffset = Vector3.Lerp(Vector3.zero, this.m_lastPosOffset, 1f - data.BlendWeight);
- }
- else
- {
- this.m_PosOffset = Vector3.Lerp(Vector3.zero, enable, data.BlendWeight);
- }
- base.PositionWeight = data.BlendWeight;
- }
- public override void Update()
- {
- if (!this.CheckDoIK())
- {
- return;
- }
- this.SetPosOffset(this.m_PosOffset);
- }
- public void SetPosOffset(Vector3 offset)
- {
- if (!base.IsIKExec)
- {
- base.PointIK.IsIKExec = true;
- base.PositionWeight = 1f;
- }
- this.IsDoSetCharaPos = true;
- Vector3 pos = this.MyIKCtrl.TgtChara.GetPos();
- this.MyIKCtrl.TgtChara.SetPos(pos + offset * base.PositionWeight);
- }
- public void CharaPosReset()
- {
- if (this.IsDoSetCharaPos)
- {
- this.MyIKCtrl.TgtChara.SetPos(this.OrijinMaidPos);
- }
- this.IsDoSetCharaPos = false;
- }
- public override void Detach(IKCtrlData.IKAttachType attachType)
- {
- this.m_lastPosOffset = this.m_PosOffset;
- base.Detach(attachType);
- base.BlendPosRot.Copy(this.PosBaseBone);
- this.HeightFit = BodyCtrlData.HeightFitType.None;
- }
- [SerializeField]
- private Vector3 m_PosOffset = Vector3.zero;
- private Vector3 m_FirstBonePos = Vector3.zero;
- private Vector3 m_lastPosOffset = Vector3.zero;
- public Transform PosBaseBone;
- public BodyCtrlData.HeightFitType HeightFit = BodyCtrlData.HeightFitType.None;
- public enum HeightFitType
- {
- Higher,
- Lower,
- None
- }
- }
|