docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Use case: Manage assets review

    You can use the Unity Cloud Assets package to send assets to review and approve or reject assets in review.

    Organization and Asset Manager Project role Send to review Approve/reject
    Asset Management Viewer no no
    Asset Management Consumer no no
    Asset Management Contributor yes yes
    Organization Owner yes yes

    Before you start

    Before you start, you must:

    1. Set up a Unity scene in the Unity Editor with an Organization and Project browser. See Get started with Assets for more information.

    2. Have some assets in the cloud. There are several ways to do so:

      • You can create assets through the Get started with Assets.
      • You can upload assets from existing Unity assets; see the Asset Database Uploader sample.
      • You can create assets through the dashboard; see the Managing assets on the dashboard documentation.

    How do I...?

    Send an asset to review

    To send an asset to review, follow these steps:

    1. Open the AssetManagementBehaviour script you created.
    2. Add the following code to the end of the class:
    
    public async Task SendAssetToReview()
    {
        var cancellationTokenSrc = new CancellationTokenSource(k_DefaultCancellationTimeout);
        try
        {
            await CurrentAsset.UpdateStatusAsync(AssetStatusAction.SendForReview, cancellationTokenSrc.Token);
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to send asset to review: {CurrentAsset.Name}. {e}");
        }
    }
    
    

    The code snippet sends an asset in the cloud to review.

    Approve an in-review asset

    To approve an in-review asset, follow these steps:

    1. Open the AssetManagementBehaviour script you created.
    2. Add the following code to the end of the class:
    
    public async Task ApproveInReviewAsset()
    {
        var cancellationTokenSrc = new CancellationTokenSource(k_DefaultCancellationTimeout);
        try
        {
            await CurrentAsset.UpdateStatusAsync(AssetStatusAction.Approve, cancellationTokenSrc.Token);
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to approve in-review asset: {CurrentAsset.Name}. {e}");
        }
    }
    
    

    The code snippet approves an in-review asset.

    Reject an in-review asset

    To reject an in-review asset, follow these steps:

    1. Open the AssetManagementBehaviour script you created.
    2. Add the following code to the end of the class:
    
    public async Task RejectInReviewAsset()
    {
        var cancellationTokenSrc = new CancellationTokenSource(k_DefaultCancellationTimeout);
        try
        {
            await CurrentAsset.UpdateStatusAsync(AssetStatusAction.Reject, cancellationTokenSrc.Token);
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to reject in-review asset: {CurrentAsset.Name}. {e}");
        }
    }
    
    

    The code snippet rejects an in-review asset.

    Add the UI for updating the status of assets

    To create UI for updating the status of assets, follow these steps:

    1. In your Unity Project window, go to Assets > Scripts.
    2. Select and hold the Assets/Scripts folder.
    3. Go to Create > C# Script. Name your script UseCaseSendToReviewApproveRejectAssetExampleUI.
    4. Open the UseCaseSendToReviewApproveRejectAssetExampleUI script you created and replace the contents of the file with the following code sample:
    
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using Unity.Cloud.Assets;
    using UnityEngine;
    
    public class UseCaseSendToReviewApproveRejectAssetExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
    
        public UseCaseSendToReviewApproveRejectAssetExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
        }
    
        public void OnGUI() { }
    }
    
    
    1. In the same script, replace the OnGUI function with the following code:
    
    public void OnGUI()
    {
        if (!m_Behaviour.IsProjectSelected) return;
    
        if (m_Behaviour.CurrentAsset == null)
        {
            GUILayout.Label(" ! No asset selected !");
            return;
        }
    
        if (string.Equals(m_Behaviour.CurrentAsset.Status, "Draft", StringComparison.OrdinalIgnoreCase))
        {
            if (GUILayout.Button("Send to Review"))
            {
                _ = m_Behaviour.SendAssetToReview();
            }
    
            GUILayout.Space(5f);
        }
        else if (string.Equals(m_Behaviour.CurrentAsset.Status, "InReview", StringComparison.OrdinalIgnoreCase))
        {
            if (GUILayout.Button("Approve in-review asset"))
            {
                _ = m_Behaviour.ApproveInReviewAsset();
            }
    
            GUILayout.Space(5f);
    
            if (GUILayout.Button("Reject in-review asset"))
            {
                _ = m_Behaviour.RejectInReviewAsset();
            }
    
            GUILayout.Space(5f);
        }
    }
    
    
    1. Open the AssetManagementUI script you created and replace the contents of the Awake function with the following code:
       m_UI.Add(new OrganizationSelectionExampleUI(m_Behaviour));
       m_UI.Add(new ProjectSelectionExampleUI(m_Behaviour));
       m_UI.Add(new AssetSelectionExampleUI(m_Behaviour));
       m_UI.Add(new UseCaseSendToReviewApproveRejectAssetExampleUI(m_Behaviour));
    

    The code snippet provides UI buttons to trigger the send to review or approve in-review or reject in-review an asset.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)