Пример #1
0
        //IK設定の初期化
        public void ikInit(HandleKun posHandle, int currentMaidNo)
        {
            Vector3 prePosition = posHandle.Pos;

            //まず、ハンドルの親をIKターゲットオブジェクトに変更
            posHandle.SetParentBone(goIKTarget[currentMaidNo].transform);
            //IKターゲットオブジェクトの位置を親変更前のハンドルの位置の値に設定
            goIKTarget[currentMaidNo].transform.position = prePosition;


            //Debuginfo.Log(goIKTarget[currentMaidNo].transform.position.ToString());
        }
Пример #2
0
        //IK設定の初期化
        private void ikInit(HandleKun.IKMODE ikmode, HandleKun posHandle, Maid maid, int currentMaidNo)
        {
            if ((int)posHandle.IKmode <= 3)
            {
                IKList[(int)posHandle.IKmode].ikInit(posHandle, currentMaidNo);

                if (!attachIKMaidNo.Contains(currentMaidNo))
                {
                    attachIKMaidList.Add(currentMaidNo, maid);
                    attachIKMaidNo.Add(currentMaidNo);
                }
            }
        }
Пример #3
0
        public void ikTargetClicked(HandleKun posHandle, int currentMaidNo, Transform trTargetIKTemp)
        {
            ikInit(posHandle, currentMaidNo);

            goIKTarget[currentMaidNo].transform.parent = trTargetIKTemp;
            if (trTargetIKTemp.name != "Bip01")
            {
                goIKTarget[currentMaidNo].transform.localPosition = Vector3.zero;
            }


            bIKAttach[currentMaidNo] = true;
        }
Пример #4
0
        public void lateupdateFunc(HandleKun posHandle)
        {
            //メイドさんがいなくなっていればリストから除外
            var deleteList = attachIKMaidNo.FindAll((m) => (attachIKMaidList[m] == null || attachIKMaidList[m].Visible == false));

            deleteList.ForEach(removeAttachMaidList);
            attachIKMaidNo.RemoveAll(deleteList.Contains);


            attachIKMaidNo.ForEach(m =>
            {
                Array.ForEach(IKList, (List) => List.lateupdateFunc(m, attachIKMaidList[m], false, false));
            });
        }
Пример #5
0
        public void inversekinematicHandle(HandleKun posHandle, int currentMaidNo)
        {
            //IK開始時は設定の初期化
            if (!bIKAttach[currentMaidNo])
            {
                ikInit(posHandle, currentMaidNo);
            }
            //ハンドル君から値取得
            goIKTarget[currentMaidNo].transform.position += posHandle.DeltaVector();



            bIKAttach[currentMaidNo] = true;
        }
Пример #6
0
        public void detachIKfromBone(Action <Undo> undoListAdd, Func <bool[], bool[]> setIKButtonActive, bool[] boolList, HandleKun posHandle, Dictionary <string, Transform> trBone, int currentMaidNo, string UndoFuncName)
        {
            //Undoチェック
            if (UndoFuncName != "IKDetach:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo)
            {
                UndoFuncName = "IKDetach:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo;
                //IKでのUndo登録
                undoListAdd(Undo.createUndoIK(this.doUndoFunc, this.checkIKAttach, this.getIKTransform, setIKButtonActive, boolList, GetMaid(currentMaidNo), currentMaidNo, false, IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo), IKList[(int)posHandle.IKmode].getIKPosition(currentMaidNo), (int)posHandle.IKmode));
                Debuginfo.Log(LogLabel + UndoFuncName);
            }

            //Vector3 postPosition = ikHandle.Pos;
            //IKターゲットの位置を初期化
            Quaternion temp = posHandle.Rot;

            //posHandle.transform.parent.parent = trBone["Bip01"];
            //posHandle.transform.parent.localPosition = Vector3.zero;

            if (posHandle.IKmode == HandleKun.IKMODE.LeftLeg)
            {
                posHandle.SetParentBone(trBone["Bip01 L Foot"]);
            }
            else if (posHandle.IKmode == HandleKun.IKMODE.RightLeg)
            {
                posHandle.SetParentBone(trBone["Bip01 R Foot"]);
            }
            else if (posHandle.IKmode == HandleKun.IKMODE.LeftArm)
            {
                posHandle.SetParentBone(trBone["Bip01 L Hand"]);
            }
            else if (posHandle.IKmode == HandleKun.IKMODE.RightArm)
            {
                posHandle.SetParentBone(trBone["Bip01 R Hand"]);
            }
            else
            {
                return;
            }

            IKList[(int)posHandle.IKmode].detachIKfromBone(trBone["Bip01"], currentMaidNo);

            //ikHandle.Pos = postPosition;
            posHandle.transform.localPosition = Vector3.zero;
            posHandle.Scale = 0.2f;

            posHandle.Rot = temp;//Quaternion.Euler(-90, 0, 90);
        }
