Created
February 8, 2024 12:44
-
-
Save SoylentGraham/ed9ebcf0d344c211db1c40efe0c701f6 to your computer and use it in GitHub Desktop.
Get all unity scriptable object assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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