Skip to content

Instantly share code, notes, and snippets.

@ArchyInf
Last active January 22, 2024 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArchyInf/c3917efc905a4be3c521eddc8cd5414f to your computer and use it in GitHub Desktop.
Save ArchyInf/c3917efc905a4be3c521eddc8cd5414f to your computer and use it in GitHub Desktop.
static TypeDB GetTypeDB(BuildTarget buildTarget)
{
BuildTargetGroup group;
if (!Enum<BuildTargetGroup>.TryParse(buildTarget.ToString(), out group))
group = BuildTargetGroup.Standalone;
var settings = new ScriptCompilationSettings
{
target = buildTarget,
group = group,
options = ScriptCompilationOptions.None,
};
var tempPath = ".temp/AssetBundleHelper_Compile";
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
var results = PlayerBuildInterface.CompilePlayerScripts(settings, tempPath);
// todo: serialize/deserialize when not changed? After switching to the scriptable build pipeline this is already done, so NO.
var typeDB = results.typeDB;
return typeDB;
}
static HashSet<AssetPath> GetDependencies(string assetPath, BuildTarget buildTarget, TypeDB typeDB)
{
var guid = new GUID(AssetDatabase.AssetPathToGUID(assetPath));
var ids = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(guid, buildTarget);
var deps = ContentBuildInterface.GetPlayerDependenciesForObjects(ids, buildTarget, typeDB);
var dependencies = new HashSet<string>();
foreach (var dep in deps)
{
var path = "";
if (dep.fileType == FileType.SerializedAssetType)
path = dep.filePath;
else if (dep.fileType == FileType.MetaAssetType)
path = AssetDatabase.GUIDToAssetPath(dep.guid.ToString());
if (string.IsNullOrEmpty(path))
continue;
dependencies.Add(path);
}
return dependencies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment