public Measurement GetMeasurement(Vector2 startWorldCoord, Vector2 endWorldCood)
        {
            Vector2 start = new Vector2(
                utils.GetWorldToContextX(startWorldCoord.x),
                utils.GetWorldToContextY(startWorldCoord.y)
                );

            Vector2 end = new Vector2(
                utils.GetWorldToContextX(endWorldCood.x),
                utils.GetWorldToContextY(endWorldCood.y)
                );

            Measurement measurement = new Measurement();

            measurement.x = start.x;
            measurement.y = start.y;
            float yDiff = end.y - start.y;
            float xDiff = end.x - start.x;

            measurement.h      = Mathf.Abs(yDiff);
            measurement.w      = Mathf.Abs(xDiff);
            measurement.angle  = Mathf.Atan2(yDiff, xDiff) * 180.0f / Mathf.PI;
            measurement.length = Mathf.Sqrt(Mathf.Pow(yDiff, 2) + Mathf.Pow(xDiff, 2));

            return(measurement);
        }
Beispiel #2
0
        void DrawHRulers()
        {
            drawing.DrawTexture(resources.rulerHBg, 0, 0, (int)viewPixelFrame.width, stripBgSize);

            float camSize             = contextInfo.editorCameraSize / contextInfo.scale.x;
            float rawSegmentUnitWidth = scaleTable[GetScaleKey(camSize)].cap;
            float segmentUnitWidth    = rawSegmentUnitWidth * contextInfo.scale.x;

            float startingLeftUnit = viewUnitFrame.botLeft.x - segmentUnitWidth;

            startingLeftUnit = startingLeftUnit - (startingLeftUnit % segmentUnitWidth);

            float endingRightUnit = viewUnitFrame.botRight.x + segmentUnitWidth;

            endingRightUnit = endingRightUnit - (endingRightUnit % segmentUnitWidth);

            startingLeftUnit += contextInfo.origin.x % segmentUnitWidth;;

            float runningUnit     = startingLeftUnit;
            float runningPixel    = utils.GetWorldToScreenPixelCoord(new Vector3(runningUnit, viewUnitFrame.topLeft.y)).x;
            float runningPixelCap = utils.GetWorldToScreenPixelCoord(new Vector3(runningUnit + segmentUnitWidth, viewUnitFrame.topLeft.y)).x;
            float innerSlicesDist = (runningPixelCap - runningPixel) / 4f;

            while (runningUnit < endingRightUnit)
            {
                // Draw main coord
                DrawVLine(runningPixel, viewPixelFrame.topLeft.y, stripHiSize, resources.rulerLinePixel);
                string virtualXCoord = FormatNumber(utils.GetWorldToContextX(runningUnit), camSize);
                DrawVLineLabel(virtualXCoord, runningPixel + vLineLabelXOffset, viewPixelFrame.topLeft.y + vLineLabelYOffset);

                // Draw slices
                runningPixel += innerSlicesDist;
                DrawVLine(runningPixel, viewPixelFrame.topLeft.y + stripLowOffset, stripLowSize, resources.rulerLinePixel);
                runningPixel += innerSlicesDist;
                DrawVLine(runningPixel, viewPixelFrame.topLeft.y + stripMidOffset, stripMidSize, resources.rulerLinePixel);
                runningPixel += innerSlicesDist;
                DrawVLine(runningPixel, viewPixelFrame.topLeft.y + stripLowOffset, stripLowSize, resources.rulerLinePixel);

                // Move to next segment
                runningUnit += segmentUnitWidth;
                runningPixel = utils.GetWorldToScreenPixelCoord(new Vector3(runningUnit, viewUnitFrame.topLeft.y)).x;
            }
        }
        void CompleteGuideCreation()
        {
            if (creatingHGuide)
            {
                if (state.snapGuideToInt)
                {
                    int contextY = Mathf.RoundToInt(utils.GetWorldToContextY(liveGuide.y));
                    liveGuide.y = utils.GetContextToWorldY(contextY);
                }

                // pure zero is reserved for logical testing
                if (liveGuide.y == 0)
                {
                    liveGuide.y = Globals.FALSE_ZERO;
                }

                state.hGuides.Add(liveGuide.y.ToString());
            }
            else
            {
                if (state.snapGuideToInt)
                {
                    int contextX = Mathf.RoundToInt(utils.GetWorldToContextX(liveGuide.x));
                    liveGuide.x = utils.GetContextToWorldX(contextX);
                }

                // pure zero is reserved for logical testing
                if (liveGuide.x == 0)
                {
                    liveGuide.x = Globals.FALSE_ZERO;
                }

                state.vGuides.Add(liveGuide.x.ToString());
            }

            liveGuide           = Vector2.zero;
            creatingHGuide      = false;
            creatingVGuide      = false;
            state.displayGuides = true;
            utils.RepaintEditorWindow();
        }
Beispiel #4
0
        public void DrawCoords()
        {
            drawing.BeginGUIArea(displayCoordXOffset, displayCoordYOffset, viewPixelFrame.width, viewPixelFrame.height);
            drawing.BeginGUIVertical();

            if (measure.IsMeasureToolActive())
            {
                ExecDrawMeasureAlert();
            }

            if (state.displayCoords)
            {
                List <Transform> transforms = R2DC_Selection.Instance.GetSelection();
                for (int i = 0; i < transforms.Count; i++)
                {
                    Transform transform = transforms[i];

                    if (transform == null)
                    {
                        // selection must be dirty
                        R2DC_Selection.Instance.UpdateSelection();
                        return;
                    }

                    ExecDrawCoord(transform.name, transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
                }
            }

            // live guides
            Vector2 liveGuide = guides.liveGuide;

            if (liveGuide.x != 0)
            {
                float x = utils.GetWorldToContextX(liveGuide.x);
                if (state.snapGuideToInt)
                {
                    x = Mathf.RoundToInt(x);
                }
                ExecDrawCoord(R2DD_Lang.guide, x, 0, 0);
            }
            else if (liveGuide.y != 0)
            {
                float y = utils.GetWorldToContextY(liveGuide.y);
                if (state.snapGuideToInt)
                {
                    y = Mathf.RoundToInt(y);
                }
                ExecDrawCoord(R2DD_Lang.guide, 0, y, 0);
            }
            else
            {
                // hover guides
                Vector2 hoverGuide = guides.hoverGuide;
                if (hoverGuide.x != 0)
                {
                    float x = utils.GetWorldToContextX(hoverGuide.x);
                    if (x == Globals.FALSE_ZERO)
                    {
                        x = 0;
                    }
                    ExecDrawCoord(R2DD_Lang.guide, x, 0, 0);
                }
                else if (hoverGuide.y != 0)
                {
                    float y = utils.GetWorldToContextY(hoverGuide.y);
                    if (y == Globals.FALSE_ZERO)
                    {
                        y = 0;
                    }
                    ExecDrawCoord(R2DD_Lang.guide, 0, y, 0);
                }
            }

            drawing.EndGUIVertical();
            drawing.EndGUIArea();
        }