public static string[] GetAssetImporterDependencies(string path) { var importer = AssetImporter.GetAtPath(path); if (importer == null) { Debug.LogWarning(Maintainer.ConstructWarning("Couldn't find AssetImporter for " + path)); return(null); } var method = importer.GetType().GetMethod("GatherDependenciesFromSourceFile", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { // this importer does not implement optional GatherDependenciesFromSourceFile message (starting from Unity 2020.1) return(null); } var items = (string[])method.Invoke(null, new [] { path }); if (items != null && items.Length > 0) { return(items); } return(null); }
private static List <string> ExtractReferencedAssets(Object assetGroup) { var so = new SerializedObject(assetGroup); var serializedEntries = so.FindProperty("m_SerializeEntries"); if (serializedEntries == null) { // legacy package version used this name serializedEntries = so.FindProperty("m_serializeEntries"); if (serializedEntries == null) { Debug.LogError(Maintainer.ConstructError("Can't reach serialize entries in AddressableAssetGroup!")); return(null); } } if (!serializedEntries.isArray) { Debug.LogError(Maintainer.ConstructError("Can't find serialize entries array in AddressableAssetGroup!")); return(null); } var result = new List <string>(); var count = serializedEntries.arraySize; for (var i = 0; i < count; i++) { var item = serializedEntries.GetArrayElementAtIndex(i); if (item == null) { Debug.LogWarning(Maintainer.ConstructWarning("Serialize entry from AddressableAssetGroup is null!")); continue; } var referencedGUID = item.FindPropertyRelative("m_GUID"); if (referencedGUID == null || referencedGUID.propertyType != SerializedPropertyType.String) { Debug.LogError(Maintainer.ConstructError("Can't reach Serialize entry GUID of AddressableAssetGroup!")); return(null); } var path = AssetDatabase.GUIDToAssetPath(referencedGUID.stringValue); if (!path.StartsWith("Assets")) { continue; } var guid = AssetDatabase.AssetPathToGUID(path); if (!string.IsNullOrEmpty(guid)) { result.Add(guid); } } return(result); }
private static void ProcessSceneForProjectLevelReferences(string path, List <TreeConjunction> conjunctions) { var openSceneResult = CSSceneTools.OpenScene(path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + path)); return; } SceneSettingsProcessor.Process(conjunctions); EntryFinder.currentLocation = Location.SceneGameObject; CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, true, false, EntryFinder.OnGameObjectTraverse); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
private static void ProcessScene() { var path = assetConjunctions.asset.Path; var openSceneResult = CSSceneTools.OpenScene(path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + path)); return; } SceneSettingsProcessor.Process(assetConjunctions.conjunctions); currentLocation = Location.SceneGameObject; CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, true, OnGameObjectTraverse); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
/// <summary> /// Register any custom dependencies parsers here. Allows parsing unknown types dependencies. /// </summary> /// Passed parsers will be used in the Assets Dependencies Map and will affect all Maintainer references-related functionality.<br/> /// Call this before running Maintainer first time (before Assets Map is created).<br/> /// For example, call it from the [InitializeOnLoad] class' static constructor. /// <param name="parsers">List of new parsers.</param> public static void AddExternalDependenciesParsers(List <IDependenciesParser> parsers) { if (parsers == null || parsers.Count == 0) { Debug.LogError(Maintainer.ConstructWarning("Empty list passed to AddExternalDependenciesParsers!")); return; } if (externalDependenciesParsers == null || externalDependenciesParsers.Count == 0) { externalDependenciesParsers = parsers; } else { foreach (var newParser in parsers) { if (!externalDependenciesParsers.Contains(newParser)) { externalDependenciesParsers.Add(newParser); } } } }
private static long GetLocalIdentifierInFile(Object unityObject) { var go = unityObject as GameObject; if (go != null) { unityObject = go; } var serializedObject = new SerializedObject(unityObject); try { CSReflectionTools.SetInspectorToDebug(serializedObject); var serializedProperty = serializedObject.FindProperty("m_LocalIdentfierInFile"); return(serializedProperty.longValue); } catch (Exception e) { Debug.LogWarning(Maintainer.ConstructWarning("Couldn't get data from debug inspector for object " + unityObject.name + " due to this error:\n" + e)); return(-1); } }
private static void ProcessScene(AssetInfo asset, string assetName, int sceneIndex, int totalScenes) { currentObjectIndex = 0; itemIndex = sceneIndex; totalItems = totalScenes; currentAssetName = assetName; var openSceneResult = CSSceneTools.OpenScene(asset.Path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + asset.Path)); return; } var skipCleanPrefabInstances = ProjectSettings.Issues.scanGameObjects && ProjectSettings.Issues.lookInAssets; IssuesDetector.SceneStart(asset); CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, skipCleanPrefabInstances, false, OnGameObjectTraverse); IssuesDetector.SceneEnd(asset); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
private static void SetReferencingEntries(List <TreeConjunction> conjunctions) { foreach (var conjunction in conjunctions) { var referencedAtInfo = conjunction.referencedAtInfo; if (referencedAtInfo.entries == null || referencedAtInfo.entries.Length == 0) { var newEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "No exact reference place found." }; var referencedAtAssetInfo = referencedAtInfo as ReferencedAtAssetInfo; if (referencedAtAssetInfo != null && referencedAtAssetInfo.assetInfo.Type == CSReflectionTools.sceneAssetType) { var sceneSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to remove all missing prefabs/scripts (if any) and re-save scene, it may cleanup junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, sceneSpecificEntry }; } else if (referencedAtAssetInfo != null && referencedAtAssetInfo.assetInfo.Type == CSReflectionTools.gameObjectType) { var prefabSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to re-Apply prefab explicitly, this may clean up junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, prefabSpecificEntry }; } else { referencedAtInfo.entries = new[] { newEntry }; } if (ReferencesFinder.debugMode) { if (conjunction.referencedAsset != null) { Debug.LogWarning(Maintainer.ConstructWarning( "Couldn't determine where exactly this asset is referenced: " + conjunction.referencedAsset.Path, ReferencesFinder.ModuleName)); } } } foreach (var targetTreeElement in conjunction.treeElements) { targetTreeElement.referencingEntries = referencedAtInfo.entries; } } }
public static bool RevealInSettings(AssetSettingsKind settingsKind, string path = null) { var result = true; switch (settingsKind) { case AssetSettingsKind.AudioManager: case AssetSettingsKind.ClusterInputManager: case AssetSettingsKind.InputManager: case AssetSettingsKind.NavMeshAreas: case AssetSettingsKind.NavMeshLayers: case AssetSettingsKind.NavMeshProjectSettings: case AssetSettingsKind.NetworkManager: break; case AssetSettingsKind.NotSettings: Debug.LogWarning(Maintainer.ConstructWarning("Can't open settings of kind NotSettings Oo")); result = false; break; case AssetSettingsKind.DynamicsManager: if (!CSMenuTools.ShowProjectSettingsPhysics()) { Debug.LogError(Maintainer.ConstructError("Can't open Physics Settings!")); result = false; } break; case AssetSettingsKind.EditorBuildSettings: if (!CSMenuTools.ShowEditorBuildSettings()) { Debug.LogError(Maintainer.ConstructError("Can't open EditorBuildSettings!")); result = false; } break; case AssetSettingsKind.EditorSettings: if (!CSMenuTools.ShowEditorSettings()) { Debug.LogError(Maintainer.ConstructError("Can't open Editor Settings!")); result = false; } break; case AssetSettingsKind.GraphicsSettings: if (!CSMenuTools.ShowProjectSettingsGraphics()) { Debug.LogError(Maintainer.ConstructError("Can't open GraphicsSettings!")); result = false; } break; case AssetSettingsKind.Physics2DSettings: if (!CSMenuTools.ShowProjectSettingsPhysics2D()) { Debug.LogError(Maintainer.ConstructError("Can't open Physics2D Settings!")); result = false; } break; case AssetSettingsKind.ProjectSettings: if (!CSMenuTools.ShowProjectSettingsPlayer()) { Debug.LogError(Maintainer.ConstructError("Can't open Player Settings!")); result = false; } break; case AssetSettingsKind.PresetManager: if (!CSMenuTools.ShowProjectSettingsPresetManager()) { Debug.LogError(Maintainer.ConstructError("Can't open Preset Manager!")); result = false; } break; case AssetSettingsKind.QualitySettings: break; case AssetSettingsKind.TagManager: if (!CSMenuTools.ShowProjectSettingsTagsAndLayers()) { Debug.LogError(Maintainer.ConstructError("Can't open Tags and Layers Settings!")); result = false; } break; case AssetSettingsKind.TimeManager: break; case AssetSettingsKind.UnityAdsSettings: break; case AssetSettingsKind.UnityConnectSettings: break; case AssetSettingsKind.VFXManager: if (!CSMenuTools.ShowProjectSettingsVFX()) { Debug.LogError(Maintainer.ConstructError("Can't open VFX Settings!")); result = false; } break; case AssetSettingsKind.Unknown: if (!string.IsNullOrEmpty(path)) { EditorUtility.RevealInFinder(path); } break; default: throw new ArgumentOutOfRangeException(); } return(result); }
public static bool FillReferenceEntries() { var canceled = false; var count = ReferencesFinder.ConjunctionInfoList.Count; var updateStep = Math.Max(count / MaintainerSettings.UpdateProgressStep, 1); for (var i = 0; i < count; i++) { if ((i < 10 || i % updateStep == 0) && EditorUtility.DisplayCancelableProgressBar( string.Format(ReferencesFinder.ProgressCaption, 2, ReferencesFinder.PhasesCount), string.Format(ReferencesFinder.ProgressText, "Filling reference details", i + 1, count), (float)i / count)) { canceled = true; break; } assetConjunctions = ReferencesFinder.ConjunctionInfoList[i]; var type = assetConjunctions.asset.Type; if (type == CSReflectionTools.gameObjectType) { ProcessPrefab(); } else if (type == CSReflectionTools.sceneAssetType) { ProcessScene(); } else if (type == CSReflectionTools.monoScriptType) { ProcessScriptAsset(); } else if (type != null && (type.BaseType == CSReflectionTools.scriptableObjectType || type == CSReflectionTools.monoBehaviourType)) { ProcessScriptableObjectAsset(); } foreach (var conjunction in assetConjunctions.conjunctions) { var referencedAtInfo = conjunction.referencedAtInfo; if (referencedAtInfo.entries == null || referencedAtInfo.entries.Length == 0) { var newEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "No exact reference place found." }; if (referencedAtInfo.assetInfo.Type == CSReflectionTools.sceneAssetType) { var sceneSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to remove all missing prefabs/scripts (if any) and re-save scene, it may cleanup junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, sceneSpecificEntry }; } else if (referencedAtInfo.assetInfo.Type == CSReflectionTools.gameObjectType) { var prefabSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to re-Apply prefab explicitly, this may clean up junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, prefabSpecificEntry }; } else { referencedAtInfo.entries = new[] { newEntry }; } if (ReferencesFinder.debugMode) { Debug.LogWarning(Maintainer.ConstructWarning("Couldn't determine where exactly this asset is referenced: " + conjunction.referencedAsset.Path, ReferencesFinder.ModuleName)); } } foreach (var targetTreeElement in conjunction.treeElements) { targetTreeElement.referencingEntries = referencedAtInfo.entries; } } } return(canceled); }