public bool TryGetStyleFromPrefix(string prefix, out HierarchyStyle style) { if (Count == 0) { style = null; return(false); } if (prefix.Contains(" ")) { prefix = prefix.TrimStart().Split(' ')[0]; } for (int i = 0; i < styles.Count; i++) { style = styles[i]; if (prefix.Equals(style.prefix)) { return(true); } } style = null; return(false); }
private static void DrawLineStyle(Rect selectionRect, HierarchyStyle style) { var setting = style.GetCurrentSettings(); switch (setting.displayedLine) { case LineStyle.NONE: break; case LineStyle.TOP: CreateLineSpacer(selectionRect, setting.lineColor); break; case LineStyle.BOTTOM: selectionRect.y += EditorGUIUtility.singleLineHeight * 0.85f; CreateLineSpacer(selectionRect, setting.lineColor); break; case LineStyle.BOTH: CreateLineSpacer(selectionRect, setting.lineColor); selectionRect.y += EditorGUIUtility.singleLineHeight * 0.85f; CreateLineSpacer(selectionRect, setting.lineColor); break; } }
public static void DrawHierarchyStyle(HierarchyStyle style, Rect styleRect, Rect labelRect, string label, bool removePrefix = true) { if (removePrefix) { label = label.Substring(style.prefix.Length).Trim(); } ModeOptions styleSetting = style.GetCurrentMode(EditorGUIUtility.isProSkin); EditorGUI.DrawRect(styleRect, styleSetting.backgroundColour); EditorGUI.LabelField(labelRect, label.ToUpper(), style.style); }
private static void TogglePrefix(GameObject gameObject, HierarchyStyle style) { string str = gameObject.name; if (str.StartsWith(style.prefix)) { str = RemoveAllPrefixesFromString(str); } else { str = $"{style.prefix} {RemoveAllPrefixesFromString (str)}"; } gameObject.name = str; }
private static void ApplyElementStyle(Rect selectionRect, string name, HierarchyStyle prefix) { var styleSetting = prefix.GetCurrentSettings(); name = RemovePrefix(name, prefix.prefix); //Setup style Color backgroundColor = styleSetting.backgroundColor; Color fontCol = styleSetting.fontColor; //Create style to draw GUIStyle style = new GUIStyle(settings.GetGUIStyle(prefix.guiStyle)) { alignment = styleSetting.fontAlignment, fontSize = styleSetting.fontSize, fontStyle = styleSetting.fontStyle, font = styleSetting.font ?? EditorStyles.standardFont, }; style.normal.textColor = fontCol; Rect backgroundRect = GetActualHierarchyWidth(selectionRect); Rect labelRect = selectionRect = GetHierarchyStyleSize(selectionRect); if (currentInstance.gameObject.transform.parent != null) { backgroundRect = selectionRect; labelRect = selectionRect; } //Draw background and label EditorGUI.DrawRect(backgroundRect, backgroundColor); //Draw twice to take into account full width draw //TODO: Consider looking into content offset, draw texture may be a future option EditorGUI.LabelField(GetActualHierarchyWidth(selectionRect), "", style); EditorGUI.LabelField(labelRect, name.ToUpper(), style); //Apply overlay line DrawLineStyle(backgroundRect, prefix); }