using System; using System.Collections.Generic; using System.Linq; using kt; using kt.ik; using kt.Physics; using kt.Utility; using RootMotion.FinalIK; using UnityEngine; public class FullBodyIKMgr : MonoBehaviour { public TBody body { get { return this.Body; } } public Maid chara { get { return this.body.maid; } } public Transform ikTargetRoot { get { return this.IKTargetRoot; } } public FullBodyBipedIK ik { get { return this.IK; } } public IKEffector bodyEffector { get { return this.ik.solver.bodyEffector; } } public IKBodyOffsetCtrl bodyOffsetCtrl { get { return this.BodyOffsetCtrl; } } public Dictionary strIKCtrlPair { get { return this.StrIKCtrlPair; } } public float blendTime { get { return this.BlendTime; } set { this.BlendTime = value; foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { aikctrl.blendTime = value; } } } public bool isUpdateEnd { get; private set; } public bool isIKExec { get { bool result; if (this.isIKActive) { result = this.strIKCtrlPair.Any((KeyValuePair ik) => ik.Value.isIKExec); } else { result = false; } return result; } } public bool isNeedAttachTargetUpdatePreExec { get { bool result; if (this.isIKActive) { result = this.strIKCtrlPair.Any((KeyValuePair ik) => ik.Value.isNeedAttachTargetUpdatePreExec); } else { result = false; } return result; } } public Transform planeColliderTrans { get; private set; } public float floorColliderY { get { return this.FloorColliderY; } set { this.FloorColliderY = value; Vector3 localPosition = this.planeColliderTrans.localPosition; localPosition.y = this.FloorColliderY; this.planeColliderTrans.localPosition = localPosition; } } public bool floorColliderEnable { set { foreach (NativePlaneCollider nativePlaneCollider in this.FloorColliderList) { if (nativePlaneCollider) { nativePlaneCollider.enabled = value; } } } } public float wallColliderZ { get { return this.WallColliderZ; } set { this.WallColliderZ = value; Vector3 localPosition = this.planeColliderTrans.localPosition; localPosition.z = this.WallColliderZ; this.planeColliderTrans.localPosition = localPosition; } } public bool wallColliderEnable { set { foreach (NativePlaneCollider nativePlaneCollider in this.WallColliderList) { if (nativePlaneCollider) { nativePlaneCollider.enabled = value; } } } } public bool wallDirectionInverse { set { foreach (NativePlaneCollider nativePlaneCollider in this.WallColliderList) { if (nativePlaneCollider) { nativePlaneCollider.planeStatus.isDirectionInverse = value; } } } } public FullBodyIKMgr.BoneCrossBorder upperCrossBorder { get; private set; } public bool upperBorderEnable { get { return this.upperCrossBorder.left.enabled && this.upperCrossBorder.right.enabled; } set { Behaviour left = this.upperCrossBorder.left; this.upperCrossBorder.right.enabled = value; left.enabled = value; } } public FullBodyIKMgr.BoneCrossBorder lowerCrossBorder { get; private set; } public bool lowerBorderEnable { get { return this.lowerCrossBorder.left.enabled && this.lowerCrossBorder.right.enabled; } set { Behaviour left = this.lowerCrossBorder.left; this.lowerCrossBorder.right.enabled = value; left.enabled = value; } } public HashSet partnerList { get { return this.PartnerList; } } public IKColliderSaveLoader colliderLoader { get; private set; } public void Init() { this.Body = base.GetComponent(); this.DestroyIKObject(); this.IKTargetRoot = new GameObject("IK Target Root").transform; this.IKTargetRoot.SetParent(this.Body.m_trBones, false); if (this.body.IsCrcBody) { this.STRoot = this.Body.m_trBones.Find("ST_Root"); } else if (!this.chara.boMAN) { this.STRoot = this.Body.m_trBones.Find("ST_Root"); } this.PlaneColiderSetUp(); if (this.body.IsCrcBody && !this.colliderLoader) { this.colliderLoader = this.IKTargetRoot.gameObject.AddComponent(); } this.IK = this.IKTargetRoot.gameObject.AddComponent(); this.Mouth = new GameObject("Mouth").transform; this.Mouth.SetParent(this.body.trsHead, false); this.Mouth.localEulerAngles = new Vector3(-90f, 90f, 0f); if (!this.chara.boMAN) { this.NippleL = new GameObject("Nipple_L").transform; this.NippleL.SetParent(CMT.SearchObjName(this.body.m_trBones, "Mune_L_sub", true), false); this.NippleR = new GameObject("Nipple_R").transform; this.NippleR.SetParent(CMT.SearchObjName(this.body.m_trBones, "Mune_R_sub", true), false); } this.NameFlagObjpair.Clear(); this.partnerList.Clear(); this.IKBoneDic = FullBodyIKMgr.GetAllIKBoneDic(this.chara); this.IK.references.root = this.Body.m_trBones; this.IK.references.pelvis = this.GetIKBone(FullBodyIKMgr.IKBoneType.Root); if (this.body.IsCrcBody) { this.IK.references.spine = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3) }; } else if (!this.chara.boMAN) { this.IK.references.spine = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3) }; } else { this.IK.references.spine = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2) }; } this.IK.references.head = this.GetIKBone(FullBodyIKMgr.IKBoneType.Head); this.IK.references.leftUpperArm = this.GetIKBone(FullBodyIKMgr.IKBoneType.UpperArm_L); this.IK.references.leftForearm = this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_L); this.IK.references.leftHand = this.GetIKBone(FullBodyIKMgr.IKBoneType.Hand_L); this.IK.references.rightUpperArm = this.GetIKBone(FullBodyIKMgr.IKBoneType.UpperArm_R); this.IK.references.rightForearm = this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_R); this.IK.references.rightHand = this.GetIKBone(FullBodyIKMgr.IKBoneType.Hand_R); this.IK.references.leftThigh = this.GetIKBone(FullBodyIKMgr.IKBoneType.Thigh_L); this.IK.references.leftCalf = this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_L); this.IK.references.leftFoot = this.GetIKBone(FullBodyIKMgr.IKBoneType.Foot_L); this.IK.references.rightThigh = this.GetIKBone(FullBodyIKMgr.IKBoneType.Thigh_R); this.IK.references.rightCalf = this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_R); this.IK.references.rightFoot = this.GetIKBone(FullBodyIKMgr.IKBoneType.Foot_R); this.IK.solver.SetToReferences(this.IK.references, null); this.IK.fixTransforms = false; foreach (IKEffector ikeffector in this.IK.solver.effectors) { ikeffector.positionWeight = 0f; ikeffector.rotationWeight = 0f; } foreach (FBIKChain fbikchain in this.IK.solver.chain) { fbikchain.bendConstraint.weight = 0f; } this.BodyOffsetCtrl = this.AddBodyCtrl(); if (this.body.IsCrcBody) { this.AddFreeFBIKCtrl(FullBodyIKMgr.IKEffectorType.Head, true, FullBodyIKMgr.IKBoneType.Neck); this.AddMouthIKCtrl(); if (!this.chara.boMAN) { this.AddMuneIKCtrl(FullBodyIKMgr.IKEffectorType.Bust_L); this.AddMuneIKCtrl(FullBodyIKMgr.IKEffectorType.Bust_R); } else { this.AddPenisIKCtrl(); } } this.IK.solver.GetChain(FullBodyBipedChain.LeftLeg).pull = 0f; this.IK.solver.GetChain(FullBodyBipedChain.RightLeg).pull = 0f; this.AddLimbIKCtrl(FullBodyIKMgr.IKEffectorType.Hand_L, FullBodyIKMgr.IKEffectorType.Forearm_L, FullBodyIKMgr.IKEffectorType.UpperArm_L, FullBodyBipedEffector.LeftHand, FullBodyBipedEffector.LeftShoulder); this.AddLimbIKCtrl(FullBodyIKMgr.IKEffectorType.Hand_R, FullBodyIKMgr.IKEffectorType.Forearm_R, FullBodyIKMgr.IKEffectorType.UpperArm_R, FullBodyBipedEffector.RightHand, FullBodyBipedEffector.RightShoulder); this.AddLimbIKCtrl(FullBodyIKMgr.IKEffectorType.Foot_L, FullBodyIKMgr.IKEffectorType.Calf_L, FullBodyIKMgr.IKEffectorType.Thigh_L, FullBodyBipedEffector.LeftFoot, FullBodyBipedEffector.LeftThigh); this.AddLimbIKCtrl(FullBodyIKMgr.IKEffectorType.Foot_R, FullBodyIKMgr.IKEffectorType.Calf_R, FullBodyIKMgr.IKEffectorType.Thigh_R, FullBodyBipedEffector.RightFoot, FullBodyBipedEffector.RightThigh); if (this.body.IsCrcBody) { this.colliderLoader.fullbodyIK = this; this.colliderLoader.fileName = (this.chara.boMAN ? "manIKCollider.ikcol" : "maidIKCollider.ikcol"); this.colliderLoader.ColliderLoad(); } if (!this.bodyEffector.target) { string name2 = this.bodyEffector.bone.name + "_Target"; Transform transform = this.ikTargetRoot.Find(name2); if (!transform) { transform = new GameObject(name2).transform; } transform.SetParent(this.IKTargetRoot, false); this.bodyEffector.target = new GameObject("IKTarget").transform; this.bodyEffector.target.SetParent(transform, false); } this.bodyEffector.effectChildNodes = false; this.IK.enabled = false; if (this.body.IsCrcBody) { Func func = delegate(string name, Transform parent) { GameObject gameObject = new GameObject(name); gameObject.transform.SetParent(parent, false); NativePlaneCollider nativePlaneCollider = gameObject.AddComponent(); nativePlaneCollider.planeStatus.direction = MathUtility.VectorType.Z; NativePlaneCollider nativePlaneCollider2 = gameObject.AddComponent(); nativePlaneCollider2.planeStatus.direction = MathUtility.VectorType.Z; nativePlaneCollider2.planeStatus.isDirectionInverse = true; Behaviour behaviour = nativePlaneCollider; bool enabled = false; nativePlaneCollider2.enabled = enabled; behaviour.enabled = enabled; return new FullBodyIKMgr.BoneCrossBorder(nativePlaneCollider, nativePlaneCollider2); }; this.upperCrossBorder = func("UpperBody_Border", this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3)); this.lowerCrossBorder = func("LowerBody_Border", this.GetIKBone(FullBodyIKMgr.IKBoneType.Pelvis)); } } private IKBodyOffsetCtrl AddBodyCtrl() { IKBodyOffsetCtrl ikbodyOffsetCtrl = new IKBodyOffsetCtrl(this); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[FullBodyIKMgr.IKEffectorType.Body]] = ikbodyOffsetCtrl; this.BodyOffsetCtrl = ikbodyOffsetCtrl; return ikbodyOffsetCtrl; } private ALimbIKCtrl[] AddLimbIKCtrl(FullBodyIKMgr.IKEffectorType hand_foot, FullBodyIKMgr.IKEffectorType elbow_knee, FullBodyIKMgr.IKEffectorType shoulder_thigh, FullBodyBipedEffector handfoot_effector, FullBodyBipedEffector shoulderthigh_effector) { IKSolverFullBodyBiped solver = this.ik.solver; IKMappingLimb limbMapping = solver.GetLimbMapping(handfoot_effector); FBIKChain chain = solver.GetChain(handfoot_effector); ShoulderThighIKCtrl shoulderThighIKCtrl = new ShoulderThighIKCtrl(solver.GetEffector(shoulderthigh_effector), chain, limbMapping, this, shoulder_thigh); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[shoulder_thigh]] = shoulderThighIKCtrl; ElbowKneeIKCtrl elbowKneeIKCtrl = new ElbowKneeIKCtrl(chain, limbMapping, this, elbow_knee); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[elbow_knee]] = elbowKneeIKCtrl; HandFootIKCtrl handFootIKCtrl = new HandFootIKCtrl(solver.GetEffector(handfoot_effector), chain, limbMapping, this, hand_foot); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[hand_foot]] = handFootIKCtrl; shoulderThighIKCtrl.SetChain(handFootIKCtrl, elbowKneeIKCtrl); elbowKneeIKCtrl.SetChain(handFootIKCtrl, shoulderThighIKCtrl); handFootIKCtrl.SetChain(elbowKneeIKCtrl, shoulderThighIKCtrl); return new ALimbIKCtrl[] { shoulderThighIKCtrl, elbowKneeIKCtrl, handFootIKCtrl }; } private FreeFBIKCtrl AddFreeFBIKCtrl(FullBodyIKMgr.IKEffectorType effector_type, bool is_upper, FullBodyIKMgr.IKBoneType bend_bone = FullBodyIKMgr.IKBoneType.None) { FreeFBIKCtrl freeFBIKCtrl = new FreeFBIKCtrl(this, effector_type, is_upper, bend_bone); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[effector_type]] = freeFBIKCtrl; return freeFBIKCtrl; } private PenisIKCtrl AddPenisIKCtrl() { FullBodyIKMgr.IKEffectorType key = FullBodyIKMgr.IKEffectorType.Penis; PenisIKCtrl penisIKCtrl = new PenisIKCtrl(this); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[key]] = penisIKCtrl; return penisIKCtrl; } private MuneIKCtrl AddMuneIKCtrl(FullBodyIKMgr.IKEffectorType effector_type) { MuneIKCtrl muneIKCtrl = new MuneIKCtrl(this, effector_type); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[effector_type]] = muneIKCtrl; return muneIKCtrl; } private MouthIKCtrl AddMouthIKCtrl() { MouthIKCtrl mouthIKCtrl = new MouthIKCtrl(this); this.strIKCtrlPair[FullBodyIKMgr.IKEffectorTypeStrDic[FullBodyIKMgr.IKEffectorType.Mouth]] = mouthIKCtrl; return mouthIKCtrl; } private void PlaneColiderSetUp() { this.FloorColliderList.Clear(); this.WallColliderList.Clear(); if (this.planeColliderTrans) { UnityEngine.Object.DestroyImmediate(this.planeColliderTrans.gameObject); } this.planeColliderTrans = new GameObject(string.Format("IKPlaneCollider_{0}[{1}]", this.chara.boMAN ? "Man" : "Maid", this.chara.ActiveSlotNo)).transform; this.planeColliderTrans.SetParent(base.transform, false); } private void ColiderStateReset() { this.floorColliderEnable = true; this.wallColliderEnable = false; float num = 0f; this.wallColliderZ = num; this.floorColliderY = num; foreach (NativePlaneCollider nativePlaneCollider in this.FloorColliderList) { if (nativePlaneCollider) { nativePlaneCollider.status.center.y = 0f; } } foreach (NativePlaneCollider nativePlaneCollider2 in this.WallColliderList) { if (nativePlaneCollider2) { nativePlaneCollider2.status.center.z = 0f; } } } public void AddFloorCollider(NativePlaneCollider floor_collider) { this.FloorColliderList.Add(floor_collider); } public void AddWallCollider(NativePlaneCollider wall_collider) { this.WallColliderList.Add(wall_collider); } public NativePlaneCollider GetFloorCollider(string ik_name) { ALimbIKCtrl ikctrl = this.GetIKCtrl(ik_name); if (!ikctrl) { return null; } return ikctrl.floorCollider; } public NativePlaneCollider GetWallCollider(string ik_name) { ALimbIKCtrl ikctrl = this.GetIKCtrl(ik_name); if (!ikctrl) { return null; } return ikctrl.wallCollider; } private void Update() { this.isUpdateEnd = false; if (this.bodyOffsetCtrl != null) { this.bodyOffsetCtrl.CharaPosReset(); } } private void OnDisable() { this.AllIKDetach(0f); } private void OnDestroy() { this.DestroyIKObject(); } public void DestroyIKObject() { if (this.ikTargetRoot) { UnityEngine.Object.DestroyImmediate(this.ikTargetRoot.gameObject); } if (this.planeColliderTrans) { UnityEngine.Object.DestroyImmediate(this.planeColliderTrans.gameObject); } if (this.upperCrossBorder != null && this.upperCrossBorder.left) { UnityEngine.Object.DestroyImmediate(this.upperCrossBorder.left.gameObject); } if (this.lowerCrossBorder != null && this.lowerCrossBorder.left) { UnityEngine.Object.DestroyImmediate(this.lowerCrossBorder.left.gameObject); } if (this.Mouth) { UnityEngine.Object.DestroyImmediate(this.Mouth); } if (this.NippleL) { UnityEngine.Object.DestroyImmediate(this.NippleL); } if (this.NippleR) { UnityEngine.Object.DestroyImmediate(this.NippleR); } } public void IKAttach(FullBodyIKMgr.IKEffectorType effector_type, IKAttachParam param) { this.IKAttach(FullBodyIKMgr.IKEffectorTypeStrDic[effector_type], param); } public void IKAttach(string ik_name, IKAttachParam param) { AIKCtrl ikctrl = this.GetIKCtrl(ik_name); if (!ikctrl) { return; } ikctrl.SetIKSetting(param); } public void SetPelvisPull(bool pull_on) { this.IsPelvisPull = pull_on; } public void IKDetach(string name) { AIKCtrl ikctrl = this.GetIKCtrl(name); if (!ikctrl) { return; } if (this.ReservedDetachList.Contains(ikctrl)) { return; } ikctrl.Detach(); } public void IKDetach(FullBodyIKMgr.IKEffectorType effector_type) { this.IKDetach(FullBodyIKMgr.IKEffectorTypeStrDic[effector_type]); } public void IKDetach(string name, float blendtime) { AIKCtrl ikctrl = this.GetIKCtrl(name); if (!ikctrl) { return; } if (this.ReservedDetachList.Contains(ikctrl)) { return; } ikctrl.blendTime = blendtime; ikctrl.Detach(); } public void IKDetach(FullBodyIKMgr.IKEffectorType effector_type, float blendtime) { this.IKDetach(FullBodyIKMgr.IKEffectorTypeStrDic[effector_type], blendtime); } public void AllIKDetach(float blendtime = 0f) { this.isIKActive = (blendtime > 0f); foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { aikctrl.blendTime = blendtime; aikctrl.Detach(); } } public void RemoveReservedDetach(AIKCtrl ik_data) { this.ReservedDetachList.Remove(ik_data); } public void SetAllColliderEnable(bool is_enable) { foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { if (aikctrl is ALimbIKCtrl) { ALimbIKCtrl alimbIKCtrl = aikctrl as ALimbIKCtrl; alimbIKCtrl.colliderEnable = is_enable; } } } public void IKReset() { this.ColiderStateReset(); this.ReservedDetachList.Clear(); this.IsPelvisPull = false; this.ikExecOrder = 0; this.upperBorderEnable = false; this.lowerBorderEnable = false; foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { aikctrl.Reset(); if (aikctrl.isIKExec) { this.ReservedDetachList.Add(aikctrl); } } } public void AllIKResetDetach(float blendtime = 0f) { this.ColiderStateReset(); this.isIKActive = (blendtime > 0f); this.IsPelvisPull = false; this.ikExecOrder = 0; this.upperBorderEnable = false; this.lowerBorderEnable = false; foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { aikctrl.blendTime = blendtime; aikctrl.ResetDetach(); } } public void AddPartner(Maid partner, bool with_partner = false) { if (!this.partnerList.Contains(partner) && partner != this.chara) { this.partnerList.Add(partner); if (with_partner) { partner.body0.fullBodyIK.AddPartner(this.chara, false); } } } public void RemovePartner(Maid partner, bool with_partner = false) { if (this.partnerList.Contains(partner)) { this.partnerList.Remove(partner); if (partner.fullBodyIK && with_partner) { partner.fullBodyIK.RemovePartner(this.chara, false); } } } public void IKUpdate() { if (!this.IsPelvisPull) { this.bodyEffector.positionWeight = 1f; } else { this.bodyEffector.positionWeight = 0f; } this.bodyEffector.target.position = this.bodyEffector.bone.position; this.bodyEffector.target.rotation = this.bodyEffector.bone.rotation; this.isUpdateLate = false; if (this.ReservedDetachList.Count > 0) { for (int i = 0; i < this.ReservedDetachList.Count; i++) { this.ReservedDetachList[i].Detach(); } this.ReservedDetachList.Clear(); } if (this.body.IsCrcBody) { if (this.upperBorderEnable) { this.SetBorderCenter(this.upperCrossBorder, this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_R)); } if (this.lowerBorderEnable) { this.SetBorderCenter(this.lowerCrossBorder, this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_R)); } } this.BodyOffsetUpdate(); if (this.isUpdateLate) { return; } foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { if (!(aikctrl is IKBodyOffsetCtrl)) { aikctrl.TargetTransCpy(); } } foreach (AIKCtrl aikctrl2 in this.strIKCtrlPair.Values) { if (!(aikctrl2 is IKBodyOffsetCtrl)) { aikctrl2.ApplyIKSetting(); } } if (!this.isUpdateLate) { if (this.isIKExec) { this.SolverUpdate(); } else { foreach (AIKCtrl aikctrl3 in this.strIKCtrlPair.Values) { aikctrl3.OnPostIKUpdate(); } } } } private void SetBorderCenter(FullBodyIKMgr.BoneCrossBorder cross_border, Transform left_bone, Transform right_bone) { NativePlaneCollider left = cross_border.left; NativePlaneCollider right = cross_border.right; Transform parent = left.transform.parent; float d = Mathf.Min(Vector3.Dot(left_bone.position - parent.position, left.worldDirection), 0f); float d2 = Mathf.Min(Vector3.Dot(right_bone.position - parent.position, right.worldDirection), 0f); left.planeStatus.center = left.localDirection * d; right.planeStatus.center = right.localDirection * d2; } private void BodyOffsetUpdate() { if (this.bodyOffsetCtrl.isCharaPosSetEnd) { return; } this.bodyOffsetCtrl.TargetTransCpy(); this.bodyOffsetCtrl.ApplyIKSetting(); if (this.isUpdateLate) { return; } if (this.bodyOffsetCtrl.isIKExec && this.isIKActive) { this.bodyOffsetCtrl.OnPostFullBodySolverUpdate(); } foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { if (aikctrl is ALimbIKCtrl && !aikctrl.isIKExec) { ALimbIKCtrl alimbIKCtrl = aikctrl as ALimbIKCtrl; if (alimbIKCtrl.correctType != ALimbIKCtrl.BorderCorrectType.HalfBody) { alimbIKCtrl.HitCheck(); } } } } private void SolverUpdate() { this.isUpdateEnd = true; if (this.isIKActive && this.isIKExec) { bool flag = false; foreach (AIKCtrl aikctrl in this.strIKCtrlPair.Values) { if (!(aikctrl is IKBodyOffsetCtrl)) { flag = aikctrl.isNeedFullbodySolverUpdate; if (flag) { break; } } } if (flag) { Vector3 localPosition = this.ik.references.spine[1].localPosition; this.ik.solver.Update(); this.ik.references.spine[1].localPosition = localPosition; } foreach (AIKCtrl aikctrl2 in this.strIKCtrlPair.Values) { if (!(aikctrl2 is IKBodyOffsetCtrl)) { aikctrl2.OnPostFullBodySolverUpdate(); } } } foreach (AIKCtrl aikctrl3 in this.strIKCtrlPair.Values) { aikctrl3.OnPostIKUpdate(); } if (this.isIKActive) { this.onPostSolverUpdate.Invoke(); } } public void LateIKUpdate() { this.IKUpdate(); this.body.AutoTwist(); this.body.IKAttachTargetUpdate(); } public Transform GetIKBone(FullBodyIKMgr.IKEffectorType effector_type) { return this.GetIKBone(FullBodyIKMgr.IKEffectorBonePair[effector_type]); } public Transform GetIKBone(FullBodyIKMgr.IKBoneType boneType) { return (!this.IKBoneDic.ContainsKey(boneType)) ? null : this.IKBoneDic[boneType]; } public Transform[] GetChainBonesToInit(FullBodyIKMgr.IKEffectorType effector_type) { return this.GetChainBonesToInit(FullBodyIKMgr.IKEffectorBonePair[effector_type]); } public Transform[] GetChainBonesToInit(FullBodyIKMgr.IKBoneType boneType) { Transform[] result = new Transform[0]; switch (boneType) { case FullBodyIKMgr.IKBoneType.ChinkoNub: if (this.chara.boMAN) { if (this.body.IsCrcBody) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko3), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko4), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko5), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko6), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko7), this.GetIKBone(FullBodyIKMgr.IKBoneType.ChinkoNub) }; } else { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Chinko2), this.GetIKBone(FullBodyIKMgr.IKBoneType.ChinkoNub) }; } } break; case FullBodyIKMgr.IKBoneType.Thigh_R: case FullBodyIKMgr.IKBoneType.Calf_R: case FullBodyIKMgr.IKBoneType.Foot_R: result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Thigh_R), this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_R), this.GetIKBone(FullBodyIKMgr.IKBoneType.Foot_R) }; break; case FullBodyIKMgr.IKBoneType.Thigh_L: case FullBodyIKMgr.IKBoneType.Calf_L: case FullBodyIKMgr.IKBoneType.Foot_L: result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Thigh_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Calf_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Foot_L) }; break; case FullBodyIKMgr.IKBoneType.Bust_L: case FullBodyIKMgr.IKBoneType.Bust_L_Sub: if (!this.chara.boMAN) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Bust_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Bust_L_Sub) }; } break; case FullBodyIKMgr.IKBoneType.Bust_R: case FullBodyIKMgr.IKBoneType.Bust_R_Sub: if (!this.chara.boMAN) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Bust_R), this.GetIKBone(FullBodyIKMgr.IKBoneType.Bust_R_Sub) }; } break; case FullBodyIKMgr.IKBoneType.Mouth: if (this.body.IsCrcBody) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck), this.GetIKBone(FullBodyIKMgr.IKBoneType.Head), this.GetIKBone(FullBodyIKMgr.IKBoneType.Mouth) }; } break; default: switch (boneType) { case FullBodyIKMgr.IKBoneType.Neck: if (this.body.IsCrcBody) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck) }; } else if (!this.chara.boMAN) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck) }; } else { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck) }; } break; case FullBodyIKMgr.IKBoneType.Head: if (this.body.IsCrcBody) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck), this.GetIKBone(FullBodyIKMgr.IKBoneType.Head) }; } else if (!this.chara.boMAN) { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine3), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck), this.GetIKBone(FullBodyIKMgr.IKBoneType.Head) }; } else { result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine0), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine1), this.GetIKBone(FullBodyIKMgr.IKBoneType.Spine2), this.GetIKBone(FullBodyIKMgr.IKBoneType.Neck), this.GetIKBone(FullBodyIKMgr.IKBoneType.Head) }; } break; case FullBodyIKMgr.IKBoneType.UpperArm_R: case FullBodyIKMgr.IKBoneType.Forearm_R: case FullBodyIKMgr.IKBoneType.Hand_R: result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.UpperArm_R), this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_R), this.GetIKBone(FullBodyIKMgr.IKBoneType.Hand_R) }; break; case FullBodyIKMgr.IKBoneType.UpperArm_L: case FullBodyIKMgr.IKBoneType.Forearm_L: case FullBodyIKMgr.IKBoneType.Hand_L: result = new Transform[] { this.GetIKBone(FullBodyIKMgr.IKBoneType.UpperArm_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Forearm_L), this.GetIKBone(FullBodyIKMgr.IKBoneType.Hand_L) }; break; } break; } return result; } public AIKCtrl GetIKCtrl(string tag_name) { if (this.strIKCtrlPair.ContainsKey(tag_name)) { return this.strIKCtrlPair[tag_name]; } return null; } public T GetIKCtrl(string tag_name) where T : AIKCtrl { AIKCtrl ikctrl = this.GetIKCtrl(tag_name); if (ikctrl != null && ikctrl is T) { return ikctrl as T; } return (T)((object)null); } public AIKCtrl GetIKCtrl(FullBodyIKMgr.IKEffectorType effector_type) { return this.GetIKCtrl(FullBodyIKMgr.IKEffectorTypeStrDic[effector_type]); } public T GetIKCtrl(FullBodyIKMgr.IKEffectorType effector_type) where T : AIKCtrl { AIKCtrl ikctrl = this.GetIKCtrl(effector_type); if (ikctrl != null && ikctrl is T) { return ikctrl as T; } return (T)((object)null); } public Transform GetSTFlagObj(string name) { if (this.NameFlagObjpair.ContainsKey(name)) { return this.NameFlagObjpair[name]; } Transform transform = this.STRoot.Find(name); if (!transform) { transform = this.body.GetBone(name); if (!transform) { Debug.LogErrorFormat("{0}は存在しません", new object[] { name }); return null; } } this.NameFlagObjpair.Add(name, transform); return transform; } public static Dictionary GetAllIKBoneDic(Maid chara) { if (chara == null) { return null; } DebugUtility.Assert.IsNotNull(chara.body0, "[body0] it does not end load."); string text = string.Empty; if (chara.body0.IsCrcBody) { text = "Bip01"; } else { text = ((!chara.boMAN) ? "Bip01" : "ManBip"); } Dictionary dictionary = new Dictionary(); dictionary.Add(FullBodyIKMgr.IKBoneType.TopFixed, chara.body0.GetBone(text).parent); dictionary.Add(FullBodyIKMgr.IKBoneType.Root, chara.body0.GetBone(text)); dictionary.Add(FullBodyIKMgr.IKBoneType.Pelvis, chara.body0.GetBone(text + " Pelvis")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine0, chara.body0.GetBone(text + " Spine")); if (chara.body0.IsCrcBody) { dictionary.Add(FullBodyIKMgr.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine0a")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine1")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine3, chara.body0.GetBone(text + " Spine1a")); } else if (!chara.boMAN) { dictionary.Add(FullBodyIKMgr.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine0a")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine1")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine3, chara.body0.GetBone(text + " Spine1a")); } else { dictionary.Add(FullBodyIKMgr.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine1")); dictionary.Add(FullBodyIKMgr.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine2")); } dictionary.Add(FullBodyIKMgr.IKBoneType.Head, chara.body0.GetBone(text + " Head")); dictionary.Add(FullBodyIKMgr.IKBoneType.Neck, chara.body0.GetBone(text + " Neck")); dictionary.Add(FullBodyIKMgr.IKBoneType.UpperArm_R, chara.body0.GetBone(text + " R UpperArm")); dictionary.Add(FullBodyIKMgr.IKBoneType.Forearm_R, chara.body0.GetBone(text + " R Forearm")); dictionary.Add(FullBodyIKMgr.IKBoneType.Hand_R, chara.body0.GetBone(text + " R Hand")); dictionary.Add(FullBodyIKMgr.IKBoneType.UpperArm_L, chara.body0.GetBone(text + " L UpperArm")); dictionary.Add(FullBodyIKMgr.IKBoneType.Forearm_L, chara.body0.GetBone(text + " L Forearm")); dictionary.Add(FullBodyIKMgr.IKBoneType.Hand_L, chara.body0.GetBone(text + " L Hand")); dictionary.Add(FullBodyIKMgr.IKBoneType.Thigh_R, chara.body0.GetBone(text + " R Thigh")); dictionary.Add(FullBodyIKMgr.IKBoneType.Calf_R, chara.body0.GetBone(text + " R Calf")); dictionary.Add(FullBodyIKMgr.IKBoneType.Foot_R, chara.body0.GetBone(text + " R Foot")); dictionary.Add(FullBodyIKMgr.IKBoneType.Thigh_L, chara.body0.GetBone(text + " L Thigh")); dictionary.Add(FullBodyIKMgr.IKBoneType.Calf_L, chara.body0.GetBone(text + " L Calf")); dictionary.Add(FullBodyIKMgr.IKBoneType.Foot_L, chara.body0.GetBone(text + " L Foot")); if (chara.boMAN) { dictionary.Add(FullBodyIKMgr.IKBoneType.ChinkoCenter, chara.body0.GetBone("chinkoCenter")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko1, chara.body0.GetBone("chinko1")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko2, chara.body0.GetBone("chinko2")); if (chara.body0.IsCrcBody) { dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko3, chara.body0.GetBone("chinko3")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko4, chara.body0.GetBone("chinko4")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko5, chara.body0.GetBone("chinko5")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko6, chara.body0.GetBone("chinko6")); dictionary.Add(FullBodyIKMgr.IKBoneType.Chinko7, chara.body0.GetBone("chinko7")); } dictionary.Add(FullBodyIKMgr.IKBoneType.ChinkoNub, chara.body0.GetBone("chinko_nub")); } else { dictionary.Add(FullBodyIKMgr.IKBoneType.Bust_L, chara.body0.GetBone("Mune_L")); dictionary.Add(FullBodyIKMgr.IKBoneType.Bust_L_Sub, chara.body0.GetBone("Mune_L_sub")); dictionary.Add(FullBodyIKMgr.IKBoneType.Bust_R, chara.body0.GetBone("Mune_R")); dictionary.Add(FullBodyIKMgr.IKBoneType.Bust_R_Sub, chara.body0.GetBone("Mune_R_sub")); } dictionary.Add(FullBodyIKMgr.IKBoneType.Mouth, chara.body0.GetBone("_IK_mouth")); return dictionary; } public static Dictionary GetBoneTypeStrDic(Maid chara) { return FullBodyIKMgr.GetBoneTypeStrDic(chara.boMAN); } public static Dictionary GetBoneTypeStrDic(bool isMan) { Dictionary dictionary = new Dictionary(FullBodyIKMgr.IKEffectorTypeStrDic); if (!isMan) { dictionary.Remove(FullBodyIKMgr.IKEffectorType.Penis); } else { dictionary.Remove(FullBodyIKMgr.IKEffectorType.Bust_L); dictionary.Remove(FullBodyIKMgr.IKEffectorType.Bust_R); } return dictionary; } public const float PULL_MIN_VALUE = 0.1f; public static readonly Dictionary IKEffectorTypeStrDic = new Dictionary { { FullBodyIKMgr.IKEffectorType.Body, "体全体" }, { FullBodyIKMgr.IKEffectorType.Hand_R, "右手" }, { FullBodyIKMgr.IKEffectorType.Forearm_R, "右肘" }, { FullBodyIKMgr.IKEffectorType.UpperArm_R, "右肩" }, { FullBodyIKMgr.IKEffectorType.Hand_L, "左手" }, { FullBodyIKMgr.IKEffectorType.Forearm_L, "左肘" }, { FullBodyIKMgr.IKEffectorType.UpperArm_L, "左肩" }, { FullBodyIKMgr.IKEffectorType.Foot_R, "右足" }, { FullBodyIKMgr.IKEffectorType.Calf_R, "右膝" }, { FullBodyIKMgr.IKEffectorType.Thigh_R, "右腿" }, { FullBodyIKMgr.IKEffectorType.Foot_L, "左足" }, { FullBodyIKMgr.IKEffectorType.Calf_L, "左膝" }, { FullBodyIKMgr.IKEffectorType.Thigh_L, "左腿" }, { FullBodyIKMgr.IKEffectorType.Head, "頭" }, { FullBodyIKMgr.IKEffectorType.Penis, "ちんこ" }, { FullBodyIKMgr.IKEffectorType.Bust_L, "左胸" }, { FullBodyIKMgr.IKEffectorType.Bust_R, "右胸" }, { FullBodyIKMgr.IKEffectorType.Mouth, "口" } }; public static readonly Dictionary IKEffectorBonePair = new Dictionary { { FullBodyIKMgr.IKEffectorType.Body, FullBodyIKMgr.IKBoneType.Root }, { FullBodyIKMgr.IKEffectorType.Hand_R, FullBodyIKMgr.IKBoneType.Hand_R }, { FullBodyIKMgr.IKEffectorType.Forearm_R, FullBodyIKMgr.IKBoneType.Forearm_R }, { FullBodyIKMgr.IKEffectorType.UpperArm_R, FullBodyIKMgr.IKBoneType.UpperArm_R }, { FullBodyIKMgr.IKEffectorType.Hand_L, FullBodyIKMgr.IKBoneType.Hand_L }, { FullBodyIKMgr.IKEffectorType.Forearm_L, FullBodyIKMgr.IKBoneType.Forearm_L }, { FullBodyIKMgr.IKEffectorType.UpperArm_L, FullBodyIKMgr.IKBoneType.UpperArm_L }, { FullBodyIKMgr.IKEffectorType.Foot_R, FullBodyIKMgr.IKBoneType.Foot_R }, { FullBodyIKMgr.IKEffectorType.Calf_R, FullBodyIKMgr.IKBoneType.Calf_R }, { FullBodyIKMgr.IKEffectorType.Thigh_R, FullBodyIKMgr.IKBoneType.Thigh_R }, { FullBodyIKMgr.IKEffectorType.Foot_L, FullBodyIKMgr.IKBoneType.Foot_L }, { FullBodyIKMgr.IKEffectorType.Calf_L, FullBodyIKMgr.IKBoneType.Calf_L }, { FullBodyIKMgr.IKEffectorType.Thigh_L, FullBodyIKMgr.IKBoneType.Thigh_L }, { FullBodyIKMgr.IKEffectorType.Head, FullBodyIKMgr.IKBoneType.Head }, { FullBodyIKMgr.IKEffectorType.Penis, FullBodyIKMgr.IKBoneType.ChinkoNub }, { FullBodyIKMgr.IKEffectorType.Bust_R, FullBodyIKMgr.IKBoneType.Bust_R_Sub }, { FullBodyIKMgr.IKEffectorType.Bust_L, FullBodyIKMgr.IKBoneType.Bust_L_Sub }, { FullBodyIKMgr.IKEffectorType.Mouth, FullBodyIKMgr.IKBoneType.Mouth } }; [SerializeField] private TBody Body; [SerializeField] private Transform IKTargetRoot; [SerializeField] private Transform STRoot; [SerializeField] private FullBodyBipedIK IK; private Dictionary IKBoneDic = new Dictionary(); [SerializeField] private IKBodyOffsetCtrl BodyOffsetCtrl; private Transform NippleL; private Transform NippleR; private Transform Mouth; private Dictionary StrIKCtrlPair = new Dictionary(); private Dictionary NameFlagObjpair = new Dictionary(); public bool isIKActive = true; [HideInInspector] public bool isUpdateLate; public PermTempAction onPostSolverUpdate = new PermTempAction(); [SerializeField] private float BlendTime; private List FloorColliderList = new List(); private float FloorColliderY; private List WallColliderList = new List(); private float WallColliderZ; private HashSet PartnerList = new HashSet(); private List ReservedDetachList = new List(); private bool IsPelvisPull; public int ikExecOrder; public enum IKBoneType { None, TopFixed, Root, Spine0, Spine1, Spine2, Spine3, Neck, Head, Clavicle_R, UpperArm_R, Forearm_R, Hand_R, Clavicle_L, UpperArm_L, Forearm_L, Hand_L, Pelvis, ChinkoCenter, Chinko1, Chinko2, Chinko3, Chinko4, Chinko5, Chinko6, Chinko7, ChinkoNub, Thigh_R, Calf_R, Foot_R, Thigh_L, Calf_L, Foot_L, Bust_L, Bust_L_Sub, Bust_R, Bust_R_Sub, Mouth } public enum IKEffectorType { Body, Hand_R, Forearm_R, UpperArm_R, Hand_L, Forearm_L, UpperArm_L, Foot_R, Calf_R, Thigh_R, Foot_L, Calf_L, Thigh_L, Head, Penis, Bust_R, Bust_L, Mouth, Finger_R0, Finger_R1, Finger_R2, Finger_R3, Finger_R4, Finger_L0, Finger_L1, Finger_L2, Finger_L3, Finger_L4 } public class BoneCrossBorder { public BoneCrossBorder(NativePlaneCollider left, NativePlaneCollider right) { this.left = left; this.right = right; } public readonly NativePlaneCollider left; public readonly NativePlaneCollider right; } }