public void DrawGUI()
        {
            // grab data
            R2DC_Settings controller   = R2DC_Settings.Instance;
            List <string> contextNames = controller.contextNames;

            // title
            drawing.BeginEditorHorizontal();
            drawing.DrawPanelTitle(R2DD_Lang.titleRulerSettings, resources.panelSettings);
            drawing.FlexibleSpace();

            if (drawing.DrawImageButton(resources.help))
            {
                Help.BrowseURL(R2DD_Resources.urlSettingsHelp);
            }
            ;

            drawing.EndEditorHorizontal();

            // Not in 2d error
            if (!utils.IsSceneViewIn2D())
            {
                drawing.DrawErrorBox(R2DD_Lang.sceneModeError);

                drawing.DrawSpace(9f);

                if (drawing.DrawButton(R2DD_Lang.set2DSceneMode))
                {
                    utils.Set2DMode();
                    utils.RepaintSceneView();
                }

                utils.RepaintEditorWindow();
                return;
            }

            // context
            drawing.DrawPanelLabel(R2DD_Lang.context);

            int oldContextInstanceId = state.context.instanceId;
            int contextIndex         = drawing.DrawPopup(controller.contextIndex, contextNames.ToArray());
            int newContextInstanceId = controller.availableContexts[contextIndex].instanceId;

            if (oldContextInstanceId != newContextInstanceId)
            {
                controller.SetContext(contextIndex);
                utils.RepaintSceneView();
            }

            drawing.DrawSpace(9f);

            // show coordinates
            bool oldDisplayCoords = state.displayCoords;

            state.displayCoords = drawing.DrawToggleWithWidth(R2DD_Lang.displaySelectedCoords, state.displayCoords, toggleWidth);

            if (oldDisplayCoords != state.displayCoords)
            {
                utils.RepaintSceneView();
            }

            // prefer colliders
            state.preferColliders = drawing.DrawToggleWithWidth(R2DD_Lang.preferColliders, state.preferColliders, toggleWidth);

            // show/hide guides
            bool oldDisplayGuides = state.displayGuides;

            state.displayGuides = drawing.DrawToggleWithWidth(R2DD_Lang.displayGuides, state.displayGuides, toggleWidth);

            if (oldDisplayGuides != state.displayGuides)
            {
                utils.RepaintSceneView();
            }

            // lock guides
            bool oldLockGuides = state.lockGuides;

            state.lockGuides = drawing.DrawToggleWithWidth(R2DD_Lang.lockGuides, state.lockGuides, toggleWidth);

            if (oldLockGuides != state.lockGuides)
            {
                utils.RepaintSceneView();
            }

            // snap guide to int
            state.snapGuideToInt = drawing.DrawToggleWithWidth(R2DD_Lang.snapGuideToInt, state.snapGuideToInt, toggleWidth);

            // use edges for snapping
            state.snapEdges = drawing.DrawToggleWithWidth(R2DD_Lang.lblUseEdgesForSnap, state.snapEdges, toggleWidth);
        }
        public void HandleInteraction()
        {
            if (!measureToolActive)
            {
                return;
            }
            EventType eventType = Event.current.type;

            Vector2 mousePosition = Event.current.mousePosition;

            mousePosition.y = viewPixelFrame.height - mousePosition.y + 5f;

            switch (eventType)
            {
            case EventType.MouseDown:
                if (IsInRenderBounds(mousePosition) && !guides.IsCreatingGuides())
                {
                    ClearMeasurement();
                    HotControl();
                    readyToMeasure = true;
                    startCoord     = utils.GetWorldCoord(mousePosition);
                }
                break;

            case EventType.MouseDrag:
                if (readyToMeasure)
                {
                    if (IsInRenderBounds(mousePosition))
                    {
                        measuring    = true;
                        currentCoord = utils.GetWorldCoord(mousePosition);
                        utils.RepaintSceneView();
                    }
                    else
                    {
                        CancelMeasurement();
                    }
                }
                break;

            case EventType.MouseUp:
                if (measuring)
                {
                    if (IsInRenderBounds(mousePosition))
                    {
                        CompleteMeasurement();
                    }
                    else
                    {
                        CancelMeasurement();
                    }
                }
                break;

            default:
                if (measuring && !IsInRenderBounds(mousePosition))
                {
                    CancelMeasurement();
                }
                break;
            }
        }
