Sometimes you need a ScriptableObject which contains a collection of other objects or we usually say Database. A simple example is the ScriptableObject which contains all the items in the game that you created. Then you want to find a certain item based on the name of the item, you can perform a search function of all items in the database that match the criteria you are looking for.
Below is an example of an ScriptableObjectWithId Database that contains all the ScriptableObjectWithId contained in a project
With this I can run a validation when unique id is changed if it has same id with these others ScriptableObject. If yes, it will show errors when editing.
To create a database like this, there are two scripts that must be created, the Repository as the container for the class you want to load and the Database itself. Below are examples of AudioDatabase and AudioRepository scripts, you can follow these examples to create your own database.
As you can see in the code, the RefreshItemList() method will be executed when the editor enters play/stop mode. Then a script will be run to find assets with a certain class type and update the repository.
Items in the database example above will only refresh when editor play mode changed.
Database.Get
To access a repository you can call the static class Database.Get<T>
// Return all Audio Clip Settings in Audio Repositoryvar allClips =Database.Get<AudioRepository>().Clips;