Skip to content

Instantly share code, notes, and snippets.

Last active September 9, 2019 08:57
What would you like to do?
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))
return dependencies;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment