private void DrawTwoToneContent(Rect rect, GameObject instance, Settings _settings) { Rect twoToneRect = GetActualHierarchyWidth(rect); Handles.DrawSolidRectangleWithOutline(twoToneRect, HierarchyGUI.GetTwoToneColour(instanceIndex), Color.clear); HierarchyGUI.DrawStandardContent(rect, instance); if (!instance.activeInHierarchy) { Handles.DrawSolidRectangleWithOutline(twoToneRect, Constants.InactiveColour, Constants.InactiveColour); } }
protected override void DrawInternal(Rect rect, GameObject instance, Settings settings) { currentTransform = instance.transform; // We've went back to the start if (firstTransform == currentTransform) { // Safe to assume the previous instance was the final finalTransform = previousTransform; // Find all invalid keys... //... remove all of them List <int> invalidKeys = new List <int> (); foreach (var key in foldoutCache.Keys) { if (!validFoldoutCache.Contains(key)) { invalidKeys.Add(key); } } for (int i = 0; i < invalidKeys.Count; i++) { foldoutCache.Remove(invalidKeys[i]); } // Clear the valid cache for the next check validFoldoutCache.Clear(); } // First transform will have the lowest index and no parent if (currentTransform.parent == null && currentTransform.GetSiblingIndex() == 0) { firstTransform = currentTransform; instanceIndex = 0; } // Draw previous transform if (previousTransform != null) { int previousInstanceID = previousTransform.GetInstanceID(); if (previousNeedsFoldout) { foldoutCache[previousInstanceID] = currentTransform.parent == previousTransform; } else if (foldoutCache.ContainsKey(previousInstanceID)) { foldoutCache.Remove(previousInstanceID); } } // Draw style, and then drawn selection on top int instanceID = currentTransform.GetInstanceID(); bool hasChildren = currentTransform.childCount > 0; bool hasStyle = settings.globalData.twoToneBackground; // Only draw the two tone background if there's no style override if (settings.globalData.twoToneBackground) { DrawTwoToneContent(rect, instance, settings); DrawSelection(rect, instanceID); hasStyle = true; } // Draw the style if one is to be applied // Have to make sure selection colours are drawn on top when required too if (settings.styleData.TryGetStyleFromPrefix(instance.name, out HierarchyStyle prefix)) { Rect styleRect = (instance.transform.parent != null) ? rect : GetActualHierarchyWidth(rect); HierarchyGUI.DrawHierarchyStyle(prefix, styleRect, rect, instance.name); DrawSelection(rect, instanceID); hasStyle = true; } // Cache values for next instance previousRect = rect; previousTransform = currentTransform; previousNeedsFoldout = hasStyle && hasChildren; // Draw foldout on top if required if (previousNeedsFoldout) { if (foldoutCache.ContainsKey(instanceID)) { DrawFoldout(rect, foldoutCache[instanceID]); } else { foldoutCache.Add(instanceID, false); } validFoldoutCache.Add(instanceID); } instanceIndex++; }
private void DrawStyleElements(Rect rect, int index, bool isActive, bool isFocused) { rect.x += 3f; rect.width -= 3f; if (index >= serializedStyles.arraySize) { return; } SerializedProperty style = serializedStyles.GetArrayElementAtIndex(index); SerializedProperty nameProp = style.FindPropertyRelative("name"); Rect removeRect = rect; removeRect.x = removeRect.width + 6f; removeRect.width = 48f; removeRect.height = 18f; if (GUI.Button(removeRect, "Delete", EditorStyles.centeredGreyMiniLabel)) { serializedStyles.DeleteArrayElementAtIndex(index); serializedSettings.ApplyModifiedProperties(); serializedSettings.Update(); return; } rect.y--; Rect foldoutRect = GetFoldoutRect(rect); Rect labelRect = GetStyleLabelRect(rect); Rect styleRect = GetStyleRect(rect); EditorGUI.BeginChangeCheck(); { HierarchyGUI.DrawHierarchyStyle(settings.styleData[index], styleRect, labelRect, nameProp.stringValue, false); // Use GUI over EditorGUI due to overlapping on draggable style.isExpanded = GUI.Toggle(foldoutRect, style.isExpanded, "", EditorStyles.foldout); Rect propertyRect = GetStylePropertyRect(rect); if (style.isExpanded) { Rect box = propertyRect; box.height -= 18f; box.x = styleRect.x; box.width = styleRect.width; box.y -= 3f; GUI.Box(box, ""); var customDraws = new Dictionary <string, Action <Rect, SerializedProperty> > () { { "modes", DrawModes } }; SerializedPropertyUtility.DrawChildrenProperties(propertyRect, style, style.isExpanded, customDraws); } } if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); serializedSettings.Update(); settings.styleData[index].UpdateStyle(EditorGUIUtility.isProSkin); } }