Publish and/or withdraw assets
You can use the Unity Asset Manager SDK package to manage the assets.
Asset management is available through the Asset Management pathway.
Note: Asset management requires users have the role of
Asset Management ContributorOR a minimum role ofManagerin the organization.
Before you start
Before you start, you must:
- Set up a Unity scene in the Unity Editor with an organization and project browser. See either Get started with Asset Discovery or Get started with Asset Management for more information.
Have some assets in the cloud. There are several ways to do so:
- You can create assets through the Get started with Asset Management.
- You can upload assets from existing Unity assets; see the Asset Uploader sample.
- You can create assets through the dashboard; see the Managing assets on the dashboard documentation.
How do I...?
Publish an asset
To publish an asset:
- Open the
AssetManagementBehaviourscript you created. - Add the following code to the end of the class:
public async Task PublishAsset()
{
var cancellationTokenSrc = new CancellationTokenSource(k_DefaultCancellationTimeout);
try
{
await PlatformServices.AssetManager.PublishApprovedAssetAsync(CurrentAsset, cancellationTokenSrc.Token);
}
catch (Exception e)
{
Debug.LogError($"Failed to publish asset: {CurrentAsset.Name}. {e.Message}");
}
}
The script sets the asset in the cloud as published.
Withdraw a published asset
To withdraw a published asset:
- Open the
AssetManagementBehaviourscript you created. - Add the following code to the end of the class:
public async Task WithdrawAsset()
{
var cancellationTokenSrc = new CancellationTokenSource(k_DefaultCancellationTimeout);
try
{
await PlatformServices.AssetManager.WithdrawPublishedAssetAsync(CurrentAsset, cancellationTokenSrc.Token);
}
catch (Exception e)
{
Debug.LogError($"Failed to withdraw published asset: {CurrentAsset.Name}. {e.Message}");
}
}
The script withdraws the published asset.
Add the UI for interacting with assets
To add UI for the example:
- Open the
AssetManagementUIscript you created. - Replace the
AssetActionsfunction with the following code:
protected virtual void AssetActions()
{
if (m_Behaviour.CurrentAsset == null)
{
GUILayout.Label(" ! No asset selected !");
return;
}
if(string.Equals(m_Behaviour.CurrentAsset.Status, "Approved", StringComparison.OrdinalIgnoreCase))
{
if (GUILayout.Button("Publish"))
{
_ = m_Behaviour.PublishAsset();
}
GUILayout.Space(5f);
}
if(string.Equals(m_Behaviour.CurrentAsset.Status, "Published", StringComparison.OrdinalIgnoreCase))
{
if (GUILayout.Button("Withdraw"))
{
_ = m_Behaviour.WithdrawAsset();
}
GUILayout.Space(5f);
}
}
The script provides UI buttons to trigger the publish or the withdraw of a new asset.