예제 #3
0
        public void HandleInteraction()
        {
            EventType eventType = Event.current.type;

            if (Event.current.button != 0)
            {
                eventType = EventType.Ignore;
            }

            Vector2 mousePosition = Event.current.mousePosition;

            mousePosition.y = viewPixelFrame.height - mousePosition.y + 5f;

            int hGuideIndex = -1;
            int vGuideIndex = -1;

            if (hoverGuide != Vector2.zero)
            {
                utils.RepaintSceneView();
            }
            hoverGuide = Vector2.zero;

            if (creatingHGuide)
            {
                ShowHorizontalCursor();
            }
            else if (creatingVGuide)
            {
                ShowVerticalCursor();
            }
            else
            {
                if (IsInRenderBounds(mousePosition) && state.displayGuides)
                {
                    hGuideIndex = GetHGuideHitBoxIndex(mousePosition);
                    if (hGuideIndex == -1)
                    {
                        vGuideIndex = GetVGuideHitBoxIndex(mousePosition);
                        if (vGuideIndex != -1)
                        {
                            ShowVerticalCursor();
                            hoverGuide.x = float.Parse(state.vGuides[vGuideIndex]);
                            utils.RepaintSceneView();
                        }
                    }
                    else
                    {
                        ShowHorizontalCursor();
                        hoverGuide.y = float.Parse(state.hGuides[hGuideIndex]);
                        utils.RepaintSceneView();
                    }
                }
            }

            switch (eventType)
            {
            case EventType.MouseDown:
                if (!IsCreatingGuides())
                {
                    if (IsOnTopRuler(mousePosition))
                    {
                        HotControl();
                        creatingHGuide = true;
                        utils.RepaintSceneView();
                    }
                    else if (IsOnLeftRuler(mousePosition))
                    {
                        HotControl();
                        creatingVGuide = true;
                        utils.RepaintSceneView();
                    }
                    else
                    {
                        if (hGuideIndex > -1)
                        {
                            HotControl();
                            state.hGuides.RemoveAt(hGuideIndex);
                            creatingHGuide = true;
                            UpdateLiveGuidePosition(mousePosition);
                            utils.RepaintSceneView();
                        }
                        else
                        {
                            if (vGuideIndex > -1)
                            {
                                HotControl();
                                state.vGuides.RemoveAt(vGuideIndex);
                                creatingVGuide = true;
                                UpdateLiveGuidePosition(mousePosition);
                                utils.RepaintSceneView();
                            }
                        }
                    }
                }
                break;

            case EventType.MouseUp:
                if (IsCreatingGuides())
                {
                    if (IsInRenderBounds(mousePosition))
                    {
                        CompleteGuideCreation();
                    }
                    else
                    {
                        CancelGuideCreation();
                    }
                    GUIUtility.hotControl = 0;
                    utils.RepaintSceneView();
                }
                break;

            case EventType.MouseDrag:
                if (IsCreatingGuides())
                {
                    if (IsInRenderBounds(mousePosition))
                    {
                        UpdateLiveGuidePosition(mousePosition);
                    }
                    else if (IsOnCorner(mousePosition) ||
                             (IsOnTopRuler(mousePosition) && creatingHGuide) ||
                             (IsOnLeftRuler(mousePosition) && creatingVGuide))
                    {
                        // just hide the live guide
                        liveGuide = Vector2.zero;
                    }
                    utils.RepaintSceneView();
                }
                break;

            default:
                if (IsCreatingGuides() && IsOutOfBounds(mousePosition))
                {
                    GUIUtility.hotControl = 0;
                    CancelGuideCreation();
                    utils.RepaintSceneView();
                }
                break;
            }
        }
