private static void ShowItem(ReferencesTreeViewItem <T> item) { var assetPath = item.data.assetPath; if (item.data.assetSettingsKind == AssetSettingsKind.NotSettings) { if (!CSSelectionTools.RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } else { if (!CSEditorTools.RevealInSettings(item.data.assetSettingsKind, assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } }
private static void ShowItem(ReferencesTreeViewItem <T> item, ReferencingEntryData referencingEntry = null) { var assetPath = item.data.assetPath; if (referencingEntry != null) { if (referencingEntry.location == Location.SceneLightingSettings || referencingEntry.location == Location.SceneNavigationSettings) { var sceneOpenResult = CSSceneTools.OpenSceneWithSavePrompt(assetPath); if (!sceneOpenResult.success) { Debug.LogError(Maintainer.ConstructError("Can't open scene " + assetPath)); MaintainerWindow.ShowNotification("Can't show it properly"); return; } } switch (referencingEntry.location) { case Location.ScriptAsset: case Location.ScriptableObjectAsset: if (!CSSelectionTools.RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetObject: if (!CSSelectionTools.RevealAndSelectSubAsset(assetPath, referencingEntry.transformPath, referencingEntry.objectId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetGameObject: case Location.SceneGameObject: if (!CSSelectionTools.RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneLightingSettings: if (!CSMenuTools.ShowSceneSettingsLighting()) { Debug.LogError(Maintainer.ConstructError("Can't open Lighting settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneNavigationSettings: if (!CSMenuTools.ShowSceneSettingsNavigation()) { Debug.LogError(Maintainer.ConstructError("Can't open Navigation settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.NotFound: case Location.Invisible: break; case Location.TileMap: if (!CSSelectionTools.RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } // TODO: open tilemap editor window? break; default: throw new ArgumentOutOfRangeException(); } } else { if (item.data.assetSettingsKind == AssetSettingsKind.NotSettings) { if (!CSSelectionTools.RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } else { if (!CSEditorTools.RevealInSettings(item.data.assetSettingsKind, assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } } }
private void CellGUI(Rect cellRect, ReferencesTreeViewItem <T> item, Columns column, ref RowGUIArgs args) { baseIndent = item.depth * DepthIndentation; //if (!item.data.exactReferencesExpanded) if (item.data.referencingEntries == null) { CenterRectUsingSingleLineHeight(ref cellRect); } else { var lines = 1 + (item.data.referencingEntries != null ? item.data.referencingEntries.Length : 0); var cellHeight = lines * RowHeight; if (cellRect.height > cellHeight) { cellRect.y += (cellRect.height - cellHeight) * 0.5f; cellRect.height = cellHeight; } cellRect.y += MultilineCellYOffset; } switch (column) { case Columns.Path: var iconPadding = !Provider.isActive ? 0 : IconPadding; var entryRect = cellRect; var num = GetContentIndent(item) + extraSpaceBeforeIconAndLabel; entryRect.xMin += num; if (item.icon != null) { var iconRect = entryRect; iconRect.width = IconWidth; iconRect.x += iconPadding; iconRect.height = EditorGUIUtility.singleLineHeight; GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit); // BASED ON DECOMPILED CODE // AssetsTreeViewGUI: // float num = (!Provider.isActive) ? 0f : 7f; // iconRightPadding = num; // iconLeftPadding = num; // TreeViewGUI: // iconTotalPadding = iconLeftPadding + iconRightPadding entryRect.xMin += // TreeViewGUI: public float k_IconWidth = 16f; IconWidth + // TreeViewGUI: iconTotalPadding iconPadding * 2 + // TreeViewGUI: public float k_SpaceBetweenIconAndText = 2f; 2f; } var eyeButtonRect = entryRect; eyeButtonRect.width = EyeButtonSize; eyeButtonRect.height = EyeButtonSize; eyeButtonRect.x += EyeButtonPadding; if (UIHelpers.IconButton(eyeButtonRect, CSIcons.Show)) { ShowItem(item); } var labelRect = entryRect; labelRect.xMin = eyeButtonRect.xMax + EyeButtonPadding; if (item.data.depth == 0 && !item.data.HasChildren) { GUI.contentColor = CSColors.labelDimmedColor; } DefaultGUI.Label(labelRect, args.label, args.selected, args.focused); GUI.contentColor = Color.white; if (/*item.data.exactReferencesExpanded && */ item.data.referencingEntries != null) { var referencingEntriesCount = item.data.referencingEntries.Length; if (referencingEntriesCount > 0) { var warningIconRect = eyeButtonRect; warningIconRect.width = 16; warningIconRect.height = 16; warningIconRect.x += 4; var entriesNotFound = item.data.referencingEntries.All(e => e.location == Location.NotFound); var boxRect = entryRect; boxRect.yMin += RowHeight - 4f; boxRect.height = referencingEntriesCount * RowHeight - 2f; boxRect.xMin = labelRect.xMin - 2f; GUI.backgroundColor = !entriesNotFound ? CSColors.backgroundGreenTint : CSColors.backgroundRedTint; GUI.Box(boxRect, GUIContent.none); GUI.backgroundColor = Color.white; for (var i = 0; i < referencingEntriesCount; i++) { var entry = item.data.referencingEntries[i]; labelRect.y += RowHeight; eyeButtonRect.y += RowHeight; if (entry.location == Location.NotFound) { warningIconRect.y = eyeButtonRect.y; GUI.DrawTexture(warningIconRect, CSEditorIcons.WarnSmallIcon, ScaleMode.ScaleAndCrop); } else if (entry.location == Location.Invisible) { warningIconRect.y = eyeButtonRect.y; GUI.DrawTexture(warningIconRect, CSEditorIcons.InfoSmallIcon, ScaleMode.ScaleAndCrop); } else if (entry.location == Location.ScriptAsset || entry.location == Location.ScriptableObjectAsset) { //labelRect.xMin = eyeButtonRect.xMax + EyeButtonPadding - eyeButtonRect.width; } else { if (UIHelpers.IconButton(eyeButtonRect, CSIcons.Show)) { ShowItem(item, entry); } } var label = entry.GetLabel(); DefaultGUI.Label(labelRect, label, args.selected, args.focused); } } } break; case Columns.Type: DefaultGUI.Label(cellRect, item.data.assetTypeName, args.selected, args.focused); break; case Columns.Size: DefaultGUI.Label(cellRect, item.data.assetSizeFormatted, args.selected, args.focused); break; case Columns.ReferencesCount: DefaultGUI.Label(cellRect, item.data.ChildrenCount.ToString(), args.selected, args.focused); break; default: throw new ArgumentOutOfRangeException("column", column, null); } }
private void CellGUI(Rect cellRect, ReferencesTreeViewItem <T> item, Columns column, ref RowGUIArgs args) { baseIndent = item.depth * DepthIndentation; CenterRectUsingSingleLineHeight(ref cellRect); switch (column) { case Columns.Path: var iconPadding = !Provider.isActive ? 0 : IconPadding; var entryRect = cellRect; var num = GetContentIndent(item) + extraSpaceBeforeIconAndLabel; entryRect.xMin += num; if (item.icon != null) { var iconRect = entryRect; iconRect.width = IconWidth; iconRect.x += iconPadding; iconRect.height = EditorGUIUtility.singleLineHeight; GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit); // BASED ON DECOMPILED CODE // AssetsTreeViewGUI: // float num = (!Provider.isActive) ? 0f : 7f; // iconRightPadding = num; // iconLeftPadding = num; // TreeViewGUI: // iconTotalPadding = iconLeftPadding + iconRightPadding entryRect.xMin += // TreeViewGUI: public float k_IconWidth = 16f; IconWidth + // TreeViewGUI: iconTotalPadding iconPadding * 2 + // TreeViewGUI: public float k_SpaceBetweenIconAndText = 2f; 2f; } Rect lastRect; var eyeButtonRect = entryRect; eyeButtonRect.width = UIHelpers.EyeButtonSize; eyeButtonRect.height = UIHelpers.EyeButtonSize; eyeButtonRect.x += UIHelpers.EyeButtonPadding; lastRect = eyeButtonRect; if (UIHelpers.IconButton(eyeButtonRect, CSIcons.Show)) { ShowItem(item); } if (item.depth == 1 && item.data.isReferenced) { var findButtonRect = entryRect; findButtonRect.width = UIHelpers.EyeButtonSize; findButtonRect.height = UIHelpers.EyeButtonSize; findButtonRect.x += UIHelpers.EyeButtonPadding * 2 + UIHelpers.EyeButtonSize; lastRect = findButtonRect; if (UIHelpers.IconButton(findButtonRect, CSIcons.Find, "Search for references")) { EditorApplication.delayCall += () => ReferencesFinder.FindAssetReferencesFromResults(item.data.assetPath); } } var labelRect = entryRect; labelRect.xMin = lastRect.xMax + UIHelpers.EyeButtonPadding; if (item.data.depth == 0 && !item.data.HasChildren) { GUI.contentColor = CSColors.labelDimmedColor; } DefaultGUI.Label(labelRect, args.label, args.selected, args.focused); GUI.contentColor = Color.white; break; case Columns.Type: DefaultGUI.Label(cellRect, item.data.assetTypeName, args.selected, args.focused); break; case Columns.Size: DefaultGUI.Label(cellRect, item.data.assetSizeFormatted, args.selected, args.focused); break; case Columns.ReferencesCount: if (item.depth == 0) { DefaultGUI.Label(cellRect, item.data.ChildrenCount.ToString(), args.selected, args.focused); } break; default: throw new ArgumentOutOfRangeException("column", column, null); } }