コード例 #1
0
        private void Awake()
        {
            player      = GetComponent <MyMMLPlayer>();
            inputField1 = transform.Find("Panel/InputField 1").GetComponent <InputField>();
            inputField2 = transform.Find("Panel/InputField 2").GetComponent <InputField>();
            inputField3 = transform.Find("Panel/InputField 3").GetComponent <InputField>();
            transform.Find("Panel/Toggle Port 0").GetComponent <Toggle>().onValueChanged.AddListener(value => { if (value)
                                                                                                                {
                                                                                                                    portNumber = 0;
                                                                                                                }
                                                                                                     });
            transform.Find("Panel/Toggle Port 1").GetComponent <Toggle>().onValueChanged.AddListener(value => { if (value)
                                                                                                                {
                                                                                                                    portNumber = 1;
                                                                                                                }
                                                                                                     });
            transform.Find("Panel/Toggle Port 2").GetComponent <Toggle>().onValueChanged.AddListener(value => { if (value)
                                                                                                                {
                                                                                                                    portNumber = 2;
                                                                                                                }
                                                                                                     });
            transform.Find("Panel/Toggle Port 3").GetComponent <Toggle>().onValueChanged.AddListener(value => { if (value)
                                                                                                                {
                                                                                                                    portNumber = 3;
                                                                                                                }
                                                                                                     });
            transform.Find("Panel/Toggle Loop").GetComponent <Toggle>().onValueChanged.AddListener(value => loop = value);
            transform.Find("Panel/Slider Volume").GetComponent <Slider>().onValueChanged.AddListener(value =>
            {
                player.Volume = value;
            });
            transform.Find("Panel/Button Play").GetComponent <Button>().onClick.AddListener(() =>
            {
                player.Stop();
                lines.Clear();
                clip      = player.Play(portNumber, 0, inputField1.text, inputField2.text, inputField3.text);
                clip.Loop = loop;
            });
            transform.Find("Panel/Button Stop").GetComponent <Button>().onClick.AddListener(() =>
            {
                player.Stop();
                clip = null;
            });
            transform.Find("Panel/Button Sample1").GetComponent <Button>().onClick.AddListener(() =>
            {
                inputField1.text = "c2e2g2c1:e1: g1d2f2a2d1: r4: r2f2.a2r2";
                inputField2.text = "";
                inputField3.text = "/* chord test!*/";
            });
            transform.Find("Panel/Button Sample2").GetComponent <Button>().onClick.AddListener(() =>
            {
                inputField1.text = "/* Froschgesang */!t88[l8b-]fgab|agfr|ab<cd|c>bar|frfrfrfr|l16ffggaabb|lagfr";
                inputField2.text = "[l8b-]r2|r2|fgab|agfr|ab<cd|c>bar|frfrfrfr|l16ffggaabb|lagfr";
                inputField3.text = "[l8b-]r2|r2|r2|r2|fgab|agfr|ab<cd|c>bar|frfrfrfr|l16ffggaabb|lagfr";
            });
            transform.Find("Panel/Button Sample3").GetComponent <Button>().onClick.AddListener(() =>
            {
                //inputField1.text = "@<128,0>v127l8 { n42:n36 n42:n36 n42:n38 n42:n36 n42:n36 n42:n36 n42:n38 n42:n36 }4 n49,1";
                inputField1.text = "@<128,0>v127l8 { n42:n36 n42 n42:n38 n42 n42:n36 n42:n36 n42:n38 n42 }4 n49,1";
                inputField2.text = "/*this is for GM tone set*/";
                inputField3.text = "/* please import any GM compatible sf2 file and set to PresetToneTemplate.mml.txt*/";
            });
            transform.Find("Panel/Button Clear").GetComponent <Button>().onClick.AddListener(() =>
            {
                inputField1.text = "";
                inputField2.text = "";
                inputField3.text = "";
            });
            monitor = transform.Find("Panel/Text Monitor").GetComponentInChildren <Text>();
            result  = transform.Find("Panel/Text Result").GetComponentInChildren <Text>();

            player.PlayingEvent += playingEvent;
        }
