Exemple #1
0
        /// <summary>
        /// Begins a scaled local area.
        /// Returns vector to offset GUI controls with to account for zooming to the pivot.
        /// Using adjustGUILayout does that automatically for GUILayout rects. Theoretically can be nested!
        /// </summary>
        public static Vector2 BeginScale(ref Rect rect, Vector2 zoomPivot, float zoom, bool adjustGUILayout)
        {
            Rect screenRect;

            if (compabilityMode)
            {
                // In compability mode, we will assume only one top group and do everything manually, not using reflected calls (-> practically blind)
                GUI.EndGroup();
                screenRect = rect;
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    screenRect.y += 23;
                }
#endif
            }
            else
            {
                // If it's supported, we take the completely generic way using reflected calls
                GUIScaleUtility.BeginNoClip();
                screenRect = GUIScaleUtility.GUIToScaledSpace(rect);
            }

            rect = Scale(screenRect, screenRect.position + zoomPivot, new Vector2(zoom, zoom));

            // Now continue drawing using the new clipping group
            GUI.BeginGroup(rect);
            rect.position = Vector2.zero;             // Adjust because we entered the new group

            // Because I currently found no way to actually scale to a custom pivot rather than (0, 0),
            // we'll make use of a cheat and just offset it accordingly to let it appear as if it would scroll to the center
            // Note, due to that, controls not adjusted are still scaled to (0, 0)
            Vector2 zoomPosAdjust = rect.center - screenRect.size / 2 + zoomPivot;

            // For GUILayout, we can make this adjustment here if desired
            adjustedGUILayout.Add(adjustGUILayout);
            if (adjustGUILayout)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(rect.center.x - screenRect.size.x + zoomPivot.x);
                GUILayout.BeginVertical();
                GUILayout.Space(rect.center.y - screenRect.size.y + zoomPivot.y);
            }

            // Take a matrix backup to restore back later on
            GUIMatrices.Add(GUI.matrix);

            // Scale GUI.matrix. After that we have the correct clipping group again.
            GUIUtility.ScaleAroundPivot(new Vector2(1 / zoom, 1 / zoom), zoomPosAdjust);

            return(zoomPosAdjust);
        }
        private void OnGUI()
        {
            if (optionStyle == null)
            {
                optionStyle         = (GUIStyle)"ObjectPickerPreviewBackground";
                optionStyle.padding = new RectOffset(10, 10, 10, 10);
            }

            DrawGrid(20, 0.2f, Color.gray);
            DrawGrid(100, 0.4f, Color.gray);
            OnGUIToolBar();

            var test = _canvasWindowRect;
            var sc   = GUIScaleUtility.BeginScale(ref test, zoomOrigin, zoomScale, false);

            if (_activeMap < _maps.Count)
            {
                DrawNodes(sc);

                ProcessNodeEvents(Event.current);
                ProcessEvents(Event.current);

                if (GUI.changed)
                {
                    Repaint();
                }
            }
            GUIScaleUtility.EndScale();

            if (_showOptions)
            {
                GUILayout.BeginArea(_optionsRect, optionStyle);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Hide Modifiers", (GUIStyle)"ButtonLeft", GUILayout.Width(115)))
                {
                    Parse(false);
                }
                if (GUILayout.Button("Show Modifiers", (GUIStyle)"ButtonRight", GUILayout.Width(115)))
                {
                    Parse(true);
                }
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Reset Zoom", EditorStyles.miniButton, GUILayout.Width(230)))
                {
                    zoomScale = 1;
                }
                GUILayout.EndArea();
            }
        }
Exemple #3
0
        /// <summary>
        /// Ends a scale region previously opened with BeginScale
        /// </summary>
        public static void EndScale()
        {
            // Set last matrix and clipping group
            if (GUIMatrices.Count == 0 || adjustedGUILayout.Count == 0)
            {
                throw new UnityException("GUIScaleUtility: You are ending more scale regions than you are beginning!");
            }
            GUI.matrix = GUIMatrices[GUIMatrices.Count - 1];
            GUIMatrices.RemoveAt(GUIMatrices.Count - 1);

            // End GUILayout zoomPosAdjustment
            if (adjustedGUILayout[adjustedGUILayout.Count - 1])
            {
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }

            adjustedGUILayout.RemoveAt(adjustedGUILayout.Count - 1);

            // End the scaled group
            GUI.EndGroup();

            if (compabilityMode)
            {
                // In compability mode, we don't know the previous group rect, but as we cannot use top groups there either way, we restore the screen group
                if (!Application.isPlaying)                 // We're in an editor window
                {
                    GUI.BeginClip(new Rect(0, 23, Screen.width, Screen.height - 23));
                }
                else
                {
                    GUI.BeginClip(new Rect(0, 0, Screen.width, Screen.height));
                }
            }
            else
            {
                // Else, restore the clips (groups)
                GUIScaleUtility.RestoreClips();
            }
        }
        private void OnEnable()
        {
            GUIScaleUtility.CheckInit();
            //MagnifierTexture = EditorGUIUtility.FindTexture("d_ViewToolZoom");
            var textOffset = new RectOffset(12, 0, 10, 0);

            nodeStyle = new GUIStyle();
            nodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node1.png") as Texture2D;
            nodeStyle.border            = new RectOffset(12, 12, 12, 12);
            nodeStyle.richText          = true;
            nodeStyle.padding           = textOffset;

            selectedNodeStyle = new GUIStyle();
            selectedNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node1 on.png") as Texture2D;
            selectedNodeStyle.border            = new RectOffset(12, 12, 12, 12);
            selectedNodeStyle.richText          = true;
            selectedNodeStyle.padding           = textOffset;

            leafNodeStyle = new GUIStyle();
            leafNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node2.png") as Texture2D;
            leafNodeStyle.border            = new RectOffset(12, 12, 12, 12);
            leafNodeStyle.richText          = true;
            leafNodeStyle.padding           = textOffset;

            inPointStyle = new GUIStyle();
            inPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left.png") as Texture2D;
            inPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left on.png") as Texture2D;
            inPointStyle.border            = new RectOffset(4, 4, 12, 12);

            outPointStyle = new GUIStyle();
            outPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right.png") as Texture2D;
            outPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right on.png") as Texture2D;
            outPointStyle.border            = new RectOffset(4, 4, 12, 12);

            Parse();
        }