123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- using System;
- using UnityEngine;
- [Serializable]
- public class BodyCtrlData : IKCtrlData
- {
- public BodyCtrlData(FullBodyIKCtrl ik_ctrl) : base(ik_ctrl, ik_ctrl.GetIKBone(IKManager.BoneType.Root), false, false)
- {
- this.PosBaseBone = this.TargetBone;
- this.m_ForceIKEnable = false;
- }
- public Vector3 OrijinMaidPos { get; private set; }
- public Vector3 OrijinAllPos { get; private set; }
- public bool DoAllOffset { get; private set; }
- public Vector3 BodyOffset
- {
- get
- {
- return this.m_PosOffset + this.m_AddOffset;
- }
- }
- public Vector3 AllOffset
- {
- get
- {
- return this.m_AllOffset;
- }
- }
- public Vector3 AddOffset
- {
- get
- {
- return this.m_AddOffset;
- }
- }
- public override Transform[] ChainBones
- {
- get
- {
- return new Transform[]
- {
- this.MyIKCtrl.GetIKBone(IKManager.BoneType.Root)
- };
- }
- }
- public override float PositionWeight { get; set; }
- public override float RotationWeight { get; set; }
- private bool CheckDoIK()
- {
- if (!base.IsIKExec)
- {
- return false;
- }
- if (this.HeightFit == BodyCtrlData.HeightFitType.None)
- {
- return true;
- }
- int value = this.MyIKCtrl.TgtMaid.GetProp(MPN.sintyou).value;
- int value2 = base.PointIK.TgtMaid.GetProp(MPN.sintyou).value;
- if (this.HeightFit == BodyCtrlData.HeightFitType.Higher)
- {
- return value < value2;
- }
- return value > value2;
- }
- protected override void SetTargetTransform(IKCtrlData.IKParam 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);
- if (!data.DoSetOffset)
- {
- if (this.OffsetWorld)
- {
- base.IKTarget.position = pos + data.TgtOffset;
- }
- else if (this.OffsetBone)
- {
- KasaiUtility.DrawAxis(pos, this.TargetBone.rotation, 0.0625f);
- base.IKTarget.position = pos + this.TargetBone.rotation * data.TgtOffset;
- }
- else
- {
- base.IKTarget.position = pos + rot * data.TgtOffset;
- }
- Debug.DrawLine(pos, base.IKTarget.position, Color.white);
- }
- 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, enable, 1f - data.BlendWeight);
- }
- else
- {
- this.m_PosOffset += Vector3.Lerp(Vector3.zero, enable, data.BlendWeight);
- }
- this.PositionWeight = data.BlendWeight;
- }
- public void SetAllOffset(Vector3 offset)
- {
- if (!base.IsIKExec)
- {
- base.PointIK.IsIKExec = true;
- this.PositionWeight = 1f;
- }
- this.DoAllOffset = true;
- this.m_AllOffset = offset;
- }
- public void SetAddOffset(Vector3 offset)
- {
- if (!base.IsIKExec)
- {
- base.PointIK.IsIKExec = true;
- this.PositionWeight = 1f;
- }
- this.m_AddOffset = offset;
- }
- public override void ApplyIKSetting()
- {
- this.m_AddOffset = Vector3.zero;
- this.DoAllOffset = false;
- this.m_PosOffset = this.OrijinMaidPos;
- this.m_AllOffset = this.OrijinAllPos;
- base.ApplyIKSetting();
- }
- 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)
- {
- this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
- this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
- base.SetIKSetting(attachType, is_another, tgt_maid, slot_no, attach_name, axis_bone, target, f_vecOffset, do_animation);
- }
- public override void Update()
- {
- if (this.DoAllOffset)
- {
- GameMain.Instance.CharacterMgr.SetCharaAllPos(this.m_AllOffset);
- }
- if (!this.CheckDoIK())
- {
- return;
- }
- this.MyIKCtrl.TgtMaid.SetPos(this.BodyOffset);
- }
- public override void Detach(IKCtrlData.IKAttachType attachType)
- {
- this.m_lastPosOffset = this.m_PosOffset - this.OrijinMaidPos;
- base.Detach(attachType);
- base.BlendPosRot.Copy(this.PosBaseBone);
- this.m_AddOffset = Vector3.zero;
- this.HeightFit = BodyCtrlData.HeightFitType.None;
- this.OrijinMaidPos = this.MyIKCtrl.TgtMaid.GetPos();
- this.OrijinAllPos = GameMain.Instance.CharacterMgr.GetCharaAllPos();
- }
- [SerializeField]
- private Vector3 m_PosOffset = Vector3.zero;
- private Vector3 m_AddOffset = Vector3.zero;
- private Vector3 m_FirstBonePos = Vector3.zero;
- private Vector3 m_lastPosOffset = Vector3.zero;
- [SerializeField]
- private Vector3 m_AllOffset = Vector3.zero;
- public Transform PosBaseBone;
- public BodyCtrlData.HeightFitType HeightFit = BodyCtrlData.HeightFitType.None;
- public enum HeightFitType
- {
- Higher,
- Lower,
- None
- }
- }
|