/// <summary>
        /// 初期化
        /// </summary>
        void Start()
        {
            // UniWindowController を探す
            uniwinc = GameObject.FindObjectOfType <UniWindowController>();

            // UniWindowDragMove を探す
            uniWinMoveHandle = GameObject.FindObjectOfType <UniWindowMoveHandle>();

            // Toggleのチェック状態を、現在の状態に合わせる
            UpdateUI();

            if (uniwinc)
            {
                // UIを操作された際にはウィンドウに反映されるようにする
                transparentToggle?.onValueChanged.AddListener(val => uniwinc.isTransparent = val);
                topmostToggle?.onValueChanged.AddListener(val => uniwinc.isTopmost         = val);
                zoomedToggle?.onValueChanged.AddListener(val => uniwinc.isZoomed           = val);
                allowDropToggle?.onValueChanged.AddListener(val => uniwinc.allowDropFiles  = val);

                widthDownButton?.onClick.AddListener(() => uniwinc.windowSize  += new Vector2(-100, 0));
                widthUpButton?.onClick.AddListener(() => uniwinc.windowSize    += new Vector2(+100, 0));
                heightDownButton?.onClick.AddListener(() => uniwinc.windowSize += new Vector2(0, -100));
                heightUpButton?.onClick.AddListener(() => uniwinc.windowSize   += new Vector2(0, +100));

                clickThroughToggle?.onValueChanged.AddListener(val => uniwinc.isClickThrough = val);

                transparentTypeDropdown?.onValueChanged.AddListener(val => uniwinc.SetTransparentType((UniWinCore.TransparentType)val));
                hitTestTypeDropdown?.onValueChanged.AddListener(val => uniwinc.hitTestType = (UniWindowController.HitTestType)val);
                menuCloseButton?.onClick.AddListener(CloseMenu);

                if (uniWinMoveHandle)
                {
                    dragMoveToggle?.onValueChanged.AddListener(val => uniWinMoveHandle.enabled = val);
                }

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                // Windows でなければ、透過方法の選択は無効とする
                //if (transparentTypeDropdown) transparentTypeDropdown.interactable = false;
                //if (transparentTypeDropdown) transparentTypeDropdown.enabled = false;
                if (transparentTypeDropdown)
                {
                    transparentTypeDropdown.gameObject.SetActive(false);
                }
#endif

                // Add events
                uniwinc.OnDisplayChanged += () => { ShowEventMessage("Display changed!"); };
                uniwinc.OnDropFiles      += files => { ShowEventMessage(string.Join(Environment.NewLine, files)); };
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 初期化
        /// </summary>
        void Start()
        {
            // UniWindowController を探す
            uniwinc = UniWindowController.current;

            // UniWindowDragMove を探す
            uniWinMoveHandle = GameObject.FindObjectOfType <UniWindowMoveHandle>();

            // CanvasのRectTransform取得
            if (menuPanel)
            {
                canvasRect = menuPanel.GetComponentInParent <Canvas>().GetComponent <RectTransform>();
            }

            // 有効なモニタ数に合わせて選択肢を作成
            UpdateMonitorDropdown();

            // Toggleのチェック状態を、現在の状態に合わせる
            UpdateUI();

            if (uniwinc)
            {
                // UIを操作された際にはウィンドウに反映されるようにする
                transparentToggle?.onValueChanged.AddListener(val => uniwinc.isTransparent = val);
                alphaSlider?.onValueChanged.AddListener(val => uniwinc.alphaValue          = val);
                topmostToggle?.onValueChanged.AddListener(val => uniwinc.isTopmost         = val);
                bottommostToggle?.onValueChanged.AddListener(val => uniwinc.isBottommost   = val);
                zoomedToggle?.onValueChanged.AddListener(val => uniwinc.isZoomed           = val);
                allowDropToggle?.onValueChanged.AddListener(val => uniwinc.allowDropFiles  = val);

                fitWindowDropdown?.onValueChanged.AddListener(val => SetFitToMonitor(val));

                widthDownButton?.onClick.AddListener(() => uniwinc.windowSize  += new Vector2(-100, 0));
                widthUpButton?.onClick.AddListener(() => uniwinc.windowSize    += new Vector2(+100, 0));
                heightDownButton?.onClick.AddListener(() => uniwinc.windowSize += new Vector2(0, -100));
                heightUpButton?.onClick.AddListener(() => uniwinc.windowSize   += new Vector2(0, +100));

                clickThroughToggle?.onValueChanged.AddListener(val => uniwinc.isClickThrough = val);

                transparentTypeDropdown?.onValueChanged.AddListener(val => uniwinc.SetTransparentType((UniWindowController.TransparentType)val));
                hitTestTypeDropdown?.onValueChanged.AddListener(val => uniwinc.hitTestType = (UniWindowController.HitTestType)val);
                menuCloseButton?.onClick.AddListener(CloseMenu);

                if (uniWinMoveHandle)
                {
                    dragMoveToggle?.onValueChanged.AddListener(val => uniWinMoveHandle.enabled = val);
                }

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                // Windows でなければ、透過方法の選択は無効とする
                //if (transparentTypeDropdown) transparentTypeDropdown.interactable = false;
                //if (transparentTypeDropdown) transparentTypeDropdown.enabled = false;
                if (transparentTypeDropdown)
                {
                    transparentTypeDropdown.gameObject.SetActive(false);
                }
#endif

                // Add events
                uniwinc.OnStateChanged += (type) =>
                {
                    UpdateUI();
                    //Debug.Log("Window state changed: " + type);
                    ShowEventMessage("State changed: " + type);
                    //ShowEventMessage("State changed: " + type + "4:isKey 2:canBecomeKey, 1:canBecomeMain  : " + uniwinc.GetDebugInfo().ToString());
                };
                uniwinc.OnMonitorChanged += () => {
                    UpdateMonitorDropdown();
                    UpdateUI();
                    ShowEventMessage("Resolution changed!");
                };
                uniwinc.OnDropFiles += files =>
                {
                    ShowEventMessage(string.Join(Environment.NewLine, files));
                };
            }

            // UinWinCが準備できてなくても動くListener
            showBorderlineToggle?.onValueChanged.AddListener(val => borderlinePanel.gameObject.SetActive(val));
        }