123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using System;
- using kt.ik;
- using kt.Utility;
- using UnityEngine;
- [Serializable]
- public class IKBodyOffsetCtrl : AIKCtrl
- {
- public IKBodyOffsetCtrl(FullBodyIKMgr ik_mgr) : base(ik_mgr, FullBodyIKMgr.IKEffectorType.Body)
- {
- this.posBaseBone = base.bone;
- this.ChainBones = new Transform[]
- {
- base.bone
- };
- this.IsIgnoreLateUpdateEnd = true;
- }
- public bool isCharaPosSetEnd { get; private set; }
- public override void SetIKSetting(IKAttachParam param)
- {
- BodyOffsetIKParam bodyOffsetIKParam = param as BodyOffsetIKParam;
- bodyOffsetIKParam.attachType = AIKCtrl.IKAttachType.NewPoint;
- bodyOffsetIKParam.posOffsetType = AIKCtrl.PosOffsetType.OffsetTarget;
- this.heightFit = bodyOffsetIKParam.heightFitType;
- this.posBaseBone = bodyOffsetIKParam.posBaseBone;
- this.AddOffset = bodyOffsetIKParam.addOffset;
- this.BlendPosOffset = this.lastPosOffset;
- base.SetIKSetting(param);
- }
- public void CheckBlendType()
- {
- if (!base.pointIKData.isIKExec)
- {
- return;
- }
- if (!base.pointIKData.isSetFirstFramePosRot)
- {
- if (base.pointIKData.blendType == AIKCtrl.IKBlendType.Not_Blend)
- {
- base.pointIKData.SetBlendType(AIKCtrl.IKBlendType.IK_To_IK);
- }
- }
- else
- {
- base.pointIKData.SetBlendType(AIKCtrl.IKBlendType.Not_Blend);
- }
- }
- public override void ApplyIKSetting()
- {
- this.PosOffset = Vector3.zero;
- if (base.isIKExec)
- {
- Maid targetChara = base.pointIKData.curTargetData.targetChara;
- if (targetChara && !targetChara.isOffsetUpdateEnd)
- {
- targetChara.OffsetUpdate();
- }
- }
- base.ApplyIKSetting();
- }
- private bool CheckDoIK()
- {
- if (!base.isIKExec)
- {
- return false;
- }
- if (this.heightFit == IKBodyOffsetCtrl.HeightFitType.None)
- {
- return true;
- }
- int num = this.myIKMgr.chara.GetProp(MPN.sintyou).value + this.myIKMgr.chara.GetProp(MPN.DouPer).value;
- Maid targetChara = base.pointIKData.curTargetData.targetChara;
- if (!targetChara)
- {
- return true;
- }
- int num2 = targetChara.GetProp(MPN.sintyou).value + targetChara.GetProp(MPN.DouPer).value;
- if (this.heightFit == IKBodyOffsetCtrl.HeightFitType.Higher)
- {
- return num > num2;
- }
- return num < num2;
- }
- protected override void SetTargetTransform(AIKCtrl.IKSettingData data, Vector3 pos, Quaternion rot)
- {
- if (!data.isPointAttach || !this.CheckDoIK())
- {
- return;
- }
- Vector3 vector = data.curTargetData.tgtOffset + this.AddOffset;
- Transform transform;
- if (data.curTargetData.targetChara)
- {
- transform = data.curTargetData.targetChara.transform;
- }
- else if (data.curTargetData.lastTgtChara)
- {
- transform = data.curTargetData.lastTgtChara.transform;
- }
- else if (data.curTargetData.lastTarget)
- {
- transform = data.curTargetData.lastTarget;
- }
- else
- {
- transform = data.curTargetData.target;
- }
- Transform transform2 = this.myIKMgr.chara.transform;
- if (data.isFirstFrame && !data.isSetFirstFramePosRot)
- {
- this.FirstBaseBonePos = transform2.InverseTransformPoint(this.posBaseBone.position);
- this.FirstLocalTgtPos = transform.InverseTransformPoint(this.FirstTgtPosRot.pos);
- }
- Vector3 vector2 = (!data.isBlendNow) ? transform2.TransformPoint(this.FirstBaseBonePos) : this.posBaseBone.position;
- pos = ((!data.isBlendNow) ? transform.TransformPoint(this.FirstLocalTgtPos) : pos);
- DebugUtility.DrawAxis(pos, rot, 0.0625f);
- vector = transform.TransformDirection(vector);
- base.constraintTarget.position = pos + vector;
- Vector3 vector3 = data.offsetEnable.GetEnable(base.constraintTarget.position - vector2, false);
- DebugUtility.DrawAxis(vector2, rot, 0.0125f);
- Debug.DrawLine(vector2, base.constraintTarget.position, Color.black);
- Debug.DrawRay(pos, vector, Color.gray);
- vector3 = this.myIKMgr.chara.transform.InverseTransformDirection(vector3);
- if (data.blendType == AIKCtrl.IKBlendType.IK_To_IK)
- {
- this.PosOffset = Vector3.Lerp(this.BlendPosOffset, vector3, data.blendWeight);
- }
- else if (data.blendType == AIKCtrl.IKBlendType.IK_To_Detach)
- {
- this.PosOffset = Vector3.Lerp(Vector3.zero, this.BlendPosOffset, base.positionWeight);
- }
- else
- {
- this.PosOffset = Vector3.Lerp(Vector3.zero, vector3, base.positionWeight);
- }
- }
- public override void OnPostFullBodySolverUpdate()
- {
- if (!this.CheckDoIK())
- {
- return;
- }
- this.AddPosOffset(this.PosOffset);
- }
- public void AddPosOffset(Vector3 offset)
- {
- this.isCharaPosSetEnd = true;
- this.myIKMgr.chara.AddPosOffset(offset);
- }
- protected override void SaveLastTargetPosRot()
- {
- base.SaveLastTargetPosRot();
- this.LastIKPosRot.Copy((!(this.posBaseBone != null)) ? base.bone : this.posBaseBone);
- this.lastPosOffset = this.PosOffset;
- }
- public void CharaPosReset()
- {
- this.isCharaPosSetEnd = false;
- }
- public override void Detach()
- {
- this.BlendPosOffset = this.lastPosOffset;
- base.Detach();
- this.heightFit = IKBodyOffsetCtrl.HeightFitType.None;
- }
- [SerializeField]
- private Vector3 PosOffset = Vector3.zero;
- private Vector3 AddOffset = Vector3.zero;
- private Vector3 FirstBaseBonePos;
- private Vector3 FirstLocalTgtPos;
- private Vector3 lastPosOffset = Vector3.zero;
- private Vector3 BlendPosOffset = Vector3.zero;
- public Transform posBaseBone;
- public IKBodyOffsetCtrl.HeightFitType heightFit = IKBodyOffsetCtrl.HeightFitType.None;
- public enum HeightFitType
- {
- Higher,
- Lower,
- None
- }
- }
|