コード例 #1
0
        public void TinyInit(string keyEditorPref, string nameEditorWindow, DEFAULT_POSITION position, float defaultWidth = 150)
        {
            _currentEditorWindow = SceneView.currentDrawingSceneView;

            Rect rect = GetNiceRectFromEnum(position, defaultWidth, out bool snapUp, out bool snapRight);

            Init(
                keyEditorPref: keyEditorPref,
                nameEditorWindow: nameEditorWindow,
                id: keyEditorPref.GetHashCode(),
                windowMenu: rect,
                currentEditorWindow: _currentEditorWindow,
                currentEvent: Event.current,
                draggable: true,
                isMinimisable: false,
                snapRight: snapRight,
                snapUp: snapUp,
                maxRect: new Vector2(0, 0),
                applySetup: true,
                closable: true,
                lockToVisibleSizeX: true,
                lockToVisibleSizeY: true);
        }
コード例 #2
0
        /// <summary>
        ///
        /// type:       UP_LEFT         UP          UP_RIGHT
        /// anchor:     (up left)       (up left)   (up right)
        ///
        /// type:       MIDDLE_LEFT     MIDDLE      MIDDLE_RIGHT
        /// anchor:     (up left)       (up left)   (up right)
        ///
        ///
        /// type:       DOWN_LEFT       DOWN        DOWN_RIGHT
        /// anchor:     (down left)     (down left) (down right)
        /// </summary>
        /// <param name="position"></param>
        /// <param name="snapUp"></param>
        /// <param name="snapRight"></param>
        /// <returns></returns>
        public Rect GetNiceRectFromEnum(DEFAULT_POSITION position, float defaultWidth, out bool snapUp, out bool snapRight)
        {
            Rect rectNav = new Rect(0, 0, 0, 0);

            snapUp    = true;
            snapRight = false;

            float height = 50;

            switch (position)
            {
            case DEFAULT_POSITION.UP_LEFT:
            {
                snapUp    = true;
                snapRight = false;

                float x = 10;
                float y = 10;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.UP:
            {
                snapUp    = true;
                snapRight = false;

                float x = (EditorGUIUtility.currentViewWidth / 2) - (defaultWidth / 2);
                float y = 10;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.UP_RIGHT:
            {
                snapUp    = true;
                snapRight = true;

                float marginFromRight = 100f;
                float x = EditorGUIUtility.currentViewWidth - defaultWidth - marginFromRight;
                float y = 10;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.MIDDLE_LEFT:
            {
                snapUp    = true;
                snapRight = false;

                float x = 10f;
                float y = (_currentEditorWindow.position.height / 2) - (height / 2);
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.MIDDLE_RIGHT:
            {
                snapUp    = true;
                snapRight = true;

                float marginFromRight = 10f;
                float x = EditorGUIUtility.currentViewWidth - defaultWidth - marginFromRight;
                float y = (_currentEditorWindow.position.height / 2) - (height / 2);
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }


            case DEFAULT_POSITION.DOWN_LEFT:
            {
                snapUp    = false;
                snapRight = false;

                float marginFromDown = 10f;
                float x = 10;
                float y = _currentEditorWindow.position.height - height - marginFromDown;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.DOWN:
            {
                float yFromDown = 10;          //from bottom, go upper
                float x         = (EditorGUIUtility.currentViewWidth / 2) - (defaultWidth / 2);
                float y         = SceneView.currentDrawingSceneView.camera.pixelRect.size.y - height - yFromDown;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }

            case DEFAULT_POSITION.DOWN_RIGHT:
            {
                float yFromDown  = 10;         //from bottom, go upper
                float xFromRight = 10;
                float x          = EditorGUIUtility.currentViewWidth - defaultWidth - xFromRight;
                float y          = SceneView.currentDrawingSceneView.camera.pixelRect.size.y - height - yFromDown;
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }


            default:
            case DEFAULT_POSITION.MIDDLE:
            {
                snapUp    = true;
                snapRight = false;

                float x = (EditorGUIUtility.currentViewWidth / 2) - (defaultWidth / 2);
                float y = (_currentEditorWindow.position.height / 2) - (height / 2);
                rectNav = new Rect(x, y, defaultWidth, height);
                return(rectNav);
            }
            }
        }