コード例 #2
0
        private void Awake()
        {
            player               = GameObject.FindObjectOfType <MyMMLPlayer>();
            sampleTools          = GameObject.FindObjectOfType <SampleTools>();
            mmlBox               = sampleTools.GetComponent <MyMMLBox>();
            player.AppDataEvent += appDataEventFunc;
            player.PlayingEvent += playingEventFunc;
#if false
            {
                string    mml  = "$@(h_close5) = @pm8[4 7 op1[0 0 15 0 7 0 0 0 0 31 0 0 0 0] op2[0 0 0 0 7 0 0 1 0 21 18 5 15 13] op3[0 0 8 0 3 0 0 0 0 31 0 0 0 14] op4[0 0 15 0 3 0 1 1 5 31 17 15 13 9] lfo[0 127 0 0 31 0 0 0 0] ]\nt0=@(h_close5)a32c32";
                MyMMLClip clip = new MyMMLClip("Click", mml);
                clip.GenerateAudioClip = true;
                mmlBox.Add(clip);
            }
#endif
            invalid          = true;
            playing          = false;
            ToneEditorCanvas = transform.parent.Find("ToneEditorCanvas").gameObject;
            {
                var button = transform.Find("Panel/ToneEditorButton").GetComponent <Button>();
                button.onClick.AddListener(() =>
                {
                    mmlBox.Play("Click");
                    sampleTools.MoveCameraTo(ToneEditorCanvas.transform.localPosition);
                    ToneEditorCanvas.GetComponent <CanvasGroup>().interactable = true;
                    this.GetComponent <CanvasGroup>().interactable             = false;
                });
            }
            ToneEditorCT8Canvas = transform.parent.Find("ToneEditorCT8Canvas").gameObject;
            {
                var button = transform.Find("Panel/ToneEditorCT8Button").GetComponent <Button>();
                button.onClick.AddListener(() =>
                {
                    mmlBox.Play("Click");
                    sampleTools.MoveCameraTo(ToneEditorCT8Canvas.transform.localPosition);
                    ToneEditorCT8Canvas.GetComponent <CanvasGroup>().interactable = true;
                    this.GetComponent <CanvasGroup>().interactable = false;
                });
            }
            {
                var button = transform.Find("Panel/PlayButton").GetComponent <Button>();
                cursolPosText   = transform.Find("Panel/CursolPosText").GetComponent <Text>();
                mmlField        = transform.Find("Panel/MMLField").GetComponent <InputField>();
                consoleText     = transform.Find("Panel/ConsolePanel").GetComponentInChildren <Text>();
                instructionText = transform.Find("Panel/InstructionPanel").GetComponentInChildren <Text>();
                playButtonText  = button.GetComponentInChildren <Text>();
#if UNITY_5_3_OR_NEWER
                mmlField.onValueChanged.AddListener((str) =>
#else
                mmlField.onValueChange.AddListener((str) =>
#endif
                {
                    invalid = true;
                    if (player.Playing)
                    {
                        player.Stop();
                        playButtonText.text = "Play";
                        consoleText.text    = "";
                        playing             = false;
                    }
                    else
                    {
                        playButtonText.text = "Play";
                    }
                });
                button.onClick.AddListener(() =>
                {
                    if (invalid)
                    {
                        if (player.Playing && (player.Clip == mmlClip))
                        {
                            player.Stop();
                            playButtonText.text = "Play";
                            consoleText.text    = "";
                            playing             = false;
                        }
                        else
                        {
                            mmlClip.TextB = mmlField.text;
                            player.Play(mmlClip);
                            resetStb();
                            invalid             = false;
                            consoleText.text    = "Playing...";
                            playButtonText.text = "Pause";
                            playing             = true;
                        }
                    }
                    else
                    {
                        if (player.Playing)
                        {
                            player.Pause();
                            consoleText.text    = "";
                            playButtonText.text = "Continue";
                            playing             = false;
                        }
                        else
                        {
                            player.Continue();
                            consoleText.text    = "Playing...";
                            playButtonText.text = "Pause";
                            playing             = true;
                        }
                    }
                });
            }
        }