Skip to content

Commit

Permalink
Merge pull request #1 from innogames/add-support-for-assetdatabasev2
Browse files Browse the repository at this point in the history
Add support for assetdatabasev2
  • Loading branch information
pak762 authored Jun 29, 2020
2 parents 84f3d81 + ec790c5 commit 78cdaf0
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ public override void TraversePrefab(string id, Object obj, Stack<PathSegment> st
subSystem.TraversePrefab(id, obj, stack);
}
}


public override void TraversePrefabVariant(string id, Object obj, Stack<PathSegment> 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<PathSegment> stack)
{
SerializedPropertyType type = property.propertyType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathSegment> stack);

public abstract void TraversePrefabVariant(string id, Object obj, Stack<PathSegment> stack);

public void Traverse(string id, Object obj, Stack<PathSegment> stack)
{
Expand Down Expand Up @@ -64,7 +66,7 @@ public void TraverseGameObject(string id, Object obj, Stack<PathSegment> 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))
{
Expand All @@ -73,13 +75,20 @@ public void TraverseGameObject(string id, Object obj, Stack<PathSegment> 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);
Expand All @@ -91,7 +100,7 @@ public void TraverseGameObject(string id, Object obj, Stack<PathSegment> stack,

if(prefabObj != currentPrefab)
{
OnPrefabTraversed(id, obj, stack);
TraversePrefab(id, prefabAssetType, obj, stack);
currentPrefab = prefabObj;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public class ObjectSerializedPropertyTraverserSubSystem : SerializedPropertyTrav
public HashSet<string> ExcludedDependencies = new HashSet<string>(new []{"UnityEngine.UI.dll", "UnityEngine.dll"});

public override void TraversePrefab(string id, Object obj, Stack<PathSegment> stack)
{
AddPrefabAsDependency(id, obj, stack);
}

public override void TraversePrefabVariant(string id, Object obj, Stack<PathSegment> stack)
{
stack.Push(new PathSegment("Variant Of", PathSegmentType.Component));
AddPrefabAsDependency(id, obj, stack);
stack.Pop();
}

private void AddPrefabAsDependency(string id, Object obj, Stack<PathSegment> stack)
{
string assetPath = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(obj));
string guid = AssetDatabase.AssetPathToGUID(assetPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathSegment> stack);

public abstract void TraversePrefabVariant(string id, Object obj, Stack<PathSegment> 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<PathSegment> stack);

Expand Down
61 changes: 49 additions & 12 deletions NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
using UnityEditor;
using UnityEngine;

#if UNITY_2019_2_OR_NEWER
using UnityEditor.Experimental;
#endif

namespace Com.Innogames.Core.Frontend.NodeDependencyLookup
{
/// <summary>
Expand Down Expand Up @@ -117,30 +121,63 @@ public static List<INodeHandler> GetNodeHandlers()
/// </summary>
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;
}

/// <summary>
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Plugin to display dependencies between assets in a tree based view within the Un
<br><br><br><br>
## 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
Expand All @@ -42,12 +42,11 @@ Find the manifest.json file in the Packages folder of your project and edit it t
<br><br><br><br>
## 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)

<br><br><br><br>
## Controls
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -120,9 +119,13 @@ Since this solution is based on an own dependency search implementation, it is m

<br><br><br><br>
## 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)

<br><br><br><br>
Expand All @@ -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
8 changes: 5 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 78cdaf0

Please sign in to comment.