Sample: Create and upload Unity Editor assets
You can use the Asset Database Uploader sample in the Unity Editor to create and upload assets from your Unity Project into your Unity Cloud project. By creating them and uploading them, your assets will be available in the Unity Asset Manager.
The sample use the management endpoints that requires a minimum role of:
Before you start
Before you use the Asset Database Uploader sample, you must have the following:
- Installed Assets package
- Installed Identity package
- A valid Unity ID Account
- Access to your Unity Gaming Services account
- Access to Asset Manager service
- A Unity Project with the Asset Manager service enabled, see: Asset Manager documentation
Note
While the Assets package doesn't depend on the Identity service, it is used in the sample to control the authentication process.
Install the sample
To install the sample, follow these steps:
In your Unity Project window, go to Package Manager > Unity Cloud Assets.
Expand the Samples section.
On the right of the Asset Database Uploader sample, select Import.
After the import process is complete, you can view your imported assets in the
Assets/Samples/Unity Cloud Assets
folder.
Run the sample
To run the sample, follow these steps:
- Go to
Assets/Samples/Unity Cloud Assets/<package-version>/Asset Database Uploader/Scenes/AssetDatabaseUploaderSample.unity
and open the scene. - Select the
AssetDatabaseUploader
game object in the Hierarchy window. - In the inspector window, select the
Fetch Organizations and Projects
button.
- Select the Organization where you want to upload your assets to.
- Select the Project where you want to upload your assets to.
- Set the folder path that contains your assets to upload.
- If you want to check which asset is already known in your Unity Cloud project, select the
Search Assets
button.
- To upload your assets, select the
Create and Upload Assets
button.
Note
The script is basic and doesn't handle asset defined by multiple files. Each file is seen as a new asset. Also, all the uploaded assets are set with draft status. The script doesn't provide a way to change the status of an asset.
The sample provide two time out settings:
One for the main queries like Fetch and Search for example.
One for the upload process.
To change the upload timeout, select the AssetDatabaseUploader
game object in the Hierarchy window. In the Inspector window, change the Upload Time Out
value.
Main components
This section describes the scripts that make up the main components of the Asset Database Uploader sample.
AssetsEditor services script
The AssetsEditorServices
class initializes and disposes of dependencies required by IAssetRepository
. You can use this class to manage the Unity Cloud services and dependencies you use in your scripts.
To open the AssetsEditorServices
script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetsEditorServices.cs
file.
Organization and Project selector script
The OrgAndProjectSelector
script shows you how to do the following:
- Retrieve Organizations and Projects from the Assets service.
- Select an Organization and Project from a list of Organizations and Projects.
To open the OrgAndProjectSelector script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/OrgAndProjectSelector.cs
file.
Assets Uploader script
The AssetsUploader
script shows you how to do the following:
- Create an asset in a Unity Cloud Project
- Create a file and attach it to the created asset
- Upload the file contents
To open the AssetsUploader script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetsUploader.cs
file.
The AssetsUploader
class has one required component called OrgAndProjectSelector
.
Asset Database Uploader sample script
The AssetDatabaseUploaderSample
shows you how to do the following:
- Integrate everything together the
AssetsEditorServices
, theOrgAndProjectSelector
and theAssetsUploader
scripts - Use the
AssetsEditorServices
class to get your authentication token - Use the
AssetsEditorServices
class to initialize theIOrganizationRepository
,IAssetRepository
- Initialize the
OrgAndProjectSelector
script - Initialize the
AssetsUploader
script
To open the Asset Database Uploader sample script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetDatabaseUploaderSample.cs
file.
Inspector UI scripts
The sample includes a set of Editor UI scripts. To open the scripts, go to Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/Editor
.
Limitations
The sample has the following limitations:
If your asset already exists in your Unity Cloud Project, the sample will not update your asset nor upload the file content. It will just skip it. For now, the API endpoints don't support to get the upload URL of an asset if the file and the content has not been created and uploaded as the same time than the Asset's creation.
Allows you to create one asset per 'file', you can add rules of your own to combine asset based on 'naming convention, or anything else'. An example would be to combine all files that have the same letters before the first _ . The example of files below would create two assets.
Marble014_8K_Roughness.png
Marble014_8K_NormalGL.png
Marble014_8K_NormalDX.png
Marble014_8K_Displacement.png
Marble014_8K_Color.png
Marble014_PREVIEW.jpg
Marble014_8K-PNG.usdc
Rock030_PREVIEW.jpg
Rock030_8K_Roughness.png
Rock030_8K_NormalGL.png
Rock030_8K_NormalDX.png
Rock030_8K_Displacement.png
Rock030_8K_Color.png
Rock030_8K_AmbientOcclusion.png
Go further with your sample
This section describes other things you can do with the Asset Database Uploader sample.
Step-by-step mode
The sample provide a step by step mode to help you understand how the script works. If you want to follow each step instead of doing everything with one selection, enable the step by step mode.
- To enable the step by step mode, select the
AssetDatabaseUploader
game object in the Hierarchy window. - In the inspector window, check the
Step By Step
checkbox. - Then like the
Create and Upload Assets
button, select each action button one by one following this order:-
Create Assets
-
Create Asset Files
-
Upload Created Assets
-
Troubleshooting
Refer to the troubleshooting section for help with sample issues.