Skip to content

Instantly share code, notes, and snippets.

@SoylentGraham
Created February 8, 2024 12:44
Show Gist options
  • Save SoylentGraham/ed9ebcf0d344c211db1c40efe0c701f6 to your computer and use it in GitHub Desktop.
Save SoylentGraham/ed9ebcf0d344c211db1c40efe0c701f6 to your computer and use it in GitHub Desktop.
Get all unity scriptable object assets
void RunForEachCondenseBuildSettings(System.Action<CondenseBuildSettings> Functor)
{
var ThisTypename = this.GetType().Name;
var BuildSettingAssetGuids = AssetDatabase.FindAssets($"t:{ThisTypename}");
// no build-settings assets in project, nothing to apply.
if ( BuildSettingAssetGuids.Length == 0 )
return;
if ( BuildSettingAssetGuids.Length > 1 )
{
Debug.LogWarning($"There are more than 1 {ThisTypename} assets in the project, they may give conflicting results");
}
foreach (string BuildSettingAssetGuid in BuildSettingAssetGuids)
{
var AssetPath = AssetDatabase.GUIDToAssetPath(BuildSettingAssetGuid);
var Asset = AssetDatabase.LoadAssetAtPath(AssetPath,this.GetType()) as CondenseBuildSettings;
if ( Asset == null )
throw new Exception($"Failed to load {this.GetType().Name} asset at {AssetPath}");
Functor(Asset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment