logo
0
0
WeChat Login

Remote Config SDK

简介

RemoteConfigSDK包括两部分

  • 面向Client端的Client SDK,用于获取和用户有关的配置信息,用于Runtime。同时内部集成了AccessToken的申请和更新,无需开发者关心。
  • 面向Server端的Server SDK,用于管理App中的配置信息。

认证模式

ClientSDK

ClientSDK采用JWT的认证模式。目前支持两种形式的JWT:

  • 开通了UOS Passport的UOS应用,可以使用Passport的登录方式获取JWT。
  • 未开通UOS Passport的UOS应用,可以使用AuthTokenManager.GenerateAccessToken(string userID)的方式来使用第三方用户ID来获取JWT。

ServerSDK

ServerSDK采用AppId+AppSecret的认证模式


API介绍

GetPlayerSettingsAsync

获取app统一的配置信息

GetPlayerSettingsOverridesAsync

获取和用户相关的配置信息


使用示例

初始化RemoteConfigSDK

  1. 在UOS Launcher中正确配置AppID和AppSecret
  2. 确认所在UOS App是否开启了UOS Passport,然后使用以下方法初始化RemoteConfigSDK。当Passport开启时,传入true,否则传入false
using Unity.UOS.Config;
// 当Passport开启时,传入true,否则传入false
// RemoteConfigSDK.Initialize(false);
RemoteConfigSDK.Initialize(true);

授权

如果使用 Passport

// 当使用 Passport External Login 的情况下, 需要手动登录一下(仅需登录一次)
string userId = "1234"; // 需要登录的 UserId
string personalId = "5678"; // 可选 需要登录的 PersonalId
await AuthTokenManager.ExternalLogin(userId, personalId);

如果不使用 Passport

// 当不使用 UOS Passport 的情况下, 需要手动设置用户授权(仅需设置一次)
string userId = "1234"; // 需要授权的 UserId
await AuthTokenManager.GenerateAccessToken(userId);

ClientSDK

获取app统一的配置信息

var req = new GetPlayerSettingsRequest()
{
    Keys = { "Alice", "Bob", "Charlie" },
    Types_ = { ConfigType.Int, ConfigType.Bool, ConfigType.String },
};

var result = await RemoteConfigSDK.GetPlayerSettingsAsync(req);

if (result.IsSuccess())
{
    GetPlayerSettingsResponse response = result.data;
    // handle it
    Debug.Log("success");
    int i = 1;
    foreach (var entry in response.Settings)
    {
        Debug.Log("item #" + i);
        Debug.Log("key: " + entry.Key);
        Debug.Log("val: " + entry.Value.Value);
        Debug.Log("type: " + entry.Value.Type);
        i++;
    }
}

获取和用户相关的配置信息

// 开发者自定义的结构体
[Serializable]
public class SampleUserAttributes
{
    public string userID;
    public string rank;
}

// 开发者自定义的结构体
[Serializable]
public class SampleAppAttributes
{
    public string packageVersion;
    public bool isDebugBuild;
}

var appAttributes = new SampleUserAttributes
{
    userID = "1234",
    rank = "king"
};

var userAttributes = new SampleAppAttributes
{
    isDebugBuild = false,
    packageVersion = "1.2.3"
};

var req = new GetPlayerOverridesRequest
{
    UserId = "1234",
    PersonaId = "5678",
    IsDebugBuild = false,
    PackageVersion = "1.2.3",
    Attributes = ModelUtil.ConvertToAttributes(appAttributes, userAttributes)
};

var result = await RemoteConfigSDK.GetPlayerSettingsOverridesAsync(req);

if (result.IsSuccess())
{
    GetPlayerOverridesResponse response = result.data;
    // handle it
}

用户可以使用ModelUtil.ConvertToAttributes(object appAttributes, object userAttributes)来将自定义的AppAttributes和UserAttributes转化为SDK需要的Attributes类型(Google.Protobuf.WellKnownTypes.Value)

About

No description, topics, or website provided.
218.00 KiB
0 forks0 stars8 branches2 TagREADMEOther license
Language
C#97.4%
Markdown2%
gitignore0.5%
Others0.1%