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.PositionWeight = 0f; 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 = ik_ctrl.IKTgtRoot.gameObject.AddComponent(); 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 override float PositionWeight { get { return this.Chain.bendConstraint.weight; } set { this.Chain.bendConstraint.weight = value; } } public override float RotationWeight { get; set; } public ShoulderThighIKData ShoulderThighData { get { return this.m_ShoulderThighData; } } public HandFootIKData HandFootData { get { return this.m_HandFootData; } } 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, this.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.IKPositionWeight = this.PositionWeight; this.m_FABRIK.solver.Update(); this.TargetBone.rotation = rotation; } } private ShoulderThighIKData m_ShoulderThighData; private HandFootIKData m_HandFootData; private FABRIK m_FABRIK; private Quaternion m_HandFootLocalRot = Quaternion.identity; private Quaternion m_TargetBoneLocalRot = Quaternion.identity; }