Appearance
Appearance
MetaplayClientOptions
, which is passed to MetaplayClient.Initialize
from userland code, and MetaplaySDKConfig
have been refactored, with some variables removed (ConnectionOptions
, LoggingOptions
, DebuggingOptions
) and others moved within the inner classes.IEnvironmentConfigProvider
internally in MetaplaySDK.Start
, MetaplayClientState.DefaultCreatePlayerContext
, MetaplayClientState.OnSharedGameConfigUpdated
and in MetaplayConnection.CreateConnection
.ConnectionConfig
and ConnectionDelegate
have been moved from MetaplayClientOptions.MetaplayConnectionOptions
to MetaplayClientOptions
.EnvironmentConfig
.MetaplayClient.Initialize
can be hard-coded into a custom environment config provider (see DeploymentConfig
example below) or set in EnvironmentConfigs.json if using the DefaultEnvironmentConfigProvider
.MetaplayClient.Initialize
is called. ConnectionConfig
and ConnectionDelegate
.MetaplayDefinesPreprocessor
has been deprecated.IEnvironmentConfigProvider
that provides an EnvironmentConfig
(see below for compatibility with DeploymentConfig
).DefaultEnvironmentConfigProvider
by populating and committing EnvironmentConfigs.json
(created by default in Assets/Resources/Metaplay/Editor).Assets/Code/MetaplayIntegration/DeploymentConfigToEnvironmentConfigProvider.cs
.DeploymentConfig
version and customizations.MetaplayClient.Initialize
to DeploymentConfigToEnvironmentConfigProvider.GetCurrent
.DeploymentConfig
usage can be left as is.using Metaplay.Core.Client;
using System;
using System.Collections.Generic;
using System.Linq;
public class DeploymentConfigToEnvironmentConfigProvider : IEnvironmentConfigProvider
{
public void InitializeSingleton() { }
public EnvironmentConfig GetCurrent()
{
var deploymentSpec =
DeploymentConfig.Instance.Specs.Find(spec => spec.Id == DeploymentConfig.Instance.SelectedSpecId);
if (deploymentSpec != null)
{
EnvironmentConfig environmentConfig = new EnvironmentConfig()
{
Id = deploymentSpec.Id,
ConnectionEndpointConfig = new ConnectionEndpointConfig()
{
ServerHost = deploymentSpec.ServerHost,
ServerPort = deploymentSpec.ServerPort,
ServerPortForWebSocket = deploymentSpec.ServerPortForWebSocket,
EnableTls = deploymentSpec.EnableTls,
BackupGateways = new List<Metaplay.Core.Client.ServerGatewaySpec>(
deploymentSpec.BackupGateways.Select(
spec => new Metaplay.Core.Client.ServerGatewaySpec(spec.Id, spec.ServerHost,
spec.ServerPort))),
CdnBaseUrl = deploymentSpec.CdnBaseUrl,
CommitIdCheckRule = deploymentSpec.CommitIdCheckRule,
},
ClientDebugConfig = new ClientDebugConfig()
{
EnablePlayerConsistencyChecks = deploymentSpec.PlayerConsistencyChecks,
LogLevel = deploymentSpec.LogLevel,
LogLevelOverrides = deploymentSpec.LogLevelOverrides.Select(spec =>
new Metaplay.Core.Client.LogLevelOverrideSpec(spec.LogLevel, spec.ChannelName)).ToList(),
PlayerChecksumGranularity = ChecksumGranularity.PerActionSingleTickPerFrame,
},
ClientGameConfigBuildApiConfig = new ClientGameConfigBuildApiConfig()
{
#if UNITY_EDITOR
AdminApiBaseUrl = deploymentSpec.AdminApiBaseUrl,
GameConfigPublishPolicy =
(Metaplay.Core.Client.GameConfigPublishPolicy)deploymentSpec.GameConfigPublishPolicy,
AdminApiAuthenticationTokenProvider =
(Metaplay.Core.Client.AuthenticationTokenProvider)deploymentSpec.AdminApiAuthenticationTokenProvider,
AdminApiCredentialsPath = deploymentSpec.AdminApiCredentialsPath,
AdminApiOAuth2Settings = new Metaplay.Core.Client.OAuth2AuthorizationServerSpec()
{
ClientId = deploymentSpec.AdminApiOAuth2Settings.ClientId,
AuthorizationEndpoint = deploymentSpec.AdminApiOAuth2Settings.AuthorizationEndpoint,
TokenEndpoint = deploymentSpec.AdminApiOAuth2Settings.TokenEndpoint,
Audience = deploymentSpec.AdminApiOAuth2Settings.Audience,
LocalCallbackUrls = new List<string>(deploymentSpec.AdminApiOAuth2Settings.LocalCallbackUrls),
}
#endif
}
};
return environmentConfig;
}
else
{
throw new ArgumentException(
$"DeploymentConfig with Id '{DeploymentConfig.Instance.SelectedSpecId}' could not be found!");
}
}
}
The default environment config provider (DefaultEnvironmentConfigProvider
) stores the environment configs in a JSON file, which can be edited with a text editor or with the built-in Unity editor window. The JSON file is built into separate JSON files that only contain a filtered version of selected environments, which by default is only the active environment. Setting the active environment is easy from both the editor and from CI pipelines.
Metaplay/Environment Configs
menu.EnvironmentConfig
class to add custom environment-specific variables (see example in Idler: CustomExtendedEnvironmentConfig
).DefaultEnvironmentConfigProvider
to customize provider behavior (simple example: customizing file paths).DefaultEnvironmentConfigProvider
's active environment can be set in different ways: Metaplay/Environment Configs
editor window-MetaplayActiveEnvironmentId=offline
).METAPLAY_ACTIVE_ENVIRONMENT_ID
to the chosen environment ID.DefaultEnvironmentConfigProvider.BuildEnvironmentConfigs(string activeEnvironmentId, string[] includedEnvironmentsIds)
method from your build pipeline.BuildEnvironmentConfigs.json
file and a BuildActiveEnvironmentId.txt
file.DefaultEnvironmentConfigBuilder
does the build automatically in OnPreprocessBuild
using: -MetaplayActiveEnvironmentId=
, if found.METAPLAY_ACTIVE_ENVIRONMENT_ID
, if found.DefaultEnvironmentConfigProvider.BuildEnvironmentConfigs
is called manually from your custom build method before BuildPipeline.BuildPlayer
or the built environment config files are created in any other way, the automatic build will not use the editor-set active environment. The command line argument and environment variable CI overrides will still always trigger the automatic environment config build, and therefore overwrite any already existing files.BuildEnvironmentConfigs
call or any other means, the automatic build will be skipped. The CI overrides will still happen and overwrite any files that exist.DefaultEnvironmentConfigBuilder
also automatically deletes the built files in OnPostProcessBuild
.