arrow-left

All pages
gitbookPowered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

Known Issues

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 DatabaseAssets via 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.

hashtag
Examples

circle-exclamation

Some of these examples have implicit operators to cast them into the correct type. You have to manually add the implicit operators, for now.

hashtag
Setting an icon for an interaction:

hashtag
Setting up tests:

hashtag
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

hashtag
The AssetData system is divided in a few classes:

hashtag
Assets

  • This class caches 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.

hashtag
DatabaseAsset

  • A class 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.

hashtag
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.

hashtag
WorldObjectAssetReference

  • A class used 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.

hashtag
AssetDatabaseSettings

  • a ScriptableSettings class 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.

circle-info

hashtag
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.

hashtag
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

  1. Create an AddressableGroup for your assets. (Window/AssetManagement/Addressables/Groups).

  2. Set your assets as addressabble and in the groups menu drag them to your new group.

  3. Go to the Assets/Content/Data/Databases folder, and create a new AssetDatabase by going to Create/SS3D/AssetDatabase.

  4. Set your AddressablesGroup in the inspector.

  5. Go to ProjectSettings/SS3D/Assets/AssetDatabaseSettings

  6. Press find and load asset databases.

  7. Check if your new database code was generated in the Assets/Scripts/SS3D/Data/Generated folder

Asset Data

The asset management system.

hashtag
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.

chevron-rightComparison:hashtag

In this example, the asset has to be named BikeHorn and searched by string in 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.

GameObject bikeHornPrefab = Items.BikeHorn