Пример #7
0
        public void ikTargetClicked(Action <Undo> undoListAdd, Func <bool[], bool[]> setIKButtonActive, bool[] boolList, HandleKun posHandle, int currentMaidNo, string UndoFuncName)
        {
            if (trTargetIKTemp != null)
            {
                Debuginfo.Log(LogLabel + "IKTarget:" + trTargetIKTemp.name.ToString());

                if ((int)posHandle.IKmode <= 3)
                {
                    //Undoチェック
                    if (UndoFuncName != "IK:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo)
                    {
                        UndoFuncName = "IK:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo;
                        //IKでのUndo登録
                        undoListAdd(Undo.createUndoIK(this.doUndoFunc, this.checkIKAttach, this.getIKTransform, setIKButtonActive, boolList, GetMaid(currentMaidNo), currentMaidNo, true, IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo), IKList[(int)posHandle.IKmode].getIKPosition(currentMaidNo), (int)posHandle.IKmode));
                        //Debuginfo.Log(LogLabel + "Undo::" + UndoFuncName);
                    }

                    IKList[(int)posHandle.IKmode].ikTargetClicked(posHandle, currentMaidNo, trTargetIKTemp);
                }


                if (trTargetIKTemp.name != "Bip01")
                {
                    posHandle.IKTargetAttachedColor(true);
                }
                else
                {
                    posHandle.IKTargetAttachedColor(false);
                }

                bIKTargetGet = false;

                trTargetIKTemp = null;
            }
        }
Пример #8
0
        //ハンドル君から値を受け取る処理
        public string  inversekinematicHandle(Action <Undo> undoListAdd, Func <int, int, Quaternion[]> getBones, Action <int, int, Quaternion[]> setBones, Quaternion[] bones, Func <bool[], bool[]> setIKButtonActive, Func <bool[]> getIKButtonActive, HandleKun posHandle, Maid maid, int currentMaidNo, string UndoFuncName)
        {
            if ((int)posHandle.IKmode <= 3 && posHandle.controllDragged())
            {
                //Undoチェック
                if (UndoFuncName != "IK:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo)
                {
                    UndoFuncName = "IK:" + (int)posHandle.IKmode + ":" + IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo).ToString() + ":" + currentMaidNo;

                    bool[] boolList = getIKButtonActive();

                    //IKでのUndo登録
                    if (IKList[(int)posHandle.IKmode].checkIKAttach(currentMaidNo))
                    {
                        undoListAdd(Undo.createUndoIK(this.doUndoFunc, this.checkIKAttach, this.getIKTransform, setIKButtonActive, boolList, maid, currentMaidNo,
                                                      true, IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo), IKList[(int)posHandle.IKmode].getIKPosition(currentMaidNo), (int)posHandle.IKmode));
                    }
                    else
                    {
                        boolList[(int)posHandle.IKmode] = false;
                        undoListAdd(Undo.createUndoIKFirst(this.doUndoFunc, this.checkIKAttach, this.getIKTransform, getBones, setBones, bones, setIKButtonActive, boolList, maid, currentMaidNo,
                                                           false, IKList[(int)posHandle.IKmode].getParentTransform(currentMaidNo), IKList[(int)posHandle.IKmode].getIKPosition(currentMaidNo), (int)posHandle.IKmode));
                    }
                    //Debuginfo.Log(LogLabel + "Undo::" + UndoFuncName );
                }

                IKList[(int)posHandle.IKmode].inversekinematicHandle(posHandle, currentMaidNo);

                if (!attachIKMaidNo.Contains(currentMaidNo))
                {
                    attachIKMaidList.Add(currentMaidNo, maid);
                    attachIKMaidNo.Add(currentMaidNo);
                }
            }

            return(UndoFuncName);
        }
