private static Rect DrawIcon(GameObject gameObject, Rect rect) { var contentRect = rect; contentRect.width = Style.minWidth; #if UNITY_2018_1_OR_NEWER contentRect.x = rect.xMax - contentRect.width; #else contentRect.x = rect.xMax; #endif //draw hierarchy background if (Event.current.type == EventType.Repaint) { Style.backgroundStyle.Draw(contentRect, false, false, false, false); } //get specific icon for this gameObject var content = EditorGuiUtility.GetObjectContent(gameObject, typeof(GameObject)); if (content.image) { //draw the specific icon GUI.Label(contentRect, content.image); } return(contentRect); }
/// <summary> /// Draws GameObject's as header. Creates separation lines and a proper background. /// </summary> /// <param name="gameObject"></param> /// <param name="rect"></param> /// <param name="label"></param> /// <param name="index"></param> private static void DrawHeaderItemLabel(GameObject gameObject, Rect rect, string label, int index = 0) { //repaint background on proper event if (Event.current.type == EventType.Repaint) { Style.backgroundStyle.Draw(rect, false, false, false, false); } if (index > 0) { EditorGUI.DrawRect(new Rect(rect.x, rect.y - Style.lineWidth, rect.width, Style.lineWidth), Style.lineColor); } EditorGUI.DrawRect(new Rect(rect.xMax, rect.y, Style.lineWidth, rect.height), Style.lineColor); EditorGUI.DrawRect(new Rect(rect.xMin, rect.y, Style.lineWidth, rect.height), Style.lineColor); //try to retrive a content for the provided GameObject var iconContent = EditorGuiUtility.GetObjectContent(gameObject, typeof(GameObject)); //prepare content for the associated (fixed) label var itemContent = new GUIContent(label, iconContent.image); //draw a custom label field for the provided GameObject EditorGUI.LabelField(rect, itemContent, Style.headerLabelStyle); EditorGUI.DrawRect(new Rect(rect.x, rect.y + rect.height - Style.lineWidth, rect.width, Style.lineWidth), Style.lineColor); }