123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using RootMotion.FinalIK;
- using UnityEngine;
- [Serializable]
- public class ElbowKneeIKData : LimbIKData
- {
- public ElbowKneeIKData(FBIKChain chain, IKMappingLimb ik_mapping, FullBodyIKCtrl ik_ctrl, Transform tgt_bone) : base(ik_ctrl, chain, ik_mapping, tgt_bone, false)
- {
- this.Chain.bendConstraint.bendGoal = base.IKTarget;
- this.m_IsUpperBody = (this.TargetBone == this.MyIKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_L) || this.TargetBone == this.MyIKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_R));
- this.m_ForceIKEnable = true;
- this.m_FABRIK = base.IKTarget.parent.gameObject.AddComponent<FABRIK>();
- this.m_FABRIK.solver.SetChain(new Transform[]
- {
- base.ChainBones[0],
- base.ChainBones[1]
- }, base.ChainBones[0]);
- this.m_FABRIK.solver.target = base.IKTarget;
- this.m_FABRIK.enabled = false;
- }
- public ShoulderThighIKData ShoulderThighData
- {
- get
- {
- return this.m_ShoulderThighData;
- }
- }
- public HandFootIKData HandFootData
- {
- get
- {
- return this.m_HandFootData;
- }
- }
- public override void TagetTransCpy()
- {
- base.TagetTransCpy();
- this.Chain.bendConstraint.weight = 0f;
- this.m_FABRIK.solver.IKPositionWeight = 0f;
- }
- public override void ApplyIKSetting()
- {
- this.m_TargetBoneLocalRot = this.TargetBone.localRotation;
- this.m_HandFootLocalRot = this.HandFootData.TargetBone.localRotation;
- base.ApplyIKSetting();
- }
- protected override void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
- {
- base.SetTargetTransform(data, pos, rot);
- Transform iktarget = this.m_ShoulderThighData.IKTarget;
- if (data.IsPointAttach)
- {
- iktarget.rotation = Quaternion.FromToRotation(this.TargetBone.position - iktarget.position, base.IKTarget.position - iktarget.position) * iktarget.rotation;
- }
- else
- {
- Vector3 axis = base.IKTarget.position - iktarget.position;
- Quaternion rotation = base.IKTarget.rotation;
- Vector3 lhs = rotation * Vector3.forward;
- Vector3 rhs = this.TargetBone.rotation * Vector3.forward;
- float f = Vector3.Dot(lhs, rhs);
- float num = Mathf.Acos(f) * 57.29578f;
- if (float.IsNaN(num))
- {
- num = 0f;
- }
- iktarget.rotation = Quaternion.AngleAxis(num, axis) * iktarget.rotation;
- }
- }
- public void SetChainData(HandFootIKData handfoot_data, ShoulderThighIKData shoulderthigh_data)
- {
- this.m_HandFootData = handfoot_data;
- this.m_ShoulderThighData = shoulderthigh_data;
- }
- public override void Update()
- {
- if (this.HandFootData.IsIKExecTruth)
- {
- return;
- }
- if (base.RotateIK.IsIKExec)
- {
- this.ShoulderThighData.TargetBone.rotation = Quaternion.Slerp(this.ShoulderThighData.TargetBone.rotation, this.ShoulderThighData.IKTarget.rotation, base.RotationWeight);
- this.TargetBone.localRotation = this.m_TargetBoneLocalRot;
- this.HandFootData.TargetBone.localRotation = this.m_HandFootLocalRot;
- }
- Quaternion rotation = this.TargetBone.rotation;
- if (base.PointIK.IsIKExec)
- {
- this.m_FABRIK.solver.Update();
- this.TargetBone.rotation = rotation;
- }
- }
- protected override void OnPostSetPositionWeight(float val)
- {
- if (this.m_IsPullBody)
- {
- this.Chain.bendConstraint.weight = val;
- }
- this.m_FABRIK.solver.IKPositionWeight = val;
- }
- private ShoulderThighIKData m_ShoulderThighData;
- private HandFootIKData m_HandFootData;
- private FABRIK m_FABRIK;
- private Quaternion m_HandFootLocalRot = Quaternion.identity;
- private Quaternion m_TargetBoneLocalRot = Quaternion.identity;
- }
|