public static void ConvertRectWithAlign(ref Rect rect, DrawAlign align) { switch (align) { case DrawAlign.TOPLEFT: { rect.x += rect.width / 2; rect.y += rect.height / 2; }; break; case DrawAlign.TOP: { rect.y += rect.height / 2; }; break; case DrawAlign.TOPRIGHT: { rect.x -= rect.width / 2; rect.y += rect.height / 2; }; break; case DrawAlign.LEFT: { rect.x += rect.width / 2; }; break; case DrawAlign.CENTER: { // 什么都不做 }; break; case DrawAlign.RIGHT: { rect.x -= rect.width / 2; }; break; case DrawAlign.BOTTOM: { rect.y -= rect.height / 2; }; break; case DrawAlign.BOTTOMLEFT: { rect.x += rect.width / 2; rect.y -= rect.height / 2; }; break; case DrawAlign.BOTTOMRIGHT: { rect.x -= rect.width / 2; rect.y -= rect.height / 2; }; break; } }
public static void DrawLabel(Vector2 pos, string lb, Color color, DrawAlign align = DrawAlign.CENTER, bool shadow = false) { Vector2 size = EditorUtil.GetStringSize(lb); tmpRect.width = size.x; tmpRect.height = size.y; tmpRect.center = pos; ConvertRectWithAlign(ref tmpRect, align); if (shadow) { using (new GUIColor(Color.black)) { tmpRect.center += Vector2.one; GUI.Label(tmpRect, lb); tmpRect.center -= Vector2.one; } } using (new GUIColor(color)) { GUI.Label(tmpRect, lb); } }
internal void DrawBorderAlign(DrawAlign Align) { this.DrawType = Align; havetoDrawBorder = true; this.Invalidate(); }
public static void DrawTexture(Vector2 pos, int width, int height, Texture2D tex, Rect tile, Color color, DrawAlign align = DrawAlign.CENTER) { tmpRect.width = width; tmpRect.height = height; tmpRect.center = pos; ConvertRectWithAlign(ref tmpRect, align); using (new GUIColor(color)) { GUI.DrawTextureWithTexCoords(tmpRect, tex, tile, true); } }