void OnGUI() { if (!ShowBorders || blankTexture == null) { return; } var screenRect = sprite.GetScreenRect(); var borders = sprite.SpriteInfo.border; var x = screenRect.x; var y = screenRect.y; var width = screenRect.width; var height = screenRect.height; var left = borders.left; var right = borders.right; var top = borders.top; var bottom = borders.bottom; if (sprite.Flip.IsSet(dfSpriteFlip.FlipHorizontal)) { left = borders.right; right = borders.left; } if (sprite.Flip.IsSet(dfSpriteFlip.FlipVertical)) { top = borders.bottom; bottom = borders.top; } // NOTE: I've been meaning to add some immediate-mode drawing functions // for things like lines and overlay sprites, but that will have to wait // until V2 for now. // // I could easily have chosen to draw the lines using Sprites, but I // think it's kind of illuminating to show how the code below increases // the draw call currentIndex by 4 just to draw some simple lines using // Unity GUI :) GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); GUI.DrawTexture(new Rect(x - 10, y + top, width + 20, 1), blankTexture); GUI.DrawTexture(new Rect(x - 10, y + height - bottom, width + 20, 1), blankTexture); GUI.DrawTexture(new Rect(x + left, y - 10, 1, height + 20), blankTexture); GUI.DrawTexture(new Rect(x + width - right, y - 10, 1, height + 20), blankTexture); }