public static GUIStyle GetHierarchyLabelStyle(GameObject go) { using (ProfilerSample.Get()) { if (!go) { return(EditorStyles.label); } var active = go.activeInHierarchy; #if UNITY_2018_3_OR_NEWER var prefabType = PrefabUtility.GetPrefabInstanceStatus(go); switch (prefabType) { case PrefabInstanceStatus.Connected: return(active ? Styles.labelPrefab : Styles.labelPrefabDisabled); case PrefabInstanceStatus.MissingAsset: return(active ? Styles.labelPrefabBroken : Styles.labelPrefabBrokenDisabled); default: return(active ? Styles.labelNormal : Styles.labelDisabled); } #else var prefabType = PrefabUtility.GetPrefabType(PrefabUtility.FindPrefabRoot(go)); switch (prefabType) { case PrefabType.PrefabInstance: case PrefabType.ModelPrefabInstance: return(active ? Styles.labelPrefab : Styles.labelPrefabDisabled); case PrefabType.MissingPrefabInstance: return(active ? Styles.labelPrefabBroken : Styles.labelPrefabBrokenDisabled); default: return(active ? Styles.labelNormal : Styles.labelDisabled); } #endif } }
private static float DoTrailing() { if (!IsRepaintEvent || !Preferences.Trailing || !IsGameObject) { return(RawRect.xMax); } using (ProfilerSample.Get()) { var size = LabelSize; // CurrentStyle.CalcSize(Utility.GetTempGUIContent(GameObjectName)).x; var iconsWidth = RightIconsWidth + LeftIconsWidth + CalcMiniLabelSize() + Preferences.RightMargin; var iconsMin = FullSizeRect.xMax - iconsWidth; var labelMax = LabelOnlyRect.xMax; var overlapping = iconsMin <= labelMax; if (!overlapping) { return(labelMax); } var rect = FullSizeRect; rect.xMin = iconsMin - 18; rect.xMax = labelMax; if (Selection.gameObjects.Contains(CurrentGameObject)) { EditorGUI.DrawRect(rect, Reflected.HierarchyFocused ? Styles.selectedFocusedColor : Styles.selectedUnfocusedColor); } else { EditorGUI.DrawRect(rect, Styles.normalColor); } rect.y++; using (new GUIColor(CurrentColor)) EditorStyles.boldLabel.Draw(rect, trailingContent, 0); return(iconsMin); } }
public static void LockObject(GameObject go) { using (ProfilerSample.Get()) { go.hideFlags |= HideFlags.NotEditable; if (!Preferences.AllowSelectingLockedSceneView) { foreach (var comp in go.GetComponents <Component>()) { if (comp && !(comp is Transform)) { comp.hideFlags |= HideFlags.NotEditable; comp.hideFlags |= HideFlags.HideInHierarchy; } } } EditorUtility.SetDirty(go); } }
public static GUIStyle CreateStyleFromTextures(GUIStyle reference, Texture2D on, Texture2D off) { using (ProfilerSample.Get()) { var style = reference != null ? new GUIStyle(reference) : new GUIStyle(); style.active.background = off; style.focused.background = off; style.hover.background = off; style.normal.background = off; style.onActive.background = on; style.onFocused.background = on; style.onHover.background = on; style.onNormal.background = on; style.imagePosition = ImagePosition.ImageOnly; style.fixedHeight = 15f; style.fixedWidth = 15f; return(style); } }
public static Texture2D FindTextureFromName(string name) { using (ProfilerSample.Get()) try { var textures = Resources.FindObjectsOfTypeAll <Texture2D>(); for (var i = 0; i < textures.Length; i++) { if (textures[i].name == name) { return(textures[i]); } } return(null); } catch (Exception e) { Debug.LogErrorFormat("Failed to find texture \"{0}\": {1}", name, e); return(null); } }
public static void ShowIconSelector(Object[] targetObjs, Rect activatorRect, bool showLabelIcons) { using (ProfilerSample.Get()) try { var iconSelectorType = ReflectionHelper.FindType("UnityEditor.IconSelector"); if (iconSelectorType.HasMethod <Object[], Rect, bool>("ShowAtPosition")) { if (!iconSelectorType.InvokeStaticMethod <bool, Object[], Rect, bool>("ShowAtPosition", targetObjs, activatorRect, showLabelIcons)) { Debug.LogWarning("Failed to open icon selector"); } return; } else { var instance = ScriptableObject.CreateInstance(iconSelectorType); if (instance.HasMethod <Object[], Rect, bool>("Init")) { instance.InvokeMethod("Init", targetObjs, activatorRect, showLabelIcons); } else { var affectedObj = targetObjs.FirstOrDefault(); instance.InvokeMethod("Init", affectedObj, activatorRect, showLabelIcons); After.Condition(() => !instance, () => { var icon = GetObjectIcon(affectedObj); foreach (var obj in targetObjs) { SetObjectIcon(obj, icon); } }); } } } catch (Exception e) { Debug.LogWarning("Failed to open icon selector\n" + e); } }
private static void DrawLeftSideIcons(Rect rect) { if (!IsGameObject || LeftIconsWidth == 0f) { return; } using (ProfilerSample.Get()) { rect.xMin += LabelSize; rect.xMin = Math.Min(rect.xMax - RightIconsWidth - LeftIconsWidth - CalcMiniLabelSize() - 5f - Preferences.RightMargin, rect.xMin); for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++) { var icon = Preferences.LeftIcons.Value[i]; rect.xMax = rect.xMin + icon.SafeGetWidth(); icon.SafeDoGUI(rect); rect.xMin = rect.xMax; } } }
private static float CalcMiniLabelSize() { Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9; using (ProfilerSample.Get()) { switch (MiniLabelProviders.Length) { case 0: return(0f); case 1: return(MiniLabelProviders[0].Measure()); default: return(Math.Max( MiniLabelProviders[0].Measure(), MiniLabelProviders[1].Measure() )); } } }
public static void ShowIconSelector(Object targetObj, Rect activatorRect, bool showLabelIcons, OnObjectIconChange onObjectChange) { using (ProfilerSample.Get()) try { var instance = ScriptableObject.CreateInstance(iconSelectorType); var update = new EditorApplication.CallbackFunction(() => { }); iconSelectorInitMethod.Invoke(instance, new object[] { targetObj, activatorRect, showLabelIcons }); update += () => { if (!instance) { onObjectChange(GetObjectIcon(targetObj)); EditorApplication.update -= update; } }; EditorApplication.update += update; } catch (Exception e) { Debug.LogWarning("Failed to open icon selector\n" + e); } }
public void Draw(ref Rect rect) { if (!HasValue()) { return; } var color = EnhancedHierarchy.CurrentColor; var alpha = Faded() ? Styles.backgroundColorDisabled.a : Styles.backgroundColorEnabled.a; var finalColor = color * new Color(1f, 1f, 1f, alpha); using (ProfilerSample.Get()) using (new GUIContentColor(finalColor)) { Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9; rect.xMin -= Measure(); if (Draw(rect, content, Styles.miniLabelStyle)) { OnClick(); } } }
private static float DoTrailing(Rect rect) { if (!IsRepaintEvent || !Preferences.Trailing || !IsGameObject) { return(rect.xMax); } using (ProfilerSample.Get()) { tempGameObjectNameContent.text = CurrentGameObject.name; var size = CurrentStyle.CalcSize(tempGameObjectNameContent); var iconsWidth = RightIconsWidth + LeftIconsWidth + CalcMiniLabelSize() + Preferences.Offset; if (size.x < rect.width - iconsWidth + 15f) { return(rect.xMax); } rect.yMin += 2f; rect.xMin = rect.xMax - iconsWidth - 18f; if (Selection.gameObjects.Contains(CurrentGameObject)) { EditorGUI.DrawRect(rect, ReflectionHelper.HierarchyFocused ? Styles.selectedFocusedColor : Styles.selectedUnfocusedColor); } else { EditorGUI.DrawRect(rect, Styles.normalColor); } rect.x -= 16f; rect.yMin -= 1f; rect.yMax -= 3f; EditorGUI.LabelField(rect, trailingContent, CurrentStyle); return(rect.xMin + 28f); } }
public static void EnableFPSCounter() { var frames = 0; var fps = 0d; var lastTime = 0d; var content = new GUIContent(); var evt = EventType.Repaint; EditorApplication.hierarchyWindowItemOnGUI += (id, rect) => { using (ProfilerSample.Get("Enhanced Hierarchy")) using (ProfilerSample.Get("FPS Counter")) { if (evt == Event.current.type) { return; } evt = Event.current.type; if (evt == EventType.Repaint) { frames++; } if (EditorApplication.timeSinceStartup - lastTime < 0.5d) { return; } fps = frames / (EditorApplication.timeSinceStartup - lastTime); lastTime = EditorApplication.timeSinceStartup; frames = 0; content.text = string.Format("{0:00.0} FPS", fps); content.image = Styles.warningIcon; SetHierarchyTitle(content); } }; }
private static void LayerMiniLabel(ref Rect rect) { if (Event.current.type == EventType.Layout) { return; } using (ProfilerSample.Get()) using (new GUIContentColor(CurrentColor * new Color(1f, 1f, 1f, CurrentGameObject.layer == UNLAYERED ? Styles.backgroundColorDisabled.a : Styles.backgroundColorEnabled.a))) { GUI.changed = false; Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9; rect.xMin -= Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(LayerMask.LayerToName(CurrentGameObject.layer))).x; var layer = EditorGUI.LayerField(rect, CurrentGameObject.layer, Styles.miniLabelStyle); if (GUI.changed) { Icons.Layer.ChangeLayerAndAskForChildren(GetSelectedObjectsAndCurrent(), layer); } } }
private static void CalculateIconsWidth() { using (ProfilerSample.Get()) { LeftIconsWidth = 0f; RightIconsWidth = 0f; if (!IsGameObject || !IsRepaintEvent) { return; } foreach (var icon in Preferences.RightIcons.Value) { RightIconsWidth += icon.Width; } foreach (var icon in Preferences.LeftIcons.Value) { LeftIconsWidth += icon.Width; } } }
private static void CalculateIconsWidth() { using (ProfilerSample.Get()) { LeftIconsWidth = 0f; RightIconsWidth = 0f; if (!IsGameObject || !IsRepaintEvent) { return; } for (var i = 0; i < Preferences.RightIcons.Value.Count; i++) { RightIconsWidth += Preferences.RightIcons.Value[i].SafeGetWidth(); } for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++) { LeftIconsWidth += Preferences.LeftIcons.Value[i].SafeGetWidth(); } } }
private static void TagMiniLabel(ref Rect rect) { if (Event.current.type == EventType.Layout) { return; } using (ProfilerSample.Get()) using (new GUIContentColor(CurrentColor * new Color(1f, 1f, 1f, CurrentGameObject.CompareTag(UNTAGGED) ? Styles.backgroundColorDisabled.a : Styles.backgroundColorEnabled.a))) { GUI.changed = false; Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9; rect.xMin -= Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(GameObjectTag)).x; var tag = EditorGUI.TagField(rect, GameObjectTag, Styles.miniLabelStyle); if (GUI.changed) { Icons.Tag.ChangeTagAndAskForChildren(GetSelectedObjectsAndCurrent(), tag); } } }
public static void SetItemInformation(int id, Rect rect) { if (!Preferences.Enabled) { return; } using (ProfilerSample.Get("Enhanced Hierarchy")) using (ProfilerSample.Get()) try { CurrentGameObject = EditorUtility.InstanceIDToObject(id) as GameObject; IsGameObject = CurrentGameObject; IsRepaintEvent = Event.current.type == EventType.Repaint; IsFirstVisible = Event.current.type != LastEventType; LastEventType = Event.current.type; if (IsGameObject) { LabelSize = EditorStyles.label.CalcSize(new GUIContent(CurrentGameObject.name)).x; HasTag = CurrentGameObject.tag != UNTAGGED || !Preferences.HideDefaultTag; HasLayer = CurrentGameObject.layer != UNLAYERED || !Preferences.HideDefaultLayer; CurrentStyle = Utility.GetHierarchyLabelStyle(CurrentGameObject); CurrentColor = CurrentStyle.normal.textColor; MonoBehaviours = CurrentGameObject.GetComponents <MonoBehaviour>(); } if (IsFirstVisible) { FinalRect = RawRect; } RawRect = rect; } catch (Exception e) { Utility.LogException(e); } }
public static bool GetTransformIsExpanded(GameObject go) { using (ProfilerSample.Get()) try { if (treeviewInstance == null) { treeviewInstance = treeviewProp.GetValue(HierarchyWindowInstance, null); treeviewDataSourceInstance = treeviewDataSourceProp.GetValue(treeviewInstance, null); } else if (treeviewDataSourceInstance == null) { treeviewDataSourceInstance = treeviewDataSourceProp.GetValue(treeviewInstance, null); } return((bool)treeviewExpandedMethod.Invoke(treeviewDataSourceInstance, new object[] { go.GetInstanceID() })); } catch (Exception e) { Preferences.NumericChildExpand.Value = false; Utility.LogException(e); Debug.LogWarning(string.Format("Disabled \"{0}\" because it failed to get hierarchy info", Preferences.NumericChildExpand.Content.text)); return(false); } }
private static void DrawHorizontalSeparator(Rect rect) { if (Preferences.LineSize < 1 || Preferences.LineColor.Value.a <= ALPHA_THRESHOLD || !IsRepaintEvent) { return; } using (ProfilerSample.Get()) { rect.xMin = 0f; rect.xMax = rect.xMax + 50f; rect.yMin -= Preferences.LineSize / 2; rect.yMax = rect.yMin + Preferences.LineSize; EditorGUI.DrawRect(rect, Preferences.LineColor); if (!IsFirstVisible) { return; } rect.y = FinalRect.y - Preferences.LineSize / 2; var height = ReflectionHelper.HierarchyWindowInstance.position.height; var count = (height - FinalRect.y) / FinalRect.height; if (FinalRect.height <= 0f) { count = 100f; } for (var i = 0; i < count; i++) { rect.y += RawRect.height; EditorGUI.DrawRect(rect, Preferences.LineColor); } } }
private static void DrawTree(Rect rect) { if (!Preferences.Tree || !IsGameObject || !IsRepaintEvent) { return; } using (ProfilerSample.Get()) using (new GUIColor(CurrentColor)) { rect.xMin -= 14f; rect.xMax = rect.xMin + 14f; if (CurrentGameObject.transform.childCount == 0 && CurrentGameObject.transform.parent) { if (Utility.LastInHierarchy(CurrentGameObject.transform)) { GUI.DrawTexture(rect, Styles.treeEndTexture); } else { GUI.DrawTexture(rect, Styles.treeMiddleTexture); } } var parent = CurrentGameObject.transform.parent; for (rect.x -= 14f; rect.xMin > 0f && parent && parent.parent; rect.x -= 14f) { if (!Utility.LastInHierarchy(parent)) { using (new GUIColor(Utility.GetHierarchyColor(parent.parent))) GUI.DrawTexture(rect, Styles.treeLineTexture); } parent = parent.parent; } } }
public static string EnumFlagsToString(Enum value) { using (ProfilerSample.Get()) try { if ((int)(object)value == -1) { return("Everything"); } var str = new StringBuilder(); var separator = ", "; foreach (var enumValue in Enum.GetValues(value.GetType())) { var i = (int)enumValue; if (i != 0 && (i & (i - 1)) == 0 && Enum.IsDefined(value.GetType(), i) && (Convert.ToInt32(value) & i) != 0) { str.Append(ObjectNames.NicifyVariableName(enumValue.ToString())); str.Append(separator); } } if (str.Length > 0) { str.Length -= separator.Length; } return(str.ToString()); } catch (Exception e) { if (Preferences.DebugEnabled) { Debug.LogException(e); } return(string.Empty); } }
private static void ChildToggle() { using (ProfilerSample.Get()) { if (!Preferences.NumericChildExpand || !IsRepaintEvent || !IsGameObject || CurrentGameObject.transform.childCount <= 0) { return; } var rect = RawRect; var childString = CurrentGameObject.transform.childCount.ToString("00"); var expanded = ReflectionHelper.GetTransformIsExpanded(CurrentGameObject); rect.xMax = rect.xMin - 1f; rect.xMin -= 15f; if (childString.Length > 2) { rect.xMin -= 4f; } using (new GUIBackgroundColor(Styles.childToggleColor)) Styles.newToggleStyle.Draw(rect, Utility.GetTempGUIContent(childString), false, false, expanded, false); } }
public static Texture2D GetObjectIcon(Object obj) { using (ProfilerSample.Get()) return(typeof(EditorGUIUtility).InvokeStaticMethod <Texture2D, Object>("GetIconForObject", obj)); }
private static void DrawTree(Rect rect) { if (Preferences.TreeOpacity <= ALPHA_THRESHOLD || !IsGameObject) { return; } if (!IsRepaintEvent && !Preferences.SelectOnTree) { return; } using (ProfilerSample.Get()) using (new GUIColor(Utility.GetHierarchyColor(CurrentGameObject.transform.parent), Preferences.TreeOpacity)) { var indent = Reflected.HierarchyArea.Supported ? Reflected.HierarchyArea.IndentWidth : 16f; // #42 - Jules: pull back indent one level and neatly align tree lines with expansion arrow tips rect.x -= indent + 2f; rect.xMin -= 14f; rect.xMax = rect.xMin + 14f; // #42 - Jules: allow showing of stems for container objects if (CurrentGameObject.transform.parent) { var lastInHierarchy = Utility.TransformIsLastChild(CurrentGameObject.transform); GUI.DrawTexture(rect, lastInHierarchy ? Styles.treeElbowTexture : Styles.treeTeeTexture); /* #42 - Jules: add short horizontal line to extend stem if there's no expansion triangle. * * NOTE: Please make this value into a slider in the preferences, since it's arguably a bad thing to have it. * It looks "nicer" with extended stems but is less clear since it throws off the stem alignments. * At a value of 1 this can make things look an entire level off of where they truly are relative to other things!!! * I think 0.5 is an okay compromise, but 0 is the most consistent, which means no extra stem line at all. * So it's the sort of thing where people might have different ideas of what's best for them... */ var extendStemProportion = CurrentGameObject.transform.childCount == 0 ? Preferences.TreeStemProportion.Value * indent : indent - 14f; if (extendStemProportion > 0.01f) { var extendedStemRect = new Rect(rect.x + rect.size.x, rect.y + (lastInHierarchy ? 9f : 8f), extendStemProportion, 1f); EditorGUI.DrawRect(extendedStemRect, Color.white); } if (Preferences.SelectOnTree && GUI.Button(rect, GUIContent.none, Styles.labelNormal)) { Selection.activeTransform = CurrentGameObject.transform.parent; } } var currentTransform = CurrentGameObject.transform.parent; for (rect.x -= indent; rect.xMin > 0f && currentTransform && currentTransform.parent; rect.x -= indent) { if (!Utility.TransformIsLastChild(currentTransform)) { using (new GUIColor(Utility.GetHierarchyColor(currentTransform.parent), Preferences.TreeOpacity)) { GUI.DrawTexture(rect, Styles.treeLineTexture); if (Preferences.SelectOnTree && GUI.Button(rect, GUIContent.none, Styles.labelNormal)) { Selection.activeTransform = currentTransform.parent; } } } currentTransform = currentTransform.parent; } } }
public static Texture2D GetObjectIcon(Object obj) { using (ProfilerSample.Get()) return((Texture2D)getIconMethod.Invoke(null, new object[] { obj })); }
private static void DoSelection(Rect rect) { if (!Preferences.EnhancedSelection || Event.current.button != 1) { DragSelection = null; return; } using (ProfilerSample.Get()) { rect.xMin = 0f; switch (Event.current.type) { case EventType.MouseDrag: if (!IsFirstVisible) { return; } if (DragSelection == null) { DragSelection = new List <Object>(); SelectionStart = Event.current.mousePosition; SelectionRect = new Rect(); } SelectionRect = new Rect() { xMin = Mathf.Min(Event.current.mousePosition.x, SelectionStart.x), yMin = Mathf.Min(Event.current.mousePosition.y, SelectionStart.y), xMax = Mathf.Max(Event.current.mousePosition.x, SelectionStart.x), yMax = Mathf.Max(Event.current.mousePosition.y, SelectionStart.y) }; if (Event.current.control || Event.current.command) { DragSelection.AddRange(Selection.objects); } Selection.objects = DragSelection.ToArray(); Event.current.Use(); break; case EventType.MouseUp: if (DragSelection != null) { Event.current.Use(); } DragSelection = null; break; case EventType.Repaint: if (DragSelection == null || !IsFirstVisible) { break; } Rect scrollRect; if (Event.current.mousePosition.y > FinalRect.y) { scrollRect = FinalRect; scrollRect.y += scrollRect.height; } else if (Event.current.mousePosition.y < RawRect.y) { scrollRect = RawRect; scrollRect.y -= scrollRect.height; } else { break; } SelectionRect = new Rect() { xMin = Mathf.Min(scrollRect.xMax, SelectionStart.x), yMin = Mathf.Min(scrollRect.yMax, SelectionStart.y), xMax = Mathf.Max(scrollRect.xMax, SelectionStart.x), yMax = Mathf.Max(scrollRect.yMax, SelectionStart.y) }; if (Event.current.control || Event.current.command) { DragSelection.AddRange(Selection.objects); } Selection.objects = DragSelection.ToArray(); GUI.ScrollTowards(scrollRect, 9f); EditorApplication.RepaintHierarchyWindow(); break; case EventType.Layout: if (DragSelection != null && IsGameObject) { if (!SelectionRect.Overlaps(rect) && DragSelection.Contains(CurrentGameObject)) { DragSelection.Remove(CurrentGameObject); } else if (SelectionRect.Overlaps(rect) && !DragSelection.Contains(CurrentGameObject)) { DragSelection.Add(CurrentGameObject); } } break; } } }
private static float CalcMiniLabelSize() { Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9; using (ProfilerSample.Get()) switch (Preferences.MiniLabel.Value) { case MiniLabelType.Tag: if (HasTag) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(GameObjectTag)).x); } else { return(0f); } case MiniLabelType.Layer: if (HasLayer) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(LayerMask.LayerToName(CurrentGameObject.layer))).x); } else { return(0f); } case MiniLabelType.TagOrLayer: if (HasTag) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(GameObjectTag)).x); } else if (HasLayer) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(LayerMask.LayerToName(CurrentGameObject.layer))).x); } else { return(0f); } case MiniLabelType.LayerOrTag: if (HasLayer) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(LayerMask.LayerToName(CurrentGameObject.layer))).x); } else if (HasTag) { return(Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(GameObjectTag)).x); } else { return(0f); } case MiniLabelType.TagAndLayer: case MiniLabelType.LayerAndTag: var tagSize = 0f; var layerSize = 0f; if (HasTag) { tagSize = Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(GameObjectTag)).x; } if (HasLayer) { layerSize = Styles.miniLabelStyle.CalcSize(Utility.GetTempGUIContent(LayerMask.LayerToName(CurrentGameObject.layer))).x; } return(Mathf.Max(tagSize, layerSize)); default: return(0f); } }
private static void DrawMiniLabel(ref Rect rect) { if (Preferences.MiniLabel.Value == MiniLabelType.None || !IsGameObject) { return; } rect.x -= 3f; using (ProfilerSample.Get()) switch (Preferences.MiniLabel.Value) { case MiniLabelType.Tag: if (HasTag) { TagMiniLabel(ref rect); } break; case MiniLabelType.Layer: if (HasLayer) { LayerMiniLabel(ref rect); } break; case MiniLabelType.TagOrLayer: if (HasTag) { TagMiniLabel(ref rect); } else if (HasLayer) { LayerMiniLabel(ref rect); } break; case MiniLabelType.LayerOrTag: if (HasLayer) { LayerMiniLabel(ref rect); } else if (HasTag) { TagMiniLabel(ref rect); } break; case MiniLabelType.TagAndLayer: if (HasTag && HasLayer || !Preferences.CentralizeMiniLabelWhenPossible) { var topRect = rect; var bottomRect = rect; topRect.yMax = RawRect.yMax - RawRect.height / 2f; bottomRect.yMin = RawRect.yMin + RawRect.height / 2f; if (HasTag) { TagMiniLabel(ref topRect); } if (HasLayer) { LayerMiniLabel(ref bottomRect); } rect.xMin = Mathf.Min(topRect.xMin, bottomRect.xMin); } else if (HasLayer) { LayerMiniLabel(ref rect); } else if (HasTag) { TagMiniLabel(ref rect); } break; case MiniLabelType.LayerAndTag: if (HasTag && HasLayer || !Preferences.CentralizeMiniLabelWhenPossible) { var topRect = rect; var bottomRect = rect; topRect.yMax = RawRect.yMax - RawRect.height / 2f; bottomRect.yMin = RawRect.yMin + RawRect.height / 2f; if (HasLayer) { LayerMiniLabel(ref topRect); } if (HasTag) { TagMiniLabel(ref bottomRect); } rect.xMin = Mathf.Min(topRect.xMin, bottomRect.xMin); } else if (HasLayer) { LayerMiniLabel(ref rect); } else if (HasTag) { TagMiniLabel(ref rect); } break; } }
private static void ColorSort(Rect rect) { if (!IsRepaintEvent) { return; } using (ProfilerSample.Get()) { rect.xMin = 0f; rect.xMax = rect.xMax + 50f; var rowTint = GetRowTint(); var rowCustomTint = GetRowCustomTint(); var rowCustomTintName = GetRowCustomTint_Name(); if (rowCustomTint.color.a > ALPHA_THRESHOLD) { using (new GUIColor(rowCustomTint.color)) { switch (rowCustomTint.mode) { case TintMode.Flat: EditorGUI.DrawRect(rect, Color.white); break; case TintMode.GradientLeftToRight: GUI.DrawTexture(Utility.FlipRectHorizontally(rect), Styles.fadeTexture, ScaleMode.StretchToFill); break; case TintMode.GradientRightToLeft: GUI.DrawTexture(rect, Styles.fadeTexture, ScaleMode.StretchToFill); break; } } } if (rowCustomTintName.color.a > ALPHA_THRESHOLD) { using (new GUIColor(rowCustomTintName.color)) { switch (rowCustomTintName.mode) { case TintMode.Flat: EditorGUI.DrawRect(rect, Color.white); break; case TintMode.GradientLeftToRight: GUI.DrawTexture(Utility.FlipRectHorizontally(rect), Styles.fadeTexture, ScaleMode.StretchToFill); break; case TintMode.GradientRightToLeft: GUI.DrawTexture(rect, Styles.fadeTexture, ScaleMode.StretchToFill); break; } } } if (rowTint.a > ALPHA_THRESHOLD) { EditorGUI.DrawRect(rect, rowTint); } if (!IsFirstVisible) { return; } rect.y = FinalRect.y; var height = Reflected.HierarchyWindowInstance.position.height; var count = (height - FinalRect.y) / FinalRect.height; if (FinalRect.height <= 0f) { count = 100f; } for (var i = 0; i < count; i++) { rect.y += RawRect.height; rowTint = GetRowTint(rect); if (rowTint.a > ALPHA_THRESHOLD) { EditorGUI.DrawRect(rect, rowTint); } } } }
private static void OnItemGUI(int id, Rect rect) { if (!Preferences.Enabled) { return; } using (ProfilerSample.Get("Enhanced Hierarchy")) try { if (IsGameObject) { for (var i = 0; i < Preferences.RightIcons.Value.Count; i++) { Preferences.RightIcons.Value[i].SafeInit(); } for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++) { Preferences.LeftIcons.Value[i].SafeInit(); } Preferences.LeftSideButton.SafeInit(); } if (IsFirstVisible) { try { ReflectionHelper.HierarchyArea.IndentWidth = Preferences.Indent; ReflectionHelper.HierarchyArea.BaseIndent = Preferences.LeftMargin; } catch (Exception e) { if (Preferences.DebugEnabled) { Debug.LogError("Failed to set"); Debug.LogException(e); } } } //SetTitle("EH 2.0"); CalculateIconsWidth(); DoSelection(RawRect); IgnoreLockedSelection(); DrawTree(RawRect); ChildToggle(); var trailingWidth = DoTrailing(RawRect); DrawHover(); ColorSort(RawRect); DrawLeftSideIcons(RawRect); DrawTooltip(RawRect, trailingWidth); if (IsGameObject) { rect.xMax -= Preferences.RightMargin; rect.xMin = rect.xMax; rect.y++; for (var i = 0; i < Preferences.RightIcons.Value.Count; i++) { using (new GUIBackgroundColor(Styles.backgroundColorEnabled)) { var icon = Preferences.RightIcons.Value[i]; rect.xMin -= icon.SafeGetWidth(); icon.SafeDoGUI(rect); rect.xMax -= icon.SafeGetWidth(); } } var leftSideRect = RawRect; if (Preferences.LeftmostButton) { leftSideRect.xMin = 0f; } else { leftSideRect.xMin -= 2f + CurrentGameObject.transform.childCount > 0 || Preferences.TreeOpacity > ALPHA_THRESHOLD ? 30f : 18f; } leftSideRect.xMax = leftSideRect.xMin + Preferences.LeftSideButton.SafeGetWidth(); using (new GUIBackgroundColor(Styles.backgroundColorEnabled)) Preferences.LeftSideButton.SafeDoGUI(leftSideRect); } DrawMiniLabel(ref rect); DrawHorizontalSeparator(RawRect); } catch (Exception e) { Utility.LogException(e); } }