// draw the node widget (the icon sprite makes this complicated) public static Rect DrawSpriteContent(string label, Sprite icon, EntityDrawContext drawContext) { var labelContent = new GUIContent(label); // fall back to the default widget where there's no icon or the user wants cirles if (icon == null || drawContext.widgetType == EntityWidgetType.Circle) { return(DrawUtil.DrawContent(labelContent, drawContext)); } // calculate layout for icon and label, then draw them var iconExtents = new Vector2(25, 25); var padding = new Vector2(4, 4); var contentExtents = drawContext.style.contentStyle.CalcSize(labelContent); var widgetExtents = new Vector2(3 * padding.x + iconExtents.x + contentExtents.x, 2 * padding.y + iconExtents.y); var widgetRect = Util.CenterRect(drawContext.position, widgetExtents); // draw the widget outer box DrawUtil.DrawBoxAndBackground(widgetRect, drawContext); // draw the icon var iconOrigin = widgetRect.GetOrigin() + padding; DrawTextureGUI(iconOrigin, icon, iconExtents); // draw the label var contentRectOrigin = new Vector2 ( widgetRect.xMin + 2 * padding.x + iconExtents.x, widgetRect.yMin + (widgetExtents.y - contentExtents.y) / 2); var contentRect = new Rect(contentRectOrigin.x, contentRectOrigin.y, contentExtents.x, contentExtents.y); GUI.Label(contentRect, labelContent, drawContext.style.contentStyle); return(widgetRect); }
} // do nothing #endregion #region content drawing // DrawContent is responsible for rendering entity information // it returns the Rect that it filled public virtual Rect DrawContent(T entity, EntityDrawContext drawContext) { return(DrawUtil.DrawContent(GetContent(entity), drawContext)); }
// DrawContent is responsible for rendering entity information // it returns the Rect that it filled public virtual Rect DrawContent(T entity, EntityDrawContext drawContext) { return(DrawUtil.DrawContent(new GUIContent(entity.name), drawContext)); }