docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Get started with Asset SDK

    Asset Manager is a Unity Cloud service that allows you to manage your assets in the cloud. Use Assets SDK to perform the following:

    • Create and read an asset project.
    • Create, read, and update:
      • assets
      • datasets
      • files
    • Download files.
    • Create, read, update, and delete collections.
    • Search your assets in an asset project or organization based on a set of criteria.
    • Group and count assets based on a set of criteria.
    • Link and unlink assets from projects.
    • Link and unlink assets from collections.
    • Start transformations on datasets.
    • Create, read, update and delete the field definitions of an organization.
    • Add and remove the accepted values of field definitions of the Selection type.

    This section explains how to set up a basic scene and script to initialize and use the Unity Assets package with Asset Manager. The script performs a search for all assets of the selected project and displays the results in a GUI.

    Before you begin, verify you meet the prerequisites.

    Requirements

    To use Assets SDK, you must have a minimum role of Asset Manager Viewer in your Unity Cloud project.

    Integrate the package in a Unity project

    To integrate the Unity Cloud Assets package in a Unity project, do the following:

    • Set up a Unity scene
    • Create an AssetManager
    • Create the PlatformServices
    • Create the behavior for managing assets
    • Create an interface for all UI scripts

    Set up a Unity scene

    To set up a Unity scene, follow these steps:

    1. In your Unity Project window, go to Assets > Scenes.
    2. Select and hold the Assets/Scenes folder.
    3. Go to Create > Scene.
    4. Name the new scene AssetManagementExample.

    Create an AssetManager

    To create an AssetManager object, first create a MonoBehaviour class to manage the UI and then create the AssetManager object in your scene as follows:

    1. Create a MonoBehaviour class to manage the UI:
      1. In your Unity Project window, go to Assets > Scripts.
      2. Create an Assets/Scripts folder if the folder does not already exist.
      3. Select and hold the Assets/Scripts folder.
      4. Go to Create > C# Script.
      5. Name your script AssetManagementUI.
    2. Create the AssetManager object in your scene:
      1. In the AssetManagementExample scene that you created here, select and hold the hierarchy and select Create Empty.
      2. Name your new object AssetManager.
      3. Select the AssetManager object and add the AssetManagementUI script that you created here.

    Create the PlatformServices

    To set up the necessary components, follow these steps:

    1. Implement the platform services pattern. Read more about dependency injection in the Identity package documentation.
    2. Update the PlatformServices class in your PlatformServices.cs file as shown below:
    
    using System;
    using System.Threading.Tasks;
    using Unity.Cloud.Assets;
    using Unity.Cloud.AppLinking.Runtime;
    using Unity.Cloud.Common;
    using Unity.Cloud.Common.Runtime;
    using Unity.Cloud.Identity;
    using Unity.Cloud.Identity.Runtime;
    
    public static class PlatformServices
    {
        /// <summary>
        /// Returns a <see cref="ICompositeAuthenticator"/>.
        /// </summary>
        public static ICompositeAuthenticator Authenticator { get; private set; }
    
        /// <summary>
        /// Returns a <see cref="IAuthenticationStateProvider"/>.
        /// </summary>
        public static IAuthenticationStateProvider AuthenticationStateProvider => Authenticator;
    
        /// <summary>
        /// Returns an <see cref="IOrganizationRepository"/>.
        /// </summary>
        public static IOrganizationRepository OrganizationRepository => Authenticator;
    
        /// <summary>
        /// Returns an <see cref="IAssetRepository"/>.
        /// </summary>
        public static IAssetRepository AssetRepository { get; private set; }
    
        public static void Create()
        {
            var httpClient = new UnityHttpClient();
            var serviceHostResolver = UnityRuntimeServiceHostResolverFactory.Create();
            var playerSettings = UnityCloudPlayerSettings.Instance;
            var platformSupport = PlatformSupportFactory.GetAuthenticationPlatformSupport();
    
            var compositeAuthenticatorSettings = new CompositeAuthenticatorSettingsBuilder(httpClient, platformSupport, serviceHostResolver, playerSettings)
                .AddDefaultPkceAuthenticator(playerSettings)
                .Build();
    
            Authenticator = new CompositeAuthenticator(compositeAuthenticatorSettings);
    
            var serviceHttpClient = new ServiceHttpClient(httpClient, Authenticator, playerSettings);
    
            AssetRepository = AssetRepositoryFactory.Create(serviceHttpClient, serviceHostResolver);
        }
    
        /// <summary>
        /// A Task that initializes all platform services.
        /// </summary>
        /// <returns>A Task.</returns>
        public static async Task InitializeAsync()
        {
            await Authenticator.InitializeAsync();
        }
    
        /// <summary>
        /// Shuts down all platform services.
        /// </summary>
        public static void ShutDownServices()
        {
            (Authenticator as IDisposable)?.Dispose();
            Authenticator = null;
        }
    }
    
    

    This script does the following:

    • Initializes an ICompositeAuthenticator interface for signing in and verifying your identity when you access the HTTP services.
    • Initializes an IOrganizationRepository interface to fetch your organizations.
    • Initializes an IAssetRepository interface to interact with the Asset Manager service.

    To initialize the PlatformServices class in your scene, 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.
    4. Name your script PlatformServicesInitialization.
    5. In the AssetManagementExample scene that you created here, select and hold the hierarchy and select Create Empty.
    6. Name your new object PlatformServices.
    7. Select the PlatformServices object and add the PlatformServicesInitialization script that you created here.
    8. Update the PlatformServicesInitialization class in your PlatformServicesInitialization.cs file as shown below:
    
    using System.Threading.Tasks;
    using UnityEngine;
    
    /// <summary>
    /// A Mono behaviour class to initialize services and dependencies for the Unity Cloud platform.
    /// </summary>
    [DefaultExecutionOrder(int.MinValue)]
    public class PlatformServicesInitialization : MonoBehaviour
    {
        void Awake()
        {
            DontDestroyOnLoad(gameObject);
            PlatformServices.Create();
        }
    
        async Task Start()
        {
            await PlatformServices.InitializeAsync();
        }
    }
    
    

    This script does the following:

    • Triggers the creation of the services available in the PlatformServices class.
    • Initializes the ICompositeAuthenticator interface.

    To clean up the PlatformServices class in your scene, 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.
    4. Name your script PlatformServicesShutdown.
    5. Select the PlatformServices object that you created here and add the PlatformServicesShutdown script that you created in the previous step.
    6. Update the PlatformServicesShutdown class in your PlatformServicesShutdown.cs file as shown below:
    
    using UnityEngine;
    
    /// <summary>
    /// A Mono behaviour class to shut down services and dependencies from the Unity Cloud platform.
    /// </summary>
    [DefaultExecutionOrder(int.MaxValue)]
    public class PlatformServicesShutdown : MonoBehaviour
    {
        void OnDestroy()
        {
            PlatformServices.ShutDownServices();
        }
    }
    
    

    This script cleans up of the services when the scene is closed.

    Create the behavior for managing assets

    To create the behavior for asset management, 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.
    4. Name your script AssetManagementBehaviour.
    5. Open the AssetManagementBehaviour script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Unity.Cloud.Assets;
    using Unity.Cloud.Identity;
    using UnityEngine;
    
    public class AssetManagementBehaviour
    {
        const int k_DefaultCancellationTimeout = 5000;
    
        IOrganization[] m_AvailableOrganizations;
    
        CancellationTokenSource m_ProjectCancellationTokenSrc = new();
        CancellationTokenSource m_AssetCancellationTokenSrc = new();
    
        public IOrganization[] AvailableOrganizations => m_AvailableOrganizations;
        public IOrganization CurrentOrganization { get; private set; }
        public bool IsOrganizationSelected => CurrentOrganization != null;
        public List<IAssetProject> AvailableProjects { get; } = new();
        public IAssetProject CurrentProject { get; private set; }
        public bool IsProjectSelected => CurrentProject != null;
        public List<IAsset> AvailableAssets { get; } = new();
        public IAsset CurrentAsset { get; set; }
    
        public void Clear()
        {
            m_ProjectCancellationTokenSrc.Cancel();
            m_ProjectCancellationTokenSrc.Dispose();
            m_AssetCancellationTokenSrc.Cancel();
            m_AssetCancellationTokenSrc.Dispose();
    
            CurrentAsset = null;
            CurrentProject = null;
            CurrentOrganization = null;
        }
    
        public void SetSelectedOrganization(IOrganization organization)
        {
            CurrentAsset = null;
            CurrentProject = null;
            CurrentOrganization = organization;
            if (CurrentOrganization != null)
            {
                _ = GetProjectsAsync();
            }
        }
    
        public void SetSelectedProject(IAssetProject project)
        {
            CurrentAsset = null;
            CurrentProject = project;
            if (CurrentProject != null)
            {
                _ = GetAssetsAsync();
            }
        }
    
        public async Task GetOrganizationsAsync()
        {
            m_AvailableOrganizations = null;
    
            try
            {
                var organizations = new List<IOrganization>();
                var organizationsAsyncEnumerable = PlatformServices.OrganizationRepository.ListOrganizationsAsync(Range.All);
                await foreach (var organization in organizationsAsyncEnumerable)
                {
                    organizations.Add(organization);
                }
    
                m_AvailableOrganizations = organizations.ToArray();
            }
            catch (OperationCanceledException oe)
            {
                Debug.Log(oe);
            }
            catch (AggregateException e)
            {
                Debug.LogError(e.InnerException);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
    
        public async Task GetProjectsAsync()
        {
            m_ProjectCancellationTokenSrc.Cancel();
            m_ProjectCancellationTokenSrc.Dispose();
            m_ProjectCancellationTokenSrc = new CancellationTokenSource();
    
            try
            {
                var token = m_ProjectCancellationTokenSrc.Token;
                var projects = PlatformServices.AssetRepository.ListAssetProjectsAsync(CurrentOrganization.Id, Range.All, token);
    
                AvailableProjects.Clear();
                CurrentProject = null;
    
                await foreach (var project in projects)
                {
                    AvailableProjects.Add(project);
                }
            }
            catch (OperationCanceledException oe)
            {
                Debug.Log(oe);
            }
            catch (AggregateException e)
            {
                Debug.LogError(e.InnerException);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
    
        public async Task GetAssetsAsync(IAsset currentAsset = null)
        {
            m_AssetCancellationTokenSrc.Cancel();
            m_AssetCancellationTokenSrc.Dispose();
            m_AssetCancellationTokenSrc = new CancellationTokenSource();
    
            try
            {
                var token = m_AssetCancellationTokenSrc.Token;
                var assets = CurrentProject.QueryAssets().ExecuteAsync(token);
    
                AvailableAssets.Clear();
                CurrentAsset = currentAsset;
    
                await foreach (var asset in assets)
                {
                    AvailableAssets.Add(asset);
                }
            }
            catch (OperationCanceledException oe)
            {
                Debug.Log(oe);
            }
            catch (AggregateException e)
            {
                Debug.LogError(e.InnerException);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
    }
    
    

    This script does the following:

    • Provides the functions to list and select organizations.
    • Provides the functions to list and select projects.
    • Performs a basic search to list the assets of the selected project.

    Create an interface for all UI scripts

    To create the interface for all UI scripts, 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.
    4. Name your script IAssetManagementUI.
    5. Open the IAssetManagementUI script that you created in the previous step and replace the contents of the file with the following code sample:
    
    public interface IAssetManagementUI
    {
        public void OnGUI();
    }
    
    

    How do I...?

    Select an organization

    To create a UI for selecting an organization, do the following:

    1. In your Unity Project window, go to Assets > Scripts.
    2. Select and hold the Assets/Scripts folder.
    3. Go to Create > C# Script.
    4. Name your script OrganizationSelectionExampleUI.
    5. Open the OrganizationSelectionExampleUI script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using UnityEngine;
    
    public class OrganizationSelectionExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
    
        Vector2 m_OrganizationListScrollPosition;
    
        public OrganizationSelectionExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
        }
    
        public void OnGUI()
        {
            if (m_Behaviour.IsOrganizationSelected) return;
    
            // Refresh the org list
            if (GUILayout.Button("Refresh", GUILayout.Width(60)))
            {
                _ = m_Behaviour.GetOrganizationsAsync();
                return;
            }
    
            GUILayout.Space(15f);
    
            // If an organization is not selected, list those available.
            SelectAnOrganization();
        }
    
        void SelectAnOrganization()
        {
            GUILayout.BeginVertical();
    
            GUILayout.Label("Available Organizations:");
            GUILayout.Space(5f);
    
            var availableOrganizations = m_Behaviour.AvailableOrganizations;
            if (availableOrganizations != null)
            {
                m_OrganizationListScrollPosition = GUILayout.BeginScrollView(m_OrganizationListScrollPosition, GUILayout.ExpandHeight(true), GUILayout.Width(250));
    
                for (var i = 0; i < availableOrganizations.Length; ++i)
                {
                    if (GUILayout.Button(availableOrganizations[i].Name))
                    {
                        m_Behaviour.SetSelectedOrganization(availableOrganizations[i]);
                    }
                }
    
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("Loading...");
            }
    
            GUILayout.EndVertical();
        }
    }
    
    

    This script generates a UI to list and select organizations.

    Select a project

    To create a UI for selecting a project, do the following:

    1. In your Unity Project window, go to Assets > Scripts.
    2. Select and hold the Assets/Scripts folder.
    3. Go to Create > C# Script.
    4. Name your script ProjectSelectionExampleUI.
    5. Open the ProjectSelectionExampleUI script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using UnityEngine;
    
    public class ProjectSelectionExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
    
        Vector2 m_ProjectListScrollPosition;
    
        public ProjectSelectionExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
        }
    
        public void OnGUI()
        {
            if (!m_Behaviour.IsOrganizationSelected || m_Behaviour.IsProjectSelected) return;
    
            GUILayout.BeginVertical();
    
            // Go back to select a different scene.
            if (GUILayout.Button("Back"))
            {
                m_Behaviour.SetSelectedOrganization(null);
                return;
            }
    
            // Refresh the project list
            if (GUILayout.Button("Refresh", GUILayout.Width(60)))
            {
                _ = m_Behaviour.GetProjectsAsync();
                return;
            }
    
            GUILayout.EndVertical();
    
            GUILayout.Space(15f);
    
            SelectAProject();
        }
    
        void SelectAProject()
        {
            GUILayout.BeginVertical();
    
            GUILayout.Label($"{m_Behaviour.CurrentOrganization.Name}");
            GUILayout.Space(15f);
    
            GUILayout.Label("Available Projects:");
            GUILayout.Space(5f);
    
            var projects = m_Behaviour.AvailableProjects.ToArray();
            if (projects.Length > 0)
            {
                m_ProjectListScrollPosition = GUILayout.BeginScrollView(m_ProjectListScrollPosition, GUILayout.ExpandHeight(true), GUILayout.Width(250));
    
                for (var i = 0; i < projects.Length; ++i)
                {
                    if (GUILayout.Button(projects[i].Name))
                    {
                        m_Behaviour.SetSelectedProject(projects[i]);
                        Debug.Log($"Selected project: {projects[i].Descriptor.ProjectId}");
                    }
                }
    
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("No projects found.");
            }
    
            GUILayout.EndVertical();
        }
    }
    
    

    This script generates a UI to list and select projects.

    Select an asset

    To create a UI for selecting an asset, do the following:

    1. In your Unity Project window, go to Assets > Scripts.
    2. Select and hold the Assets/Scripts folder.
    3. Go to Create > C# Script.
    4. Name your script AssetSelectionExampleUI.
    5. Open the AssetSelectionExampleUI script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using UnityEngine;
    
    public class AssetSelectionExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
    
        Vector2 m_AssetListScrollPosition;
    
        public AssetSelectionExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
        }
    
        public void OnGUI()
        {
            if (!m_Behaviour.IsProjectSelected) return;
    
            // Go back to select a different scene.
            if (GUILayout.Button("Back"))
            {
                m_Behaviour.SetSelectedProject(null);
                return;
            }
    
            GUILayout.Space(15f);
    
            GUILayout.BeginVertical();
    
            GUILayout.Label($"{m_Behaviour.CurrentOrganization.Name} >> {m_Behaviour.CurrentProject.Name}");
            GUILayout.Space(15f);
    
            SelectAnAsset();
    
            GUILayout.EndVertical();
        }
    
        void SelectAnAsset()
        {
            GUILayout.Label($"Available Assets ({m_Behaviour.AvailableAssets.Count}):");
            GUILayout.Space(5f);
    
            var assets = m_Behaviour.AvailableAssets.ToArray();
            if (assets.Length > 0)
            {
                m_AssetListScrollPosition = GUILayout.BeginScrollView(m_AssetListScrollPosition, GUILayout.ExpandHeight(true), GUILayout.Width(250));
    
                for (var i = 0; i < assets.Length; ++i)
                {
                    GUI.enabled = m_Behaviour.CurrentAsset?.Descriptor.AssetId != assets[i].Descriptor.AssetId;
    
                    if (GUILayout.Button(assets[i].Name))
                    {
                        m_Behaviour.CurrentAsset = assets[i];
                        Debug.Log($"Selected: {assets[i].Descriptor.AssetId}");
                    }
    
                    GUI.enabled = true;
                }
    
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("No assets found.");
            }
        }
    }
    
    

    This script generates a UI to list and select assets.

    Create an asset

    To create an asset, follow these steps:

    1. Open the AssetManagementBehaviour script that you created here.
    2. Add the following code to the end of the class:
    
    public List<IStatusFlow> AvailableStatusFlows { get; private set; }
    
    public async Task GetOrganizationStatusFlows()
    {
        AvailableStatusFlows = null;
    
        try
        {
            var statusFlowsAsync = PlatformServices.AssetRepository.ListStatusFlowsAsync(CurrentOrganization.Id, Range.All, CancellationToken.None);
            AvailableStatusFlows = new List<IStatusFlow>();
            await foreach (var statusFlow in statusFlowsAsync)
            {
                AvailableStatusFlows.Add(statusFlow);
            }
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to get organization status flows. {e}");
            throw;
        }
    }
    
    public async Task CreateAssetAsync(AssetType assetType, string statusFlowId)
    {
        var assetCreation = new AssetCreation("GrayTexture_0")
        {
            Description = "Documentation example asset creation.",
            Type = assetType,
            StatusFlowDescriptor = string.IsNullOrEmpty(statusFlowId) ? null : new StatusFlowDescriptor(CurrentOrganization.Id, statusFlowId)
        };
    
        try
        {
            var asset = await CurrentProject.CreateAssetAsync(assetCreation, CancellationToken.None);
            if (asset != null)
            {
                await GetAssetsAsync(asset);
            }
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to create asset. {e}");
            throw;
        }
    }
    
    

    This code snippet does the following:

    • Provides a method to fetch the status flows of the selected organization.
    • Provides a method to create a new asset with a type and a status flow.

    To create a UI for asset creation, 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.
    4. Name your script UseCaseAssetCreationExampleUI.
    5. Open the UseCaseAssetCreationExampleUI script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using UnityEngine;
    using Unity.Cloud.Assets;
    using Unity.Cloud.Common;
    using Unity.Cloud.Identity;
    
    public class UseCaseAssetCreationExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
        readonly string[] m_AssetTypeList;
    
        public UseCaseAssetCreationExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
            m_AssetTypeList = AssetTypeExtensions.AssetTypeList().ToArray();
        }
    
        public void OnGUI() { }
    }
    
    
    1. In the same script, replace the OnGUI function with the following code:
    
    OrganizationId m_OrganizationId;
    AssetType m_SelectedType = AssetType.Other;
    int m_SelectedStatusFlow;
    
    public void OnGUI()
    {
        if (!m_Behaviour.IsProjectSelected) return;
    
        if (m_OrganizationId != m_Behaviour.CurrentOrganization.Id)
        {
            m_OrganizationId = m_Behaviour.CurrentOrganization.Id;
            _ = m_Behaviour.GetOrganizationStatusFlows();
        }
    
        GUILayout.BeginVertical();
    
        GUILayout.BeginHorizontal();
    
        GUILayout.Label("Type: ");
    
        var type = (int) m_SelectedType;
        type = GUILayout.SelectionGrid(type, m_AssetTypeList, 4, GUILayout.Width(280));
        if (type != -1)
            m_SelectedType = (AssetType) type;
    
        GUILayout.EndHorizontal();
    
        GUILayout.BeginHorizontal();
    
        GUILayout.Label("Status Flow:");
    
        if (m_Behaviour.AvailableStatusFlows == null)
        {
            GUILayout.Label("Loading...");
        }
        else
        {
            var statusFlowNames = m_Behaviour.AvailableStatusFlows.Select(x => x.Name).ToArray();
            m_SelectedStatusFlow = GUILayout.SelectionGrid(m_SelectedStatusFlow, statusFlowNames, 4, GUILayout.Width(280));
        }
    
        GUILayout.EndHorizontal();
    
        if (GUILayout.Button("Create new asset", GUILayout.Width(150f)))
        {
            var statusFlowId = string.Empty;
            if (m_Behaviour.AvailableStatusFlows != null && m_SelectedStatusFlow >= 0 && m_SelectedStatusFlow < m_Behaviour.AvailableStatusFlows.Count)
            {
                statusFlowId = m_Behaviour.AvailableStatusFlows[m_SelectedStatusFlow].Descriptor.StatusFlowId;
            }
    
            _ = m_Behaviour.CreateAssetAsync(m_SelectedType, statusFlowId);
        }
    
        GUILayout.EndVertical();
    }
    
    

    Integrate the UI scripts

    To bring all your UI scripts into a single MonoBehaviour, open the AssetManagementUI script that you created here and replace the contents of the file with the following code sample:

    
    using System;
    using System.Collections.Generic;
    using Unity.Cloud.Identity;
    using UnityEngine;
    
    public class AssetManagementUI : MonoBehaviour
    {
        protected readonly AssetManagementBehaviour m_Behaviour = new();
        protected readonly List<IAssetManagementUI> m_UI = new();
    
        IAuthenticationStateProvider m_AuthenticationStateProvider;
    
        bool IsLoggedIn => m_AuthenticationStateProvider?.AuthenticationState == AuthenticationState.LoggedIn;
    
        protected virtual void Awake()
        {
            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 UseCaseAssetCreationExampleUI(m_Behaviour));
        }
    
        void Start()
        {
            m_AuthenticationStateProvider = PlatformServices.AuthenticationStateProvider;
            m_AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
        }
    
        void OnDestroy()
        {
            if (m_AuthenticationStateProvider != null)
            {
                m_AuthenticationStateProvider.AuthenticationStateChanged -= OnAuthenticationStateChanged;
            }
    
            m_Behaviour.Clear();
        }
    
        void OnGUI()
        {
            GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
    
            UpdateAuthenticationUI(m_AuthenticationStateProvider.AuthenticationState);
    
            if (!IsLoggedIn)
            {
                GUILayout.EndHorizontal();
                return;
            }
    
            foreach (var ui in m_UI)
            {
                ui.OnGUI();
            }
    
            AdditionalGUI();
    
            GUILayout.FlexibleSpace();
    
            GUILayout.EndHorizontal();
        }
    
        protected virtual void AdditionalGUI()
        {
            // Do more stuff here.
        }
    
        static void UpdateAuthenticationUI(AuthenticationState state)
        {
            GUILayout.BeginVertical();
    
            switch (state)
            {
                case AuthenticationState.AwaitingInitialization:
                    GUILayout.Label("Initializing Service...");
                    break;
    
                case AuthenticationState.AwaitingLogout:
                    GUILayout.Label("Logging out...");
                    break;
    
                case AuthenticationState.LoggedOut:
                    if (GUILayout.Button("Login"))
                    {
                        _ = PlatformServices.Authenticator.LoginAsync();
                    }
    
                    break;
    
                case AuthenticationState.AwaitingLogin:
                    GUILayout.Label("Logging in...");
                    if (GUILayout.Button("Cancel"))
                    {
                        PlatformServices.Authenticator.CancelLogin();
                    }
    
                    break;
    
                case AuthenticationState.LoggedIn:
                    if (GUILayout.Button("Logout"))
                    {
                        _ = PlatformServices.Authenticator.LogoutAsync();
                    }
    
                    break;
    
                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
    
            GUILayout.EndVertical();
        }
    
        void OnAuthenticationStateChanged(AuthenticationState obj)
        {
            if (obj == AuthenticationState.LoggedIn)
            {
                _ = m_Behaviour.GetOrganizationsAsync();
            }
        }
    }
    
    

    This script does the following:

    • Registers to the ICompositeAuthenticator interface to track sign-in changes.
    • Creates an instance of the AssetManagementBehaviour script.
    • Creates instances of the UI scripts for selecting an organization, project, and asset.

    Going further

    Read more about asset management.

    Updating assets

    Read more about updating assets.

    Uploading files

    Read more about uploading files.

    Grouping assets in collections

    Use collections to group of assets within a project. Read more about managing collections.

    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)