コード例 #1
0
ファイル: MJSimulate.cs プロジェクト: ZWO2VPY6UT/grewRL
    // per-frame keyboard input; called from Update
    unsafe void ProcessKeyboard()
    {
        // F1: toggle help
        if (Input.GetKeyDown(KeyCode.F1))
        {
            showhelp++;
            if (showhelp > 2)
            {
                showhelp = 0;
            }
        }

        // G: toggle gravity
        else if (Input.GetKeyDown("g"))
        {
            MJP.TOption opt;
            MJP.GetOption(&opt);
            opt.gravity = 1 - opt.gravity;
            MJP.SetOption(&opt);
        }

        // E: toggle equality
        else if (Input.GetKeyDown("e"))
        {
            MJP.TOption opt;
            MJP.GetOption(&opt);
            opt.equality = 1 - opt.equality;
            MJP.SetOption(&opt);
        }

        // L: toggle limit
        else if (Input.GetKeyDown("l"))
        {
            MJP.TOption opt;
            MJP.GetOption(&opt);
            opt.limit = 1 - opt.limit;
            MJP.SetOption(&opt);
        }

        // R: toggle video recording
        else if (Input.GetKeyDown("r"))
        {
            // recording: close
            if (record)
            {
                record = false;
                videofile.Close();
                videofile = null;
            }

            // not recording: open
            else
            {
                record    = true;
                videofile = new FileStream(Application.streamingAssetsPath + "/../../" + "video_" + videos + ".raw",
                                           FileMode.Create, FileAccess.Write);
                videos++;
            }
        }

        // S: save snapshot
        else if (Input.GetKeyDown("s"))
        {
            RenderToTexture();
            byte[] bytes = offtex.EncodeToPNG();
            File.WriteAllBytes(Application.streamingAssetsPath + "/../../" + "img_" + snapshots + ".png", bytes);
            snapshots++;
        }

        // backspace: reset and sync
        else if (Input.GetKeyDown(KeyCode.Backspace))
        {
            MJP.Reset();
            MJP.SetTime(Time.time);
            videotime = Time.time;
        }

        // space: toggle pause and sync
        else if (Input.GetKeyDown(KeyCode.Space))
        {
            pause = !pause;
            MJP.SetTime(Time.time);
            videotime = Time.time;
        }

        // Esc: main camera
        else if (Input.GetKeyDown(KeyCode.Escape))
        {
            camindex = -1;
        }

        // load scene or set model camera
        else
        {
            for (int i = 0; i <= 9; i++)
            {
                if (Input.GetKeyDown(i.ToString()))
                {
                    // load scene: runtime only
                    if (Input.GetKey(KeyCode.LeftShift) ||
                        Input.GetKey(KeyCode.RightShift))
                    {
                    #if !UNITY_EDITOR
                        if (i < SceneManager.sceneCountInBuildSettings)
                        {
                            SceneManager.LoadScene(i, LoadSceneMode.Single);
                        }
                    #endif
                    }

                    // set camera
                    else
                    {
                        if (i < ncamera)
                        {
                            camindex = i;
                        }
                    }
                }
            }
        }
    }