Beispiel #1
0
        // Show buttons and a textarea
        private void OnGUI()
        {
            float x = 170f;

            if (GUI.Button(new Rect(x, 10, 160, 80), "Open a file"))
            {
                FilePanel.Settings settings = new FilePanel.Settings();
                settings.filters = new FilePanel.Filter[]
                {
                    new FilePanel.Filter("All files", "*"),
                    new FilePanel.Filter("Image files (*.png;*.jpg;*.jpeg;*.tiff;*.gif;*.tga)", "png", "jpg", "jpeg", "tiff", "gif", "tga"),
                    new FilePanel.Filter("Documents (*.txt;*.rtf;*.doc;*.docx)", "txt", "rtf", "doc", "docx"),
                };
                settings.title            = "Open a file!";
                settings.initialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);

                message = "Canceled";
                FilePanel.OpenFilePanel(settings, (files) =>
                {
                    message = "Open a file\n" + string.Join("\n", files);
                });
            }

            if (GUI.Button(new Rect(x, 100, 160, 80), "Open multiple files"))
            {
                FilePanel.Settings settings = new FilePanel.Settings();
                settings.filters = new FilePanel.Filter[]
                {
                    new FilePanel.Filter("Image files (*.png;*.jpg;*.jpeg;*.tiff;*.gif;*.tga)", "png", "jpg", "jpeg", "tiff", "gif", "tga"),
                    new FilePanel.Filter("Documents (*.txt;*.rtf;*.doc;*.docx)", "txt", "rtf", "doc", "docx"),
                    new FilePanel.Filter("All files", "*"),
                };
                settings.flags            = FilePanel.Flag.AllowMultipleSelection;
                settings.title            = "Open multiple files!";
                settings.initialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);

                message = "Canceled";
                FilePanel.OpenFilePanel(settings, (files) =>
                {
                    message = "Open multiple files\n" + string.Join("\n", files);
                });
            }

            if (GUI.Button(new Rect(x, 200, 160, 80), "Save file"))
            {
                FilePanel.Settings settings = new FilePanel.Settings();
                settings.filters = new FilePanel.Filter[]
                {
                    new FilePanel.Filter("Text file (*.txt;*.log)", "txt", "log"),
                    new FilePanel.Filter("Image files (*.png;*.jpg;*.jpeg;*.tiff;*.gif;*.tga)", "png", "jpg", "jpeg", "tiff", "gif", "tga"),
                    new FilePanel.Filter("All files", "*"),
                };
                settings.title       = "No save is actually performed";
                settings.initialFile = "Test.txt";

                message = "Canceled";
                FilePanel.SaveFilePanel(settings, (files) =>
                {
                    message = "Selected file\n" + string.Join("\n", files);
                });
            }

            GUI.TextArea(new Rect(x + 200, 10, 400, 400), message);
        }
Beispiel #2
0
        /// <summary>
        /// 毎フレーム行う処理
        /// </summary>
        private void Update()
        {
            // ヒットテスト関連の表示を更新
            UpdateHitTestUI();

            // 動作確認のためウィンドウ位置・サイズを表示
            if ((lastEventOccurredTime + eventMessageTimeout) < Time.time)
            {
                ShowWindowMetrics();
            }

            // マウス右ボタンクリックでメニューを表示させる。閾値以下の移動ならクリックとみなす。
            if (Input.GetMouseButtonDown(1))
            {
                lastMousePosition = Input.mousePosition;
                touchDuration     = 0f;
            }
            if (Input.GetMouseButton(1))
            {
                mouseMoveSS += (Input.mousePosition - lastMousePosition).sqrMagnitude;
            }
            if (Input.GetMouseButtonUp(1))
            {
                if (mouseMoveSS < mouseMoveSSThreshold)
                {
                    ShowMenu(lastMousePosition);
                }
                mouseMoveSS   = 0f;
                touchDuration = 0f;
            }

            // ロングタッチでもメニューを表示させる
            if (Input.touchSupported && (Input.touchCount > 0))
            {
                Touch touch = Input.GetTouch(0);
                if (touch.phase == TouchPhase.Began)
                {
                    lastMousePosition = Input.mousePosition;
                    touchDuration     = 0f;
                }
                if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                {
                    mouseMoveSS   += touch.deltaPosition.sqrMagnitude;
                    touchDuration += touch.deltaTime;
                }
                if (touch.phase == TouchPhase.Ended)
                {
                    if ((mouseMoveSS < mouseMoveSSThreshold) && (touchDuration >= touchDurationThreshold))
                    {
                        ShowMenu(lastMousePosition);
                    }
                    mouseMoveSS   = 0f;
                    touchDuration = 0f;
                }
            }

            // キーでも設定変更
            if (uniwinc)
            {
                // Toggle transparent
                if (Input.GetKeyUp(KeyCode.T))
                {
                    uniwinc.isTransparent = !uniwinc.isTransparent;
                }

                // Toggle always on the front
                if (Input.GetKeyUp(KeyCode.F))
                {
                    uniwinc.isTopmost = !uniwinc.isTopmost;
                }

                // Toggle always on the bottom
                if (Input.GetKeyUp(KeyCode.B))
                {
                    uniwinc.isBottommost = !uniwinc.isBottommost;
                }

                // Toggle zoom
                if (Input.GetKeyUp(KeyCode.Z))
                {
                    uniwinc.isZoomed = !uniwinc.isZoomed;
                }
            }


            // Test for OpenFilePanel
            if (Input.GetKeyUp(KeyCode.O))
            {
                FilePanel.Settings ds = new FilePanel.Settings
                {
                    flags   = FilePanel.Flag.AllowMultipleSelection,
                    title   = "Open!",
                    filters = new FilePanel.Filter[] {
                        new FilePanel.Filter("Image files", "png", "jpg", "jpeg"),
                        //new FilePanel.Filter("All files", "*"),
                    },
                    initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    initialFile      = "test.png",
                };
                FilePanel.OpenFilePanel(ds, (files) => ShowEventMessage(string.Join(Environment.NewLine, files)));
            }

            // Test for SaveFilePanel
            if (Input.GetKeyDown(KeyCode.S))
            {
                FilePanel.Settings ds = new FilePanel.Settings
                {
                    flags   = FilePanel.Flag.AllowMultipleSelection,
                    title   = "Save!",
                    filters = new FilePanel.Filter[] {
                        new FilePanel.Filter("Shell script", "sh"),
                        new FilePanel.Filter("Log", "log"),
                        new FilePanel.Filter("Plain text", "txt"),
                        //new FilePanel.Filter("All files", "*"),
                    },
                    initialFile      = "Test.txt",
                    initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                };
                FilePanel.SaveFilePanel(ds, (files) => ShowEventMessage(string.Join(Environment.NewLine, files)));
            }

            // Quit or stop playing when pressed [ESC]
            if (Input.GetKey(KeyCode.Escape))
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#else
                Application.Quit();
#endif
            }
        }