//public override void IkClear(Maid tgt, List<string> listHand, XtMasterSlave.MsLinkConfig mscfg, AIKCtrl.IKAttachType IkType = (AIKCtrl.IKAttachType)(-1))
        public override void IkClear(Maid tgt, List <string> listHand, XtMasterSlave.MsLinkConfig mscfg, int IkType = (-1))
        {
            List <AIKCtrl.IKAttachType> listTypes = new List <AIKCtrl.IKAttachType>
            {
                AIKCtrl.IKAttachType.NewPoint, AIKCtrl.IKAttachType.Rotate
            };

            listHand.ToList().ForEach(h =>
            {
                var ctrl = tgt.body0.fullBodyIK.GetIKCtrl(h);
                listTypes.ForEach(t =>
                {
                    var iks = ctrl.GetIKSettingData(t);

                    if (IkXT.IsIkCtrlO117)
                    {
                        IKAttachParam ikAttachParam = new IKAttachParam(null, tgt);
                        ikAttachParam.attachType    = t;
                        ikAttachParam.execTiming    = AIKCtrl.IKExecTiming.Normal;
                        ikAttachParam.offset        = Vector3.zero;


                        ctrl.SetIKSetting(ikAttachParam);
                        //ctrl.SetIKSetting(t, AIKCtrl.IKExecTiming.Normal, null, string.Empty, null, Vector3.zero);
                        ctrl.Detach();
                        //ctrl.SetIKSetting(t, false, null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
                        //iks.SetIKSetting(null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
                        //ctrl.Detach(t, 0f);
                    }
                    else
                    {
                        //iks.TgtMaid = null;
                        //iks.Tgt_AttachSlot = -1;
                        //iks.Tgt_AttachName = string.Empty;
                        //iks.Target = null;
                        //iks.AxisTgt = null;
                        //iks.TgtOffset = Vector3.zero;
                        //iks.IsTgtAxis
                    }

                    if (iks.attachType != AIKCtrl.IKAttachType.Rotate)
                    {
                        if (IkType >= 0 && IkType != (int)AIKCtrl.IKAttachType.Rotate &&
                            Enum.IsDefined(typeof(AIKCtrl.IKAttachType), IkType))
                        {
                            iks.attachType = ((AIKCtrl.IKAttachType)IkType);
                        }
                        else
                        {
                            if (mscfg != null)
                            {
                                iks.attachType = (GetDefType(mscfg));/*fix v5.0
                                                                      * else
                                                                      * iks.ChangePointType(AIKCtrl.IKAttachType.NewPoint);*/
                            }
                        }
                    }
                });
            });
        }
        public override void IkClear(Maid tgt, XtMasterSlave.MsLinkConfig mscfg)
        {
            List <string> listHand = new List <string> {
                "右手", "左手"
            };

            IkClear(tgt, listHand, mscfg);
        }
 private IKCtrlData.IKAttachType GetDefType(XtMasterSlave.MsLinkConfig mscfg)
 {
     if (mscfg.doIK159NewPointToDef)
     {
         return(IKCtrlData.IKAttachType.NewPoint);
     }
     else
     {
         return(IKCtrlData.IKAttachType.Point);
     }
 }
        //public override void IkClear(Maid tgt, List<string> listHand, XtMasterSlave.MsLinkConfig mscfg, IKCtrlData.IKAttachType IkType = (IKCtrlData.IKAttachType)(-1))
        public override void IkClear(Maid tgt, List <string> listHand, XtMasterSlave.MsLinkConfig mscfg, int IkType = (-1))
        {
            List <IKCtrlData.IKAttachType> listTypes = new List <IKCtrlData.IKAttachType>
            {
                IKCtrlData.IKAttachType.NewPoint, IKCtrlData.IKAttachType.Rotate
            };

            listHand.ToList().ForEach(h =>
            {
                var ctrl = tgt.body0.IKCtrl.GetIKData(h, IKBend);
                listTypes.ForEach(t =>
                {
                    var iks = ctrl.GetTargetData(t);

                    if (IkXT.IsIkCtrlO117)
                    {
                        //ctrl.SetIKSetting(t, false, null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
                        ctrl.SetIKSetting(t, 0, null, -1, string.Empty, null, null, Vector3.zero, false);
                        //iks.SetIKSetting(null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
                        //ctrl.Detach(t, 0f);
                        ctrl.Detach(t);
                    }
                    else
                    {
                        iks.TgtChara       = null;
                        iks.Tgt_AttachSlot = -1;
                        iks.Tgt_AttachName = string.Empty;
                        iks.Target         = null;
                        iks.AxisTgt        = null;
                        iks.TgtOffset      = Vector3.zero;
                        //iks.IsTgtAxis
                    }

                    //if (iks.MyType != IKCtrlData.IKAttachType.Rotate)
                    if (iks.MyType != IKCtrlData.IKAttachType.Rotate)
                    {
                        if (IkType >= 0 && IkType != (int)IKCtrlData.IKAttachType.Rotate &&
                            Enum.IsDefined(typeof(IKCtrlData.IKAttachType), IkType))
                        {
                            iks.ChangePointType((IKCtrlData.IKAttachType)IkType);
                        }
                        else
                        {
                            if (mscfg != null)
                            {
                                iks.ChangePointType(GetDefType(mscfg));/*fix v5.0
                                                                        * else
                                                                        * iks.ChangePointType(IKCtrlData.IKAttachType.NewPoint);*/
                            }
                        }
                    }
                });
            });
        }
        public UserConfig()
        {
            for (int i = 0; i < cfgs_p.Length; i++)
            {
                cfgs_p[i] = new UserConfigPage();
            }

            for (int i = 0; i < cfgs_ms.Length; i++)
            {
                cfgs_ms[i] = new XtMasterSlave.MsLinkConfig();
            }
        }
        //public override void IkClear(Maid tgt, List<string> listHand, XtMasterSlave.MsLinkConfig mscfg, IKMgrData.IKAttachType IkType = (IKMgrData.IKAttachType)(-1))
        public override void IkClear(Maid tgt, List <string> listHand, XtMasterSlave.MsLinkConfig mscfg, int IkType = (-1))
        {
            List <IKMgrData.IKAttachType> listTypes = new List <IKMgrData.IKAttachType>
            {
                IKMgrData.IKAttachType.NewPoint, IKMgrData.IKAttachType.Rotate
            };

            listHand.ToList().ForEach(h =>
            {
                listTypes.ForEach(t =>
                {
                    var iks = tgt.body0.StrIKDataPair[h].GetIKParam(t);

                    iks.TgtMaid        = null;
                    iks.Tgt_AttachSlot = -1;
                    iks.Tgt_AttachName = string.Empty;
                    iks.Target         = null;
                    iks.AxisTgt        = null;
                    iks.TgtOffset      = Vector3.zero;
                    //iks.IsTgtAxis

                    if (iks.MyType != IKMgrData.IKAttachType.Rotate)
                    {
                        if (IkType >= 0 && IkType != (int)IKMgrData.IKAttachType.Rotate &&
                            Enum.IsDefined(typeof(IKMgrData.IKAttachType), IkType))
                        {
                            iks.ChangePointType((IKMgrData.IKAttachType)IkType);
                        }
                        else
                        {
                            if (mscfg != null)
                            {
                                iks.ChangePointType(GetDefType(mscfg));
                            }
                            else
                            {
                                iks.ChangePointType(IKMgrData.IKAttachType.NewPoint);
                            }
                        }
                    }
                });
            });
        }
        public override bool UpdateFinalIK(Maid maid, XtMasterSlave.MsLinks ms, XtMasterSlave.MsLinkConfig mscfg)
        {
            if (!maid || !maid.body0)
            {
                return(false);
            }

            needInit = false;
            if (mscfg.doIK159NewPointToDef)
            {
                IKInit(maid, ms, mscfg);
            }
#if DEBUG
            else
            {
                IKInit4OldPoint(maid);
            }
#endif
            return(true); // 実行できたか
        }
        public override void SetHandIKTarget(XtMasterSlave.MsLinkConfig mscfg, string handName, Maid master, Maid slave, int slot_no, string attach_name, Transform target, Vector3 v3HandLOffset)
        {
            /*if (needInit)
             * {
             *  needInit = false;
             *  if (mscfg.doIK159NewPointToDef)
             *      IKInit(slave, mscfg);
             #if DEBUG
             *  else
             *      IKInit4OldPoint(slave);
             #endif
             * }*/

            //slave.IKCtrl.GetIKData(handName, IKBend).SetIKSetting(GetDefType(mscfg), false, master, slot_no, attach_name, null, target, v3HandLOffset, boAnime, 0f);
            slave.IKCtrl.GetIKData(handName, IKBend).SetIKSetting(GetDefType(mscfg), 0, master, slot_no, attach_name, null, target, v3HandLOffset, boAnime);

            BipedIKCtrlData ikdata = slave.IKCtrl.GetIKData <BipedIKCtrlData>(handName, IKBend);

            ikdata.CorrectType = BipedIKCtrlData.BorderCorrectType.Bone;
        }
 public override void SetHandIKTarget(XtMasterSlave.MsLinkConfig mscfg, string handName, Maid master, Maid slave, int slot_no, string attach_name, Transform target, Vector3 v3HandLOffset)
 {
     slave.IKCtrl.GetIKData(handName).SetIKSetting(GetDefType(mscfg), false, master, slot_no, attach_name, null, target, v3HandLOffset, boAnime, 0f);
 }
        private void IKInit(Maid slave, XtMasterSlave.MsLinks ms, XtMasterSlave.MsLinkConfig mscfg)
        {
            var fik = slave.body0.IKCtrl.GetNonPublicField <RootMotion.FinalIK.FullBodyBipedIK>("m_FullbodyIK");

            RootMotion.FinalIK.FullBodyBipedIK FullbodyIK = fik;
            var solver = FullbodyIK.solver;

            string[] tgtlist = new string[] { "IKTarget", "BendBone", "ChainRootBone" };

            bool animStop = true; //モーション停止中

            if (ms.doMasterSlave && !mscfg.doStackSlave_PosSyncMode)
            {
                animStop = false;
            }
            else
            {
                Animation anim = slave.body0.m_Bones.GetComponent <Animation>();
                animStop = !anim.isPlaying;
            }

            if (!lastAnimeFNs.ContainsKey(slave) || slave.body0.LastAnimeFN != lastAnimeFNs[slave])
            {
                lastAnimeFNs[slave] = slave.body0.LastAnimeFN;
                animStop            = false;
            }

            solver.spineStiffness           = 1f;   //背骨の硬さ
            solver.pullBodyVertical         = 0.5f; //ボディエフェクター位置補正
            solver.pullBodyHorizontal       = 0f;
            solver.spineMapping.twistWeight = 0f;

            foreach (var e in solver.effectors)
            {
                if (solver.leftHandEffector == e || solver.rightHandEffector == e)
                {
                    // 手のIKは本体側に任せる
                    continue;
                }

                bool donotPin = false;

                if (animStop || donotPin)
                {
                    e.positionWeight = 1f;
                    e.rotationWeight = 0f;
                }
                else
                {
                    e.PinToBone(1f, 0f);
                }

                var tgtname = e.target.gameObject.name;

                if (donotPin)
                {
                    continue;
                }
                else
                {
                    if (tgtlist.Contains(tgtname))
                    {
                        // COM3D2標準ターゲット
                        e.target.transform.position = e.bone.position;
                        e.target.transform.rotation = e.bone.rotation;
                    }
                }
            }

            solver.rightShoulderEffector.positionWeight = 0.95f;
            solver.leftShoulderEffector.positionWeight  = 0.95f;

            solver.bodyEffector.rotationWeight = 1f;

            solver.rightThighEffector.positionWeight = 0.95f;
            solver.leftThighEffector.positionWeight  = 0.95f;

            if (mscfg != null && mscfg.doFinalIKShoulderMove)
            {
                solver.rightShoulderEffector.positionWeight = 0f;
                solver.leftShoulderEffector.positionWeight  = 0f;
            }
            if (mscfg != null && mscfg.doFinalIKThighMove)
            {
                solver.bodyEffector.rotationWeight = 0f;

                solver.rightThighEffector.positionWeight = 0f;
                solver.leftThighEffector.positionWeight  = 0f;
            }

            foreach (var m in solver.limbMappings)
            {
                m.weight = 1f;
                m.maintainRotationWeight = 0f;
            }

            if (mscfg != null)
            {
                solver.rightLegMapping.weight = mscfg.fFinalIKLegWeight; //0.5f;
                solver.leftLegMapping.weight  = mscfg.fFinalIKLegWeight; //0.5f;
            }
            solver.rightLegMapping.maintainRotationWeight = 1f;
            solver.leftLegMapping.maintainRotationWeight  = 1f;
        }
        public void ProcParam(Maid master, Maid slave, Maid maid0, XtMasterSlave.MsLinkConfig p_mscfg)
        {
            //v0025 masterの不在を許可 if (!master && !master.body0 && !slave && !slave.body0)
            if (!slave && !slave.body0)
            {
                return;
            }

            //サイズ変更
            if (master && master.body0)
            {
                master.gameObject.transform.localScale = new Vector3(Scale_Master, Scale_Master, Scale_Master);
                if (!master.boMAN)
                {
                    XtMasterSlave.UpdateHitScale(master, Scale_Master, p_mscfg);
                }
                //  XtMasterSlave.UpdateHitScale(master, Scale_Master * p_mscfg.Scale_HitCheckEffect);
            }
            slave.gameObject.transform.localScale = new Vector3(Scale_Slave, Scale_Slave, Scale_Slave);
            if (!slave.boMAN)
            {
                XtMasterSlave.UpdateHitScale(slave, Scale_Slave, p_mscfg);
            }
            //  XtMasterSlave.UpdateHitScale(slave, Scale_Slave * p_mscfg.Scale_HitCheckEffect);

            if (master && master.body0)
            {
                // 男設定 chinkoサイズ・位置など
                if (master.boMAN)
                {
                    XtMasterSlave.SetManVisible(master, !Master_Hide);

                    //master.body0.SetChinkoVisible(Cnk_Visible);
                    XtMasterSlave.SetChinkoVisible(master.body0, Cnk_Visible); //v0030 fix
                    if (Cnk_Visible)
                    {
                        XtMasterSlave.SetChinkoScale(master.body0, Cnk_Scale);
                        XtMasterSlave.SetChinkoPos(master.body0, XtMasterSlave.faTov3(Cnk_OffsetPos));
                    }
                    XtMasterSlave.SetManAlpha(master, manAlpha);
                }
                else
                {
                    XtMasterSlave.SetStateMaskItemsAll(master, Master_Hide);

                    if (slave.boMAN)
                    {
                        //slave.body0.SetChinkoVisible(Cnk_Visible);
                        XtMasterSlave.SetChinkoVisible(master.body0, Cnk_Visible); //v0030 fix
                        if (Cnk_Visible)
                        {
                            XtMasterSlave.SetChinkoScale(slave.body0, Cnk_Scale);
                            XtMasterSlave.SetChinkoPos(slave.body0, XtMasterSlave.faTov3(Cnk_OffsetPos));
                        }
                        XtMasterSlave.SetManAlpha(slave, manAlpha);
                    }
                }
            }
#if DEBUG
            Console.WriteLine(string.Format("+Stgt_boHeadToCam={0} Stgt_boEyeToCam={1}", Stgt_boHeadToCam, Stgt_boEyeToCam));
#endif

            if (!slave.boMAN)
            {
#if DEBUG
                Console.WriteLine(string.Format("-Stgt_boHeadToCam={0} Stgt_boEyeToCam={1}", Stgt_boHeadToCam, Stgt_boEyeToCam));
#endif
                slave.body0.boHeadToCam = Stgt_boHeadToCam;
                slave.body0.boEyeToCam  = Stgt_boEyeToCam;
                Maid tgt = null;
                switch (Stgt_sBoneName)
                {
                case "Bip01 Head":
                    if (maid0 && maid0.body0 && slave != maid0)
                    {
                        tgt = maid0;
                    }
                    break;

                case "_IK_vagina":
                    if (maid0 && maid0.body0 && slave != maid0)
                    {
                        tgt = maid0;
                    }
                    break;

                case "ManBip Head":
                    if (master && master.body0)
                    {
                        tgt = master;
                    }
                    break;

                case "chinko2":
                    if (master && master.body0)
                    {
                        tgt = master;
                    }
                    break;

                default:
                    Stgt_sBoneName = string.Empty;
                    break;
                }

                if (tgt)
                {
                    Transform tgt_tr = BoneLink.BoneLink.SearchObjName(tgt.body0.m_Bones.transform, Stgt_sBoneName, true);
                    slave.EyeToTarget(tgt, GameUty.MillisecondToSecond(0), Stgt_sBoneName);
                }
                else
                {
                    slave.EyeToReset(GameUty.MillisecondToSecond(0));
                }
                slave.body0.boHeadToCam = Stgt_boHeadToCam;
                slave.body0.boEyeToCam  = Stgt_boEyeToCam;
            }
        }