This system is very experimental, we are still seeing if this makes sense to use and if this is the best alternative. Please report issues.
If the database is renamed, the old generated class is not deleted.
The new way of referencing DatabaseAssetsvia WorldObjectReferences only works for GameObjects (by design). Ideally this should be separated by type or category, and have a way to not depend on guids, I was thinking on testing some stuff with the localization table for ids.
Using Asset Data
To use an existing asset database, simply look for its file by "Assets/Scripts/SS3D/Data/Generated", find the database you want to use and then call the item you want to grab.
Example on what it looks like to find the database.
Examples
Some of these examples have implicit operators to cast them into the correct type. You have to manually add the implicit operators, for now.
Setting an icon for an interaction:
Setting up tests:
Creating a world space loading bar
// The Icon field is a Sprite field.
// The InteractionIcons.Open is not a Sprite, it is an AssetDatabase.
// There are implicit operators to cast this AssetDatabase into a Sprite.
public override Sprite GetIcon(InteractionEvent interactionEvent)
{
return Icon != null ? Icon : InteractionIcons.Open;
}
// Get local player position,
// interaction controller and put bikehorn in first hand available.
// Note that we are adding a PDA manually for the test.
AttachedContainer hand =
TestHelpers.LocalPlayerSpawnItemInFirstHandAvailable(Items.PDA);
// Calling the New() method simply creates an instance for that object.
_loadingBarInstance = WorldSpaceUI.LoadingBar.New();
How Asset Data works
The AssetData system is divided in a few classes:
Assets
This classcaches all the AssetDatabases in the game, its where we retrieve the asset we want. We can use the getters to specify which asset from a database to retrieve it.
DatabaseAsset
Aclass that contains a reference for the Name and DatabaseName of an asset, this is used to load them in a convenient way as the class is used when we generate the database code.
AssetDatabase
ScriptableObject that loads all assets present on an AddressablesGroup, adding them to a list of assets and generating a static class with DatabaseAssets related to those assets.
WorldObjectAssetReference
A classused for world object assets, assets that can be placed in the world as a GameObject, this has the purpose of creating a way to reference database assets via the inspector, without having to look for a prefab, it is also generated by the asset data system.
AssetDatabaseSettings
a ScriptableSettingsclass that loads all the AssetDatabases. Everything here is automated, you don't have to mess with. Its useful to see if all the databases are loaded, or to ignore code generation.
The system will automatically load all databases and generate the code/assets for it when a project reload is triggered or when the UI for the settings is opened.
How it works
Whenever the code/asset generation is triggered, the system will scan for asset databases that are not loaded, load them in the list and then start the generation process.
The generation process simply iterates through each database and generate a static class of an DatabaseAsset for each item in the database.
The system will also generate a bunch of WorldObjectAssetReferences, this is done on all assets that can be cast to GameObjects, they can be used in the inspector to reference an database asset.
This is an example of a generated class.
Creating an Asset Database
Create an AddressableGroup for your assets. (Window/AssetManagement/Addressables/Groups).
Set your assets as addressabble and in the groups menu drag them to your new group.
Go to the Assets/Content/Data/Databases folder, and create a new AssetDatabase by going to Create/SS3D/AssetDatabase.
Set your AddressablesGroup in the inspector.
Go to ProjectSettings/SS3D/Assets/AssetDatabaseSettings
Press find and load asset databases.
Check if your new database code was generated in the Assets/Scripts/SS3D/Data/Generated folder
Asset Data
The asset management system.
What is Asset Data?
Asset data is the nickname of a collection of scripts that for a system initially introduced by Seteron, it beingb v a way to get assets in a more practical manner than using Resources.Load("AssetName").
With Asset data, however we use static classes with the corresponding to the asset name, so finding an asset is a manner of knowing the asset name in order to load it.
Comparison:
In this example, the asset has to be named BikeHornand searched by stringin order to be found, and has to be placed into an Editor folder. This prevents it from working at runtime. So we won't be able to do this ingame.
GameObject
bikeHornPrefab
=
Resources
.
Load
(
"BikeHorn"
);
Using the asset data system, autogenerated classes provide easy access to the content of those databases.