private void Awake()
 {
     MyLog.LogMessage("Awake");
     SongMotionUtill.Deserialize();
     Harmony.CreateAndPatchAll(typeof(CharacterMgrPatch));
 }
예제 #2
0
        private void DrawVMDAnimationArea()
        {
            //EnsureResourceLoaded();
            //GUI.skin.GetStyle("Button");
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            #region Favorites

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Favorites", gui[100, 25]))
            {
                isFavorites = !isFavorites;
            }
            if (GUILayout.Button("add", gui[50f, 25f]))
            {
                SongMotionUtill.Set(
                    FavoritesName
                    , oggFilename
                    //, VMDAnimationMgr.Instance.controllers.Where(x=> CharacterMgrPatch.maids.Contains(x.maid) ).Select(x => x.lastLoadedVMD).ToArray()
                    , VMDAnimationMgr.Instance.maidcontrollers.Values.Select(x => new SongMotionUtill.motionAndTime(x.lastLoadedVMD, x.timeShiftNow)).ToArray()
                    );
                // MyLog.LogMessage("add", VMDAnimationMgr.Instance.controllers.Count, CharacterMgrPatch.maids.Count, VMDAnimationMgr.Instance.controllers.Where(x => CharacterMgrPatch.maids.Contains(x.maid)).Count() );
                MyLog.LogMessage("add", VMDAnimationMgr.Instance.maidcontrollers.Count, CharacterMgrPatch.maids.Count);
            }
            FavoritesName = GUILayout.TextField(FavoritesName, gui[350, 25]);
            if (GUILayout.Button("reload", gui[50, 25]))
            {
                SongMotionUtill.Deserialize();
            }
            if (GUILayout.Button("chack", gui[50, 25]))
            {
                MyLog.LogMessage("chack", VMDAnimationMgr.Instance.maidcontrollers.Count);
                MyLog.LogMessage("chack", CharacterMgrPatch.maids.Count);
            }
            GUILayout.EndHorizontal();


            if (isFavorites)
            {
                foreach (var item in SongMotionUtill.GetList())
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button(item.Key, gui[550f, 25f]))
                    {
                        FavoritesName = item.Key;
                        //VMDAnimationMgr.Instance.ControllerInstallAll();
                        VMDAnimationMgr.Instance.ClearAll();
                        if (item.Value.Motions2.Count > 0)
                        {
                            //var v = VMDAnimationMgr.Instance.maidcontrollers.ToList();
                            //var v=VMDAnimationMgr.Instance.controllers.Where(x => CharacterMgrPatch.maids.Contains(x.maid)).ToList();
                            var v = CharacterMgrPatch.maids;
                            for (int i = 0; i < item.Value.Motions2.Count && i < v.Count; i++)
                            {
                                vMDAnimationControllerSub = VMDAnimationController.Install(v[i]);
                                vMDAnimationControllerSub.VMDAnimEnabled = true;
                                vMDAnimationControllerSub.timeShiftNow   = item.Value.Motions2[i].time;
                                vMDAnimationControllerSub.LoadVMDAnimation(item.Value.Motions2[i].motion);
                            }
                            //vMDAnimationController = VMDAnimationController.Install(focusChara);
                            lastFilename = vMDAnimationController.lastLoadedVMD;
                        }
                        oggFilename = item.Value.Song;
                        AudioManager.Load(oggFilename, vMDAnimationController.Loop);

                        //for (int i = 0; i < item.Value.Motions.Count && i < v.Count; i++)
                        //{
                        //    vMDAnimationController.Play();
                        //}
                        VMDAnimationMgr.Instance.PlayAll();
                        AudioManager.Play();

                        isFavorites = false;
                        this.gameObject.SetActive(false);
                    }
                    if (GUILayout.Button("Del", gui[50f, 25f]))
                    {
                        SongMotionUtill.Del(item.Key);
                    }
                    GUILayout.EndHorizontal();
                }
            }

            #endregion

            #region OGG ===========================================

            GUILayout.BeginHorizontal( );

            GUILayout.Label("OGG", gui[50, 25]);

            if (GUILayout.Button("load", gui[50, 25]))
            {
                if (vMDAnimationController != null)
                {
                    AudioManager.Load(oggFilename, vMDAnimationController.Loop);
                }
                else
                {
                    AudioManager.Load(oggFilename, true);
                }
            }
            if (AudioManager.isPlay())
            {
                if (GUILayout.Button("Pause", (GUILayoutOption[])new GUILayoutOption[2] {
                    GUILayout.Width(50f), GUILayout.Height(25f)
                }))
                {
                    AudioManager.Pause();
                }
            }
            else
            {
                if (GUILayout.Button("play", (GUILayoutOption[])new GUILayoutOption[2] {
                    GUILayout.Width(50f), GUILayout.Height(25f)
                }))
                {
                    AudioManager.Play();
                }
            }
            if (oggFilename == null)
            {
                oggFilename = string.Empty;
            }
            oggFilename = GUILayout.TextField(oggFilename, gui[350, 25]);
            if (GUILayout.Button("...", gui[30, 25]))
            {
                dialog.Filter = "OGG files (*.ogg)|*.ogg|WAV files (*.wav)|*.wav";

                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // 음악은 상대경로가 안먹힌다?
                    oggFilename = MyUtill.EvaluateRelativePath(Environment.CurrentDirectory, dialog.FileName);
                    if (vMDAnimationController != null)
                    {
                        AudioManager.Load(oggFilename, vMDAnimationController.Loop);
                    }
                    else
                    {
                        AudioManager.Load(oggFilename, true);
                    }
                    AudioManager.Play();
                }
            }
            GUILayout.EndHorizontal();

            #endregion =================================



            if (focusChara == null)
            {
                GUILayout.BeginHorizontal( );
                GUILayout.Label("Character not selected.", (GUILayoutOption[])new GUILayoutOption[1]
                {
                    GUILayout.Width(200f)
                });
                //GUILayout.Space(50f);
                if (GUILayout.Button("Close", gui[50f, 25f]))
                {
                    this.gameObject.SetActive(false);
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                vMDAnimationController = VMDAnimationController.Install(focusChara);
                if (!(vMDAnimationController == null) && focusChara != null)
                {
                    GUILayout.BeginVertical();
                    if (vMDAnimationController != lastController)
                    {
                        lastFilename   = vMDAnimationController.lastLoadedVMD;
                        lastController = vMDAnimationController;
                        timeShiftNow   = vMDAnimationController.timeShiftNow;
                    }
                    if (lastFilename == null)
                    {
                        lastFilename = "";
                    }

                    #region Maid Select

                    GUILayout.BeginHorizontal( );

                    if (GUILayout.Button("<", gui[20f, 25f]))
                    {
                        focusChara = FindPrevNextMaid(false);
                    }
                    if (GUILayout.Button(">", gui[20f, 25f]))
                    {
                        focusChara = FindPrevNextMaid(true);
                    }
                    if (GUILayout.Button(vMDAnimationController.VMDAnimEnabled ? "On" : "Off", gui[50f, 25f]))
                    {
                        vMDAnimationController.VMDAnimEnabled = !vMDAnimationController.VMDAnimEnabled;
                        //isFavorites = vMDAnimationController.VMDAnimEnabled;
                    }
                    GUILayout.Label((focusChara.status.fullNameJpStyle), (GUILayoutOption[])new GUILayoutOption[1]
                    {
                        GUILayout.Width(200f)
                    });

                    /*
                     * if (vMDAnimationController.VMDAnimEnabled)
                     * {
                     *  GUILayout.Space(50f);
                     *  if (vMDAnimationController.lastLoadedVMD != null && File.Exists(vMDAnimationController.lastLoadedVMD))
                     *  {
                     *      GUILayout.Label(Path.GetFileNameWithoutExtension(vMDAnimationController.lastLoadedVMD),  );
                     *  }
                     * }
                     */
                    GUILayout.Space(50f);
                    if (GUILayout.Button("Close", gui[50f, 25f]))
                    {
                        this.gameObject.SetActive(false);
                    }
                    //GUILayout.Space(50f);

                    GUILayout.EndHorizontal();

                    #endregion

                    if (vMDAnimationController.VMDAnimEnabled)
                    {
                        #region VMD =====================================================================

                        GUILayout.BeginHorizontal( );
                        GUILayout.Label("VMD", (GUILayoutOption[])new GUILayoutOption[2] {
                            GUILayout.Width(50f), GUILayout.Height(25f)
                        });
                        if (GUILayout.Button("Load", (GUILayoutOption[])new GUILayoutOption[2] {
                            GUILayout.Width(50f), GUILayout.Height(25f)
                        }))
                        {
                            vMDAnimationController.LoadVMDAnimation(lastFilename, true);
                        }
                        if (GUILayout.Button("Reload", gui[50f, 25f]))
                        {
                            vMDAnimationController.ReloadVMDAnimation();
                            lastFilename = vMDAnimationController.lastLoadedVMD;
                        }
                        if (lastFilename == null)
                        {
                            lastFilename = string.Empty;
                        }
                        lastFilename = GUILayout.TextField(lastFilename, gui[350f, 25f]);
                        if (GUILayout.Button("...", gui[30f, 25f]))
                        {
                            //System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
                            dialog.Filter = "VMD files (*.vmd)|*.vmd";

                            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                lastFilename = MyUtill.EvaluateRelativePath(Environment.CurrentDirectory, dialog.FileName);
                                vMDAnimationController.LoadVMDAnimation(lastFilename);
                                vMDAnimationController.Play();
                            }
                        }
                        if (GUILayout.Button("All apply", gui[60, 25f]))
                        {
                            VMDAnimationMgr.Instance.ClearAll();
                            foreach (var item in  CharacterMgrPatch.maids)
                            {
                                vMDAnimationControllerSub = VMDAnimationController.Install(item);
                                vMDAnimationControllerSub.VMDAnimEnabled = true;
                                vMDAnimationControllerSub.LoadVMDAnimation(lastFilename);
                            }
                            //vMDAnimationController = VMDAnimationController.Install(focusChara);
                            VMDAnimationMgr.Instance.PlayAll();
                        }
                        GUILayout.EndHorizontal();

                        #endregion

                        #region play

                        GUILayout.BeginHorizontal( );
                        GUILayout.Label("(Player)", gui[50f, 25f]);
                        if (GUILayout.Button("Play", gui[50f, 25f]))
                        {
                            vMDAnimationController.Play();
                            AudioManager.Play(vMDAnimationController.Loop);
                            this.gameObject.SetActive(false);
                        }
                        if (GUILayout.Button("Pause", gui[50f, 25f]))
                        {
                            vMDAnimationController.Pause();
                            AudioManager.Pause(vMDAnimationController.Loop);
                        }
                        if (GUILayout.Button("Stop", gui[50f, 25f]))
                        {
                            vMDAnimationController.Stop();
                            AudioManager.Stop();
                        }
                        GUILayout.Space(30f);
                        GUILayout.Label("(All)", gui[GUILayoutOptionUtill.Type.Width, 50f]);
                        if (GUILayout.Button("Play", gui[50f, 25f]))
                        {
                            VMDAnimationMgr.Instance.PlayAll();
                            AudioManager.Play();
                            this.gameObject.SetActive(false);
                        }
                        if (GUILayout.Button("Pause", gui[50f, 25f]))
                        {
                            VMDAnimationMgr.Instance.PauseAll();
                            AudioManager.Pause(vMDAnimationController.Loop);
                        }
                        if (GUILayout.Button("Stop", gui[50f, 25f]))
                        {
                            VMDAnimationMgr.Instance.StopAll();
                            AudioManager.Stop();
                        }
                        GUILayout.EndHorizontal();

                        #endregion

                        #region option

                        #region time shift

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Sync Anm to BGM", gui[GUILayoutOptionUtill.Type.Width, 120f]);
                        if (GUILayout.Button(vMDAnimationController.SyncToBGM ? "On" : "Off", gui[GUILayoutOptionUtill.Type.Width, 40f]))
                        {
                            vMDAnimationController.SyncToBGM = !vMDAnimationController.SyncToBGM;
                        }

                        /*GUILayout.Space(30f);
                         *                      GUILayout.Label("Sync BGM to Anm", (GUILayoutOption[])new GUILayoutOption[1]
                         *                      {
                         *                                      GUILayout.Width(120f)
                         *                      });
                         *                      if (GUILayout.Button(vMDAnimationController.SyncToAnim ? "On" : "Off", (GUILayoutOption[])new GUILayoutOption[1]
                         *                      {
                         *                                      GUILayout.Width(40f)
                         *                      }))
                         *                      {
                         *                              vMDAnimationController.SyncToAnim = !vMDAnimationController.SyncToAnim;
                         *                      }*/

                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();

                        //                    GUILayout.Label("time shift");

                        //                  timeShiftNow_s = GUILayout.TextField(timeShiftNow.ToString(), gui[GUILayoutOptionUtill.Type.Width, 40]);

                        //                      GUILayout.Label("min");

                        //timeShiftNow= GUILayout.HorizontalSlider(timeShiftNow, timeShiftMin, timeShiftMax, gui[GUILayoutOptionUtill.Type.Width, 80]);
                        vMDAnimationController.timeShiftNow = AddSliderWithTextFixedScale("time shift", vMDAnimationController.timeShiftNow, timeShiftMin, timeShiftMax);
                        //sizeMultiplier = EditorGUILayout.FloatField("Increase scale by:", sizeMultiplier);


                        if (!float.TryParse(GUILayout.TextField(timeShiftMin.ToString("0.00"), gui[GUILayoutOptionUtill.Type.Width, 60]), out timeShiftMin))
                        {
                            timeShiftMin = -60;
                        }

                        if (!float.TryParse(GUILayout.TextField(timeShiftMax.ToString("0.00"), gui[GUILayoutOptionUtill.Type.Width, 60]), out timeShiftMax))
                        {
                            timeShiftMax = 60;
                        }

//                        GUILayout.Label("max");

                        //if (GUI.changed)
                        //{
                        //    if (!float.TryParse(timeShiftNow_s, out timeShiftNow)) timeShiftNow = 0;
                        //    if (!float.TryParse(timeShiftMin_s, out timeShiftMin)) timeShiftMin = -60;
                        //    if (!float.TryParse(timeShiftMax_s, out timeShiftMax)) timeShiftMax =  60;
                        //
                        //    vMDAnimationController.timeShiftNow = timeShiftNow;
                        //
                        //}
                        if (GUILayout.Button("All apply", gui[60, 25f]))
                        {
                            foreach (var item in CharacterMgrPatch.maids)
                            {
                                vMDAnimationControllerSub = VMDAnimationController.Install(item);
                                vMDAnimationControllerSub.timeShiftNow = vMDAnimationController.timeShiftNow;
                            }
                        }
                        GUILayout.FlexibleSpace();
                        //vMDAnimationController = VMDAnimationController.Install(focusChara);

                        GUILayout.EndHorizontal();

                        #endregion



                        GUILayout.BeginHorizontal( );
                        vMDAnimationController.speed = AddSliderWithText("vmdAnimSpeed", "Speed", vMDAnimationController.speed, 5f);
                        GUILayout.EndHorizontal();


                        GUILayout.BeginHorizontal( );
                        GUILayout.Label("Loop", gui[GUILayoutOptionUtill.Type.Width, 40f]);
                        if (GUILayout.Button(vMDAnimationController.Loop ? "On" : "Off", gui[GUILayoutOptionUtill.Type.Width, 40f]))
                        {
                            vMDAnimationController.Loop = !vMDAnimationController.Loop;
                            AudioManager.SetLoop(vMDAnimationController.Loop);
                        }
                        GUILayout.Space(20f);
                        GUILayout.Label("Face", gui[GUILayoutOptionUtill.Type.Width, 40f]);
                        if (GUILayout.Button(vMDAnimationController.faceAnimeEnabled ? "On" : "Off", gui[GUILayoutOptionUtill.Type.Width, 40f]))
                        {
                            vMDAnimationController.faceAnimeEnabled = !vMDAnimationController.faceAnimeEnabled;
                        }
                        GUILayout.Space(10f);
                        GUILayout.Label("IK (foot)", gui[GUILayoutOptionUtill.Type.Width, 60f]);
                        if (GUILayout.Button(vMDAnimationController.enableIK ? "On" : "Off", gui[GUILayoutOptionUtill.Type.Width, 40f]))
                        {
                            vMDAnimationController.enableIK = !vMDAnimationController.enableIK;
                        }
                        GUILayout.Space(10f);
                        if (vMDAnimationController.enableIK)
                        {
                            GUILayout.Label("IK (toe)", gui[GUILayoutOptionUtill.Type.Width, 60f]);
                            if (GUILayout.Button(vMDAnimationController.IKWeight.disableToeIK ? "Off" : "On", gui[GUILayoutOptionUtill.Type.Width, 40f]))
                            {
                                vMDAnimationController.IKWeight.disableToeIK = !vMDAnimationController.IKWeight.disableToeIK;
                            }
                        }

                        /*GUILayout.Space(10f);
                         *                      GUILayout.Label("IK(Head)", (GUILayoutOption[])new GUILayoutOption[1]
                         *                      {
                         *                                      GUILayout.Width(60f)
                         *                      });
                         *                      if (GUILayout.Button(vMDAnimationController.enableHeadRotate ? "On" : "Off", (GUILayoutOption[])new GUILayoutOption[1]
                         *                      {
                         *                                      GUILayout.Width(40f)
                         *                      }))
                         *                      {
                         *                              vMDAnimationController.enableHeadRotate = !vMDAnimationController.enableHeadRotate;
                         *                      }*/
                        GUILayout.EndHorizontal();



                        if (vMDAnimationController.enableIK)
                        {
                            GUILayout.BeginHorizontal( );
                            vMDAnimationController.IKWeight.footIKPosWeight = AddSliderWithText("vmdIKFootPosWeight", "IK Weight(pos)", vMDAnimationController.IKWeight.footIKPosWeight, 1f);
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal( );
                            vMDAnimationController.IKWeight.footIKRotWeight = AddSliderWithText("vmdIKFootRotWeight", "IK Weight(rot)", vMDAnimationController.IKWeight.footIKRotWeight, 1f);
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.BeginHorizontal( );
                        GUILayout.Label("Config: (needs Reload): ", gui[GUILayoutOptionUtill.Type.Width, 150f]);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        float num = AddSliderWithText("vmdCenterYPos", "(PMD)Center pos(y)", vMDAnimationController.centerBasePos.y, 15f);
                        if (num != vMDAnimationController.centerBasePos.y)
                        {
                            vMDAnimationController.centerBasePos.y = num;
                            //vMDAnimationController.centerBasePos = new Vector3(0f, num, 0f);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        float num2 = AddSliderWithTextFixedScale("(PMD)Hip pos(y)", vMDAnimationController.hipPositionAdjust.y, 1f, 6f);
                        if (num2 != vMDAnimationController.hipPositionAdjust.y)
                        {
                            vMDAnimationController.hipPositionAdjust.y = num2;
                            //vMDAnimationController.hipPositionAdjust = new Vector3(0f, num2, 0f);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        float num3 = AddSliderWithText("vmdModelScale", "Model Scale", vMDAnimationController.quickAdjust.ScaleModel, 2f);
                        if (num3 != vMDAnimationController.quickAdjust.ScaleModel)
                        {
                            vMDAnimationController.quickAdjust.ScaleModel = num3;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        vMDAnimationController.quickAdjust.Shoulder = AddSliderWithTextFixedScale("Shoulder Tilt", vMDAnimationController.quickAdjust.Shoulder, -10f, 40f);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        vMDAnimationController.quickAdjust.ArmUp = AddSliderWithTextFixedScale("Upper Arm Tilt", vMDAnimationController.quickAdjust.ArmUp, -10f, 40f);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal( );
                        vMDAnimationController.quickAdjust.ArmLow = AddSliderWithTextFixedScale("Lower Arm Tilt", vMDAnimationController.quickAdjust.ArmLow, -10f, 40f);
                        GUILayout.EndHorizontal();
                        //GUILayout.Label("Other Config", (GUILayoutOption[])new GUILayoutOption[1]
                        //{
                        //	GUILayout.Width(150f)
                        //});
                        //GUILayout.BeginHorizontal( );
                        //vMDAnimationController.BgmVolume = AddSliderWithTextFixedScale("BGM volume", vMDAnimationController.BgmVolume, 0f, 1f);
                        //GUILayout.EndHorizontal();

                        #endregion
                    }

                    GUILayout.EndVertical();
                }
            }

            GUILayout.EndScrollView();
        }