/// <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); }
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); }
static Style() { normalLabelStyle = new GUIStyle(EditorStyles.miniLabel) { #if UNITY_2019_3_OR_NEWER fontSize = 9 #else fontSize = 8 #endif }; layerLabelStyle = new GUIStyle(EditorStyles.miniLabel) { #if UNITY_2019_3_OR_NEWER fontSize = 9, #else fontSize = 8, #endif #if UNITY_2019_3_OR_NEWER alignment = TextAnchor.MiddleCenter #else alignment = TextAnchor.UpperCenter #endif }; remarkLabelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel); headerLabelStyle = new GUIStyle(EditorStyles.boldLabel) { alignment = TextAnchor.MiddleCenter }; selectLabelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleRight, contentOffset = new Vector2() { x = -2.0f } }; backgroundStyle = new GUIStyle(); backgroundStyle.normal.background = EditorGuiUtility.CreateColorTexture(labelColor); componentIcon = EditorGUIUtility.IconContent("cs Script Icon").image; transformIcon = EditorGUIUtility.IconContent("Transform Icon").image; } } }
static Style() { headerLabelStyle = new GUIStyle(EditorStyles.boldLabel) { alignment = TextAnchor.MiddleCenter }; remarkLabelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel); selectLabelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleRight, contentOffset = new Vector2() { x = -2.0f } }; backgroundStyle = new GUIStyle(); backgroundStyle.normal.background = EditorGuiUtility.CreateColorTexture(labelColor); }