public void Begin(Rect zoomRect)
        {
            // Ends group that Unity implicity begins for every editor window
            zoomAreaRect = zoomRect;
            GUI.EndGroup();


            Vector2 offset = GetContentOffset();

            //float xFactor = offset.x / bgTexture.width;
            //float yFactor = offset.y / bgTexture.height;

            //GUI.DrawTextureWithTexCoords(zoomAreaRect, bgTexture, // texcoords are between 0 and 1! 1 == fullwrap!
            //	new Rect(xFactor, -yFactor, zoomAreaRect.width / (bgTexture.width * zoomScale),
            //		zoomAreaRect.height / (bgTexture.height * zoomScale)));

            GraphBackground.DrawGraphBackground(zoomAreaRect, -offset, zoomScale);


            Rect clippedArea = ScaleSizeBy(zoomAreaRect, 1.0f / zoomScale, new Vector2(zoomAreaRect.xMin, zoomAreaRect.yMin));

            GUI.BeginGroup(clippedArea);

            prevGUIMatrix = GUI.matrix;

            Matrix4x4 translation = Matrix4x4.TRS(
                new Vector2(clippedArea.xMin, clippedArea.yMin), Quaternion.identity, Vector3.one);
            Matrix4x4 scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1f));

            GUI.matrix = translation * scale * translation.inverse * GUI.matrix;
        }
Beispiel #2
0
    public override void DrawPreview(Rect rect)
    {
        GUIStyle style = new GUIStyle(GUI.skin.label)
        {
            fontSize  = 12,
            alignment = TextAnchor.MiddleCenter
        };

        rect = GetCenteredRect(rect);

        // Draw background of the rect we plot points in
        GraphBackground.DrawGraphBackground(rect, rect);
        //EditorGUI.DrawRect(rect, new Color(0.9f, 0.9f, 0.9f));

        float dotSize     = 15; // size in pixels of the point we draw
        float halfDotSize = dotSize * 0.5f;

        float viewportSize = 5; // size of our viewport in Units

        // a value of 10 means we can display any vector from -5,-5 to 5,5 within our rect.
        // change this value for your needs

        for (int i = 0; i < Pattern.arraySize; i++)
        {
            SerializedProperty vectorProperty = Pattern.GetArrayElementAtIndex(i);

            Vector2 vector             = new Vector2(vectorProperty.vector2Value.x, vectorProperty.vector2Value.y);
            Vector2 normalizedPosition = vector / new Vector2(viewportSize, -viewportSize);

            if (Mathf.Abs(normalizedPosition.x) > 0.5f || Mathf.Abs(normalizedPosition.y) > 0.5f)
            {
                // don't draw points outside our viewport
                continue;
            }

            float   l           = (float)i / (float)Pattern.arraySize;
            Color32 lerpedColor = Color32.Lerp(low, high, l);

            Vector2 pixelPosition = rect.center + rect.size * normalizedPosition;
            EditorGUI.DrawRect(new Rect(pixelPosition.x - halfDotSize, pixelPosition.y - halfDotSize, dotSize, dotSize), lerpedColor);
            EditorGUI.LabelField(new Rect(pixelPosition.x - halfDotSize, pixelPosition.y - halfDotSize, dotSize, dotSize), i.ToString(), style);
        }
    }