Пример #9
0
        public void updateFunc(HandleKun posHandle, Dictionary <string, Transform> trBone)
        {
            //カメラ操作の右ドラッグと区別するため
            if (Input.GetMouseButtonDown(1))
            {
                //Debuginfo.Log("右クリック開始");
                bIKTargetGet = true;
            }
            else if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0 || Input.mouseScrollDelta != Vector3.zero)
            {
                //IKハンドル君表示中にカメラ操作があったらラベルも付随して移動させる
                posHandle.IKBoneLabelPos = 1.5f * (Camera.main.WorldToScreenPoint(posHandle.IKTargetPos) - new Vector3(Screen.width * 0.5f, Screen.height * 0.5f - 30f, Camera.main.WorldToScreenPoint(posHandle.IKTargetPos).z));

                bIKTargetGet = false;
            }
            else if (Input.GetMouseButtonUp(1) && bIKTargetGet == true)
            {
                //Debuginfo.Log("右クリック終了");
                //ここで画面内オブジェクトの検知を済ませておく
                //今表示されているメイドさんの_IK_ボーン情報をコレクションに収納
                //settrTargetIKBones();

                //Debuginfo.Log("mouse:" + Input.mousePosition.ToString());
                Vector3 mousePos = Input.mousePosition;

                trTargetIKTemp = null;

                float clickCheckOffset = clickCheckOffsetInit;


                float magnitude0 = (Camera.main.WorldToScreenPoint(trBone["Bip01 Neck"].position) - mousePos).magnitude;
                if (magnitude0 < clickCheckOffset)
                {
                    clickCheckOffset = magnitude0;
                    trTargetIKTemp   = trBone["Bip01 Neck"];
                }

                List <int> RemoveNo = new List <int>();

                foreach (var trArray in trTargetIKBones)
                {
                    if (trArray.Value[0] == null)
                    {
                        RemoveNo.Add(trArray.Key);
                        continue;
                    }

                    Array.ForEach(trArray.Value, tr =>
                    {
                        float magnitude = (Camera.main.WorldToScreenPoint(tr.position) - mousePos).magnitude;
                        if (magnitude < clickCheckOffset)
                        {
                            clickCheckOffset = magnitude;
                            trTargetIKTemp   = tr;
                            //Debuginfo.Log(trIK.name + ":" + Camera.main.WorldToScreenPoint(trIK.position).ToString());
                        }
                    });
                }


                RemoveNo.ForEach(m => trTargetIKBones.Remove(m));


                if (trTargetIKTemp != null)
                {
                    //Debuginfo.Log("右クリック何かあった");

                    posHandle.IKTargetPos = trTargetIKTemp.position;

                    if (trTargetIKTemp.name == "Bip01 Neck")
                    {
                        trTargetIKTemp = trBone["Bip01"];
                    }

                    //なぜかNGUIの位置指定と実際のピクセルで1.5倍の違いがあるので1.5倍する
                    posHandle.IKBoneLabelPos = 1.5f * (Camera.main.WorldToScreenPoint(posHandle.IKTargetPos) - new Vector3(Screen.width * 0.5f, Screen.height * 0.5f - 30f, Camera.main.WorldToScreenPoint(posHandle.IKTargetPos).z));

                    posHandle.IKTargetLabelString = sIKBoneName[trTargetIKTemp.name];

                    posHandle.IKTargetVisible = true;
                }
            }
        }