예제 #4
0
        public void DrawGUI()
        {
            bool alignEnabled = movement.alignEnabled;

            // title
            drawing.BeginEditorHorizontal();
            drawing.DrawPanelTitle(R2DD_Lang.titleToolbox, resources.panelToolbox);
            drawing.FlexibleSpace();

            if (drawing.DrawImageButton(resources.help))
            {
                Help.BrowseURL(resources.urlToolboxHelp);
            }
            ;
            drawing.EndEditorHorizontal();

            // Not in 2d error
            if (!utils.IsSceneViewIn2D())
            {
                drawing.DrawErrorBox(R2DD_Lang.sceneModeError);

                drawing.DrawSpace(9f);
                if (drawing.DrawButton(R2DD_Lang.set2DSceneMode))
                {
                    utils.Set2DMode();
                    utils.RepaintSceneView();
                }

                utils.RepaintEditorWindow();
                return;
            }

            // align tools
            drawing.DrawCenteredLabel(R2DD_Lang.lblAlign);

            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            drawing.DrawSpace(4f);
            if (drawing.DrawToolButton(resources.alignTop, alignEnabled, R2DD_Lang.tipAlignTop))
            {
                movement.AlignTop();
            }
            if (drawing.DrawToolButton(resources.alignYMid, alignEnabled, R2DD_Lang.tipAlignHMid))
            {
                movement.AlignYMid();
            }
            if (drawing.DrawToolButton(resources.alignBot, alignEnabled, R2DD_Lang.tipAlignBot))
            {
                movement.AlignBot();
            }
            if (drawing.DrawToolButton(resources.alignLeft, alignEnabled, R2DD_Lang.tipAlignLeft))
            {
                movement.AlignLeft();
            }
            if (drawing.DrawToolButton(resources.alignXMid, alignEnabled, R2DD_Lang.tipAlignVMid))
            {
                movement.AlignXMid();
            }
            if (drawing.DrawToolButton(resources.alignRight, alignEnabled, R2DD_Lang.tipAlignRight))
            {
                movement.AlignRight();
            }
            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();

            // Distribute tools
            bool distroEnabled = movement.distroEnabled;

            drawing.DrawSpace(6f);
            drawing.DrawCenteredLabel(R2DD_Lang.lblDistribute);

            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            drawing.DrawSpace(4f);
            if (drawing.DrawToolButton(resources.distroTop, distroEnabled, R2DD_Lang.tipDistTop))
            {
                movement.DistroTop();
            }

            if (drawing.DrawToolButton(resources.distroYMid, distroEnabled, R2DD_Lang.tipDistYMid))
            {
                movement.DistroYMid();
            }

            if (drawing.DrawToolButton(resources.distroBot, distroEnabled, R2DD_Lang.tipDistBot))
            {
                movement.DistroBot();
            }

            if (drawing.DrawToolButton(resources.distroLeft, distroEnabled, R2DD_Lang.tipDistLeft))
            {
                movement.DistroLeft();
            }

            if (drawing.DrawToolButton(resources.distroXMid, distroEnabled, R2DD_Lang.tipDistXMid))
            {
                movement.DistroXMid();
            }

            if (drawing.DrawToolButton(resources.distroRight, distroEnabled, R2DD_Lang.tipDistRight))
            {
                movement.DistroRight();
            }
            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();

            // Spacing tools
            bool spaceEnabled = movement.spaceEnabled;

            drawing.DrawSpace(6f);
            drawing.DrawCenteredLabel(R2DD_Lang.lblSpace);

            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            bool spaceXPressed = drawing.DrawToolButton(resources.spaceX, spaceEnabled, R2DD_Lang.tipSpaceX);

            drawing.BeginEditorVertical();
            drawing.DrawSpace(9f);
            state.spaceX = drawing.DrawFloatFieldWithWidth("", state.spaceX);
            drawing.EndEditorVertical();

            if (spaceXPressed)
            {
                movement.SpaceX(state.spaceX);
            }

            bool spaceYPressed = drawing.DrawToolButton(resources.spaceY, spaceEnabled, R2DD_Lang.tipSpaceY);

            drawing.BeginEditorVertical();
            drawing.DrawSpace(9f);
            state.spaceY = drawing.DrawFloatFieldWithWidth("", state.spaceY);
            drawing.EndEditorVertical();

            if (spaceYPressed)
            {
                movement.SpaceY(state.spaceY);
            }

            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();

            // Guide Snap Tool
            bool guideSnapEnabled = movement.guideSnapEnabled;

            drawing.DrawSpace(6f);
            drawing.DrawCenteredLabel(R2DD_Lang.lblSnapToGuide);

            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            drawing.DrawSpace(4f);

            bool leftRightEnabled = state.vGuides.Count > 0 && guideSnapEnabled && state.displayGuides ? true : false;
            bool topDownEnabled   = state.hGuides.Count > 0 && guideSnapEnabled && state.displayGuides ? true : false;

            if (drawing.DrawToolButton(resources.snapLeft, leftRightEnabled, R2DD_Lang.tipSnapLeft))
            {
                movement.SnapLeft();
            }

            if (drawing.DrawToolButton(resources.snapRight, leftRightEnabled, R2DD_Lang.tipSnapRight))
            {
                movement.SnapRight();
            }

            if (drawing.DrawToolButton(resources.snapTop, topDownEnabled, R2DD_Lang.tipSnapTop))
            {
                movement.SnapTop();
            }

            if (drawing.DrawToolButton(resources.snapBot, topDownEnabled, R2DD_Lang.tipSnapBot))
            {
                movement.SnapBot();
            }

            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();


            // Measure
            drawing.DrawSpace(6f);
            drawing.DrawCenteredLabel(R2DD_Lang.lblMeasure);

            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            drawing.DrawSpace(4f);

            Texture measureButton = measure.IsMeasureToolActive() ? resources.measureActive : resources.measureInactive;

            if (drawing.DrawToolButton(measureButton, true, R2DD_Lang.tipMeasure))
            {
                measure.ToggleMeasureTool();
            }

            if (drawing.DrawToolButton(resources.measureObj, measure.IsMeasureObjEnabled(), R2DD_Lang.tipMeasureObj))
            {
                measure.MeasureObj();
            }

            if (drawing.DrawToolButton(resources.clearMeasure, true, R2DD_Lang.tipClearMeasure))
            {
                measure.ClearMeasureTool();
            }

            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();

            // clear guides
            drawing.DrawSpace(9f);
            if (drawing.DrawButton(R2DD_Lang.clearGuides))
            {
                state.hGuides.Clear();
                state.vGuides.Clear();
                utils.RepaintSceneView();
            }

            // tip
            drawing.DrawSpace(4f);
            if (movement.error == R2DC_Movement.ADError.NGUIContext)
            {
                drawing.DrawErrorBox(R2DD_Lang.nguiInvalidContext);
            }
            else if (movement.error == R2DC_Movement.ADError.NGUIReflection)
            {
                drawing.DrawErrorBox(R2DD_Lang.nguiError);
            }
            else if (movement.error == R2DC_Movement.ADError.CanvasContext)
            {
                drawing.DrawErrorBox(R2DD_Lang.canvasInvalidContext);
            }
            else
            {
                drawing.DrawHelpBox(R2DD_Lang.guideHelp);
            }

            // logo
            drawing.FlexibleSpace();
            drawing.BeginEditorHorizontal();
            drawing.FlexibleSpace();
            drawing.DrawPanelTexture(resources.logo);
            drawing.FlexibleSpace();
            drawing.EndEditorHorizontal();
            drawing.DrawSpace(5f);
        }
        public void DrawGUI()
        {
            // title
            drawing.BeginEditorHorizontal();
            drawing.DrawPanelTitle(R2DD_Lang.titleGrid, resources.panelGrid);
            drawing.FlexibleSpace();

            if (drawing.DrawImageButton(resources.help))
            {
                Help.BrowseURL(R2DD_Resources.urlGridHelp);
            }
            ;

            drawing.EndEditorHorizontal();

            // Not in 2d error
            if (!utils.IsSceneViewIn2D())
            {
                drawing.DrawErrorBox(R2DD_Lang.sceneModeError);

                drawing.DrawSpace(9f);

                if (drawing.DrawButton(R2DD_Lang.set2DSceneMode))
                {
                    utils.Set2DMode();
                    utils.RepaintSceneView();
                }

                utils.RepaintEditorWindow();
                return;
            }


            // enable grid
            bool oldGridEnabled = state.gridEnabled;

            state.gridEnabled = drawing.DrawToggle(R2DD_Lang.gridEnabled, state.gridEnabled);

            if (oldGridEnabled != state.gridEnabled)
            {
                utils.RepaintSceneView();
            }

            // grid columns
            int oldGridCols = state.gridCols;

            state.gridCols = drawing.DrawIntField(R2DD_Lang.gridCols, state.gridCols);

            if (state.gridCols < 2)
            {
                state.gridCols = 2;
            }

            if (oldGridCols != state.gridCols)
            {
                utils.RepaintSceneView();
            }

            // grid rows
            int oldGridRows = state.gridRows;

            state.gridRows = drawing.DrawIntField(R2DD_Lang.gridRows, state.gridRows);

            if (state.gridRows < 2)
            {
                state.gridRows = 2;
            }

            if (oldGridRows != state.gridRows)
            {
                utils.RepaintSceneView();
            }

            // grid x
            float oldGridX = state.gridX;

            state.gridX = drawing.DrawFloatField(R2DD_Lang.gridX, state.gridX);

            if (state.gridX < 0.1f)
            {
                state.gridX = 0.1f;
            }

            if (oldGridX != state.gridX)
            {
                utils.RepaintSceneView();
            }

            // grid y
            float oldGridY = state.gridY;

            state.gridY = drawing.DrawFloatField(R2DD_Lang.gridY, state.gridY);

            if (state.gridY < 0.1f)
            {
                state.gridY = 0.1f;
            }

            if (oldGridY != state.gridY)
            {
                utils.RepaintSceneView();
            }

            // grid origin x
            float oldGridOriginX = state.gridOriginX;

            state.gridOriginX = drawing.DrawFloatField(R2DD_Lang.gridOriginX, state.gridOriginX);

            if (oldGridOriginX != state.gridOriginX)
            {
                utils.RepaintSceneView();
            }

            // grid origin y
            float oldGridOriginY = state.gridOriginY;

            state.gridOriginY = drawing.DrawFloatField(R2DD_Lang.gridOriginY, state.gridOriginY);

            if (oldGridOriginY != state.gridOriginY)
            {
                utils.RepaintSceneView();
            }

            // snap to grid
            state.snapToGrid = drawing.DrawToggle(R2DD_Lang.snapToGrid, state.snapToGrid);

            // toggle unity grid
            // clear guides
            drawing.DrawSpace(9f);

            if (drawing.DrawButton(R2DD_Lang.toggleUnityGrid))
            {
                grid.ToggleUnityGrid();
                utils.RepaintSceneView();
            }

            // NGUI snap issue guide
            drawing.DrawSpace(4f);

            if (state.context.type == ContextType.NGUI && state.snapToGrid)
            {
                drawing.DrawHelpBox(R2DD_Lang.nguiGridHelp);
            }
        }