Environments API
Manage logical data partitions using the Environments API.
Read time 1 minuteLast updated 17 hours ago
Environments are logical partitions for Unity Gaming Services that contain data associated with your project. This section focuses on the Environments API in the Core package. The access point to the Environments API is through the
EnvironmentsApinamespace Unity.Services.Core.Environments.Editor{ public class EnvironmentsApi { public static IEnvironmentsApi Instance { get; } }}
Environment Selector
The Environment Selector sets the current environment for all supported services. To select an environment in the Unity Editor:- Go to Edit > Project Settings > Services > Environments.
- In the Editor Environment field, select the environment to use.
Active environment
You can access the active environment as the name or GUID. ThePropertyChangednamespace Unity.Services.Core.Environments.Editor{ public class EnvironmentsApi { public string ActiveEnvironmentName { get; set; } public System.Nullable<System.Guid> ActiveEnvironmentId { get; } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; }}
Environment management
TheEnvironmentsApinamespace Unity.Services.Core.Editor.Environments{ public class EnvironmentsApi { public System.Collections.Generic.IReadOnlyCollection<EnvironmentInfo> Environments { get; } public System.Threading.Tasks.Task RefreshAsync(); public void SetActiveEnvironment(EnvironmentInfo environment); public System.Threading.Tasks.Task<ValidationResult> ValidateEnvironmentAsync(); }}
Build and runtime
At build and runtime, the chosen environment uses a priority fallback mechanism to choose the correct environment:InitializationOptions"production"InitializationOptionsUI components
TheEnvironmentView
<ui:UXML xmlns:uie="UnityEditor.UIElements" xmlns:coreUi="Unity.Services.Core.Editor.Environments.UI" editor-extension-mode="True"> <uie:Toolbar> <coreUi:EnvironmentView /> </uie:Toolbar></ui:UXML>