From e11d470f1f268c41ccd595e39452d4eb04bb77ef Mon Sep 17 00:00:00 2001 From: "hanschristian.kientopf" Date: Fri, 26 Jun 2020 15:35:34 +0200 Subject: [PATCH 1/2] Added support for prefab variants to be detected by the ObjectSerializedDependencyResolver and Fixed calculation of asset sizes when using AssetDatabaseV2 --- .../AssetDependencyCache.cs | 2 +- .../AssetSerializedPropertyTraverser.cs | 15 ++++- .../AssetTraverser/AssetTraverser.cs | 17 ++++-- ...ectSerializedPropertyTraverserSubSystem.cs | 12 ++++ .../SerializedPropertyTraverserSubSystem.cs | 2 + .../Utility/NodeDependencyLookupUtility.cs | 61 +++++++++++++++---- README.md | 31 +++++----- changelog.md | 8 ++- package.json | 2 +- 9 files changed, 113 insertions(+), 37 deletions(-) diff --git a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetDependencyCache.cs b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetDependencyCache.cs index 94f4fde..c21b021 100644 --- a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetDependencyCache.cs +++ b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetDependencyCache.cs @@ -12,7 +12,7 @@ namespace Com.Innogames.Core.Frontend.NodeDependencyLookup */ public class AssetDependencyCache : IDependencyCache { - public const string Version = "1.01"; + public const string Version = "1.02"; public const string FileName = "AssetDependencyCacheData_" + Version + ".cache"; private AssetNode[] _assetNodes = new AssetNode[0]; diff --git a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetSerializedPropertyTraverser.cs b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetSerializedPropertyTraverser.cs index 527151a..b5641cd 100644 --- a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetSerializedPropertyTraverser.cs +++ b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetSerializedPropertyTraverser.cs @@ -186,7 +186,20 @@ public override void TraversePrefab(string id, Object obj, Stack st subSystem.TraversePrefab(id, obj, stack); } } - + + public override void TraversePrefabVariant(string id, Object obj, Stack stack) + { + if (!m_guidToResolver.ContainsKey(id)) + { + Debug.LogErrorFormat("AssetSerializedPropertyTraverser: could not find guid {0} in resolver list", id); + } + + foreach (SerializedPropertyTraverserSubSystem subSystem in m_guidToResolver[id]) + { + subSystem.TraversePrefabVariant(id, obj, stack); + } + } + public void TraverseProperty(string id, Type objType, object obj, SerializedProperty property, string propertyPath, Stack stack) { SerializedPropertyType type = property.propertyType; diff --git a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetTraverser.cs b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetTraverser.cs index 5bd3354..1558675 100644 --- a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetTraverser.cs +++ b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/AssetTraverser.cs @@ -17,6 +17,8 @@ public abstract class AssetTraverser // What to to when a prefab got found, in case of searching for assets, it should be added as a dependency public abstract void TraversePrefab(string id, Object obj, Stack stack); + + public abstract void TraversePrefabVariant(string id, Object obj, Stack stack); public void Traverse(string id, Object obj, Stack stack) { @@ -64,7 +66,7 @@ public void TraverseGameObject(string id, Object obj, Stack stack, #if UNITY_2018_3_OR_NEWER PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType(obj); - if (prefabAssetType == PrefabAssetType.Regular) + if (prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant) { if (PrefabUtility.GetCorrespondingObjectFromSource(go)) { @@ -73,13 +75,20 @@ public void TraverseGameObject(string id, Object obj, Stack stack, if(prefabObj != currentPrefab) { - TraversePrefab(id, obj, stack); + if (prefabAssetType == PrefabAssetType.Regular) + { + TraversePrefab(id, obj, stack); + } + else if (prefabAssetType == PrefabAssetType.Variant) + { + TraversePrefabVariant(id, obj, stack); + } + currentPrefab = prefabObj; } } } #endif - #if !UNITY_2018_3_OR_NEWER PrefabType prefabType = PrefabUtility.GetPrefabType(obj); @@ -91,7 +100,7 @@ public void TraverseGameObject(string id, Object obj, Stack stack, if(prefabObj != currentPrefab) { - OnPrefabTraversed(id, obj, stack); + TraversePrefab(id, prefabAssetType, obj, stack); currentPrefab = prefabObj; } } diff --git a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/ObjectSerializedPropertyTraverserSubSystem.cs b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/ObjectSerializedPropertyTraverserSubSystem.cs index 2a450e8..2d560f9 100644 --- a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/ObjectSerializedPropertyTraverserSubSystem.cs +++ b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/ObjectSerializedPropertyTraverserSubSystem.cs @@ -18,6 +18,18 @@ public class ObjectSerializedPropertyTraverserSubSystem : SerializedPropertyTrav public HashSet ExcludedDependencies = new HashSet(new []{"UnityEngine.UI.dll", "UnityEngine.dll"}); public override void TraversePrefab(string id, Object obj, Stack stack) + { + AddPrefabAsDependency(id, obj, stack); + } + + public override void TraversePrefabVariant(string id, Object obj, Stack stack) + { + stack.Push(new PathSegment("Variant Of", PathSegmentType.Component)); + AddPrefabAsDependency(id, obj, stack); + stack.Pop(); + } + + private void AddPrefabAsDependency(string id, Object obj, Stack stack) { string assetPath = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(obj)); string guid = AssetDatabase.AssetPathToGUID(assetPath); diff --git a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/SerializedPropertyTraverserSubSystem.cs b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/SerializedPropertyTraverserSubSystem.cs index 94ac72a..8a6a307 100644 --- a/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/SerializedPropertyTraverserSubSystem.cs +++ b/NodeDependencyLookup/Editor/Caches/AssetDependencyCache/AssetTraverser/SubSystems/SerializedPropertyTraverserSubSystem.cs @@ -19,6 +19,8 @@ public class Result // What to to when a prefab got found, in case of searching for assets, it should be added as a dependency public abstract void TraversePrefab(string id, Object obj, Stack stack); + public abstract void TraversePrefabVariant(string id, Object obj, Stack stack); + // Returns a dependency result of the given serialized property is a UnityEngine.Object public abstract Result GetDependency(Type objType, object obj, SerializedProperty property, string propertyPath, SerializedPropertyType type, Stack stack); diff --git a/NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs b/NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs index a396b84..f7b09cd 100644 --- a/NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs +++ b/NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs @@ -6,6 +6,10 @@ using UnityEditor; using UnityEngine; +#if UNITY_2019_2_OR_NEWER +using UnityEditor.Experimental; +#endif + namespace Com.Innogames.Core.Frontend.NodeDependencyLookup { /// @@ -117,30 +121,63 @@ public static List GetNodeHandlers() /// public static int GetPackedAssetSize(string guid) { - string path = AssetDatabase.GUIDToAssetPath(guid); - string fullpath = string.Empty; + string fullpath = GetLibraryFullPath(guid); + + if (!String.IsNullOrEmpty(fullpath) && File.Exists(fullpath)) + { + FileInfo info = new FileInfo(fullpath); + return (int) (info.Length / 1024); + } + + return 0; + } + public static string GetLibraryFullPath(string guid) + { if (String.IsNullOrEmpty(guid)) { - return 0; + return null; } - + + string path = AssetDatabase.GUIDToAssetPath(guid); + if (Path.GetExtension(path).Equals(".asset")) { - fullpath = path; + return path; } - else + + +#if UNITY_2019_2_OR_NEWER + if (EditorSettings.assetPipelineMode == AssetPipelineMode.Version1) { - fullpath = Application.dataPath + "../../Library/metadata/" + guid.Substring(0, 2) + "/" + guid; + return GetAssetDatabaseVersion1LibraryDataPath(guid); } - - if (File.Exists(fullpath)) + else { - FileInfo info = new FileInfo(fullpath); - return (int) (info.Length / 1024); + Hash128 artifactHash = AssetDatabaseExperimental.GetArtifactHash(guid); + + string[] paths; + + AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out paths); + + foreach (string artifactPath in paths) + { + if(artifactPath.EndsWith(".info")) + continue; + + return Path.GetFullPath(artifactPath); + } } +#else // For older version that dont have asset database V2 yet + return return GetAssetDatabaseVersion1LibraryDataPath(guid); +#endif + + return null; + } - return 0; + private static string GetAssetDatabaseVersion1LibraryDataPath(string guid) + { + return Application.dataPath + "../../Library/metadata/" + guid.Substring(0, 2) + "/" + guid; } /// diff --git a/README.md b/README.md index d077d4d..72fdd82 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,16 @@ Plugin to display dependencies between assets in a tree based view within the Un



## Features -* Standalone Editor UI without any dependencies -* View which dependencies an asset has +* Standalone Editor UI without any external dependencies +* View which dependencies an asset has to other assets * View which assets have the given asset as a dependency -* Show thumnails of all assets in the dependency tree -* Filter to filter for Asset Names and Asset Types in displayed tree -* Show if an asset is used in the project (going to be packed in the app) +* Show thumbnails of all assets in the dependency tree +* filter for Asset Names and Asset Types in displayed tree +* Highlight if an asset is used in the project (going to be packed in the app) * Show path of where an asset is used exactly within a scene, prefab or asset -* Display byte size of asset together with overall size of dependency tree -* Extendable by own dependency resolvers, for example to show addressables in tree -* Support additional connection- and nodetypes which can be added via addons +* Display byte size of compressed asset together with overall size of dependency tree +* Extendable by own dependency resolvers, for example to show addressables +* Support additional connection- and nodetypes which can be added via addons, for example: * Addressable Groups * Addressables * AssetBundles @@ -42,12 +42,11 @@ Find the manifest.json file in the Packages folder of your project and edit it t



## First Usage -1. Select an asset as to show in unity project explorer +1. Select an asset within the unity project explorer 2. Right click to open context menu for an asset 3. Select "Show in Asset Relations Viewer" 4. On Dialog for the first startup of AssetRelationsViewer click on yes 5. Wait for the resolver to find all dependencies for all assets in the project which can take a while for a large project with many assets -6. Activate "Object" to show dependencies for Unity Objects (Assets)



## Controls @@ -76,7 +75,7 @@ Menu items sorted from left to right **Show hierarchy Once**: To only show the same dependency hierarchy for an asset once within the displayed tree -**Show referencers** If referencers (Assets that have the selected asset as a dependency) should be shown or not +**Show referencers**: If referencers (Assets that have the selected asset as a dependency) should be shown or not **Show Property Pathes**: If path of where the dependency is within the scene, prefab, scriptable object is shown @@ -120,9 +119,13 @@ Since this solution is based on an own dependency search implementation, it is m



## Showing dependency pathes -If you want to know where exactly in a scene, prefab, scriptable object a reference is done the "ObjectSerializedDependencyResolver" needs to be active and "Show Property Pathes" in the menu needs to be active. +If one wants to know where exactly in a scene, prefab, scriptable object a reference is done the "ObjectSerializedDependencyResolver" needs to be active and "Show Property Pathes" in the menu needs to be active. Once active the whole path of the dependency (GameObject->Components->ClassMemberVariable) is shown. +#### Showing "Unknown Path" path nodes +This is due to the issue that the AssetDatabase.GetDependencies() function returns dependencies of nested prefabs as well as prefab variants even though the dependencies are not serialized within the asset itself. +This is why the ObjectSerializedDependencyResolver cant find these dependencies within the serialized properties of the asset itself while AssetDatabase.GetDependencies() still returns it for non recursive dependencies so the path is unknown. + ![](Docs~/Images/arv_example_pathes.png)



@@ -142,6 +145,4 @@ An addon is available to add support for showing addressables and also addressab The Package is called asset-relations-viewer-addressables #### Writing own addons to support custom connection- and nodetypes -Documentation on how to write own addons will be added later - - +Documentation on how to write own addons will be added later \ No newline at end of file diff --git a/changelog.md b/changelog.md index 16d320a..9f43768 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,7 @@ -**1.0.0** - - - Initial commit +**1.1.0** + - Added support for prefab variants to be detected by the ObjectSerializedDependencyResolver + - Fixed calculation of asset sizes when using AssetDatabaseV2 +**1.0.0** + - Initial commit \ No newline at end of file diff --git a/package.json b/package.json index 5a56b52..4475237 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.innogames.asset-relations-viewer", "displayName": "Asset Relations Viewer", "description": "Editor UI for displaying dependencies between assets in a tree based view", - "version": "1.0.0", + "version": "1.1.0", "unity": "2018.4", "license": "MIT", "repository": { From ec790c54be42205793e6edf8b027ec65780338f9 Mon Sep 17 00:00:00 2001 From: "hanschristian.kientopf" Date: Fri, 26 Jun 2020 16:56:46 +0200 Subject: [PATCH 2/2] Fixed error in calculation of path node height --- .../Editor/VisualizationNode/PathVisualizationNode.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AssetRelationsViewer/Editor/VisualizationNode/PathVisualizationNode.cs b/AssetRelationsViewer/Editor/VisualizationNode/PathVisualizationNode.cs index fc43600..837f608 100644 --- a/AssetRelationsViewer/Editor/VisualizationNode/PathVisualizationNode.cs +++ b/AssetRelationsViewer/Editor/VisualizationNode/PathVisualizationNode.cs @@ -55,7 +55,13 @@ private int GetPathNodeCount() foreach (VisualizationConnection connection in GetRelations(RelationType.DEPENDENCY, true, true)) { - pathCount += connection.Datas.Count; + for (var i = 0; i < connection.Datas.Count; i++) + { + if (connection.Datas[i].PathSegments.Length > 0) + { + pathCount++; + } + } } return pathCount;