mirror of
https://github.com/StarBeat/UnityDependencyAnalyzer.git
synced 2026-03-08 05:35:27 +08:00
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
namespace UnityFileApi
|
|
{
|
|
public static class DependencyTool
|
|
{
|
|
static DependencyTool()
|
|
{
|
|
UnityFileSystem.Init();
|
|
}
|
|
|
|
public static List<string> GetDependencies(string path)
|
|
{
|
|
List<string> dependencies = new List<string>();
|
|
try
|
|
{
|
|
using var archive = UnityFileSystem.MountArchive(path, "/");
|
|
foreach (var node in archive.Nodes)
|
|
{
|
|
Console.WriteLine($"Processing {node.Path} {node.Size} {node.Flags}");
|
|
|
|
if (node.Flags.HasFlag(ArchiveNodeFlags.SerializedFile))
|
|
{
|
|
using (var serializedFile = UnityFileSystem.OpenSerializedFile(path))
|
|
{
|
|
foreach (var extRef in serializedFile.ExternalReferences)
|
|
{
|
|
dependencies.Add(extRef.Guid);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dependencies;
|
|
}
|
|
catch (NotSupportedException)
|
|
{
|
|
// Try as SerializedFile
|
|
using (var serializedFile = UnityFileSystem.OpenSerializedFile(path))
|
|
{
|
|
foreach (var extRef in serializedFile.ExternalReferences)
|
|
{
|
|
dependencies.Add(extRef.Guid);
|
|
}
|
|
}
|
|
return dependencies;
|
|
}
|
|
}
|
|
}
|
|
} |