Пример #1
0
        /// <summary>
        /// Easily draws a zoomable and pannable canvas in one call. Includes styling options.
        /// </summary>
        public static void Canvas(this HUMEditor.Data.Immediate immediate, float zoom, Vector2 panOffset, HUMEditor.CanvasStyle canvasStyle = null)
        {
            var style = canvasStyle;
            var rect  = immediate.rect;

            if (style == null)
            {
                style = HUMEditor.CanvasStyle.Create();
            }

            Vector2   center   = rect.size / 2f;
            Texture2D gridTex  = style.mainTexure;
            Texture2D crossTex = style.secondaryTexture;

            if (gridTex != null && crossTex != null)
            {
                // Offset from origin in tile units
                float xOffset = -(center.x * zoom + panOffset.x) / gridTex.width;
                float yOffset = ((center.y - rect.size.y) * zoom + panOffset.y) / gridTex.height;

                Vector2 tileOffset = new Vector2(xOffset, yOffset);

                // Amount of tiles
                float tileAmountX = Mathf.Round(rect.size.x * zoom) / gridTex.width;
                float tileAmountY = Mathf.Round(rect.size.y * zoom) / gridTex.height;

                Vector2 tileAmount = new Vector2(tileAmountX, tileAmountY);

                // Draw tiled background
                GUI.DrawTextureWithTexCoords(rect, gridTex, new Rect(tileOffset, tileAmount));
                GUI.DrawTextureWithTexCoords(rect, crossTex, new Rect(tileOffset + new Vector2(0.5f, 0.5f), tileAmount));
            }
        }
Пример #2
0
 public static HUMEditor.CanvasStyle LineColor(this HUMEditor.CanvasStyle style, Color color)
 {
     style.lineColor        = color;
     style.secondaryTexture = GenerateSecondaryTexture(color);
     return(style);
 }
Пример #3
0
 public static HUMEditor.CanvasStyle BackgroundColor(this HUMEditor.CanvasStyle style, Color color)
 {
     style.backgroundColor = color;
     style.mainTexure      = GenerateMainTexture(style.lineColor, color);
     return(style);
 }
Пример #4
0
 public static HUMEditor.CanvasStyle Spacing(this HUMEditor.CanvasStyle style, int x = 60, int y = 60)
 {
     style.spacing = new Vector2(x, y);
     return(style);
 }