EN

# 六、开发者常见问题

# 6.1 老版本迁移

由于从Unity SDK v1.3.0开始,奇遇SDK优化了产品架构,解耦了XR SDK和Platform SDK。如果您从奇遇UnityXR SDK v1.2.1及以前的版本,升级到Platform v1.0.0,请按以下步骤升级:

# A. 导入新版本QIYU XR Plugin和QIYU Platform SDK

图6.1.1 升级QIYU XR Plugin和 QIYU Platform SDK

# B. 更新QIYU SDK Samples和QIYU Platform Samples

如果工程中已导入SDK Sample,会由于类名变更导致报错(如下图6.2所示),此时点击Samples-Update,重新导入QIYU SDK Samples和QIYU Platform Samples,会自动修复Samples中的代码错误。

图6.1.2 升级后,由于类名变更导致报错
图6.1.3 更新 QIYU XR Samples
图6.1.4 更新 QIYU Platform Samples

# C. 修改工程代码

如果游戏中调用了以下类名、接口名,在升级后会导致编译错误,请手动修改为新的名称。具体的变化如下:

# 1. 平台接口类名

由QiyuSDKCorePlugins改为QiyuXRPlatformPlugin

# 2. 平台初始化接口

新版本初始化直接传入回调函数,删除老的监听设置方式,并且类名由QiyuPlugin变为QiyuXRPlatform,QiyuPlugin.MessageResult变为QiyuMessage.GetRequestResult,QiyuPlugin.SDKInit变为QiyuMessage.SDKInit

  • v1.2.1及以前的版本:
//First, you need to monitor the SDK initialization result
QiyuMessageListener.AddListener(MessageCode.QiyuSdkInit, ret =>
{
 QiyuPlugin.MessageResult<QiyuPlugin.SDKInit> msg = ret[0] as QiyuPlugin.MessageResult<QiyuPlugin.SDKInit>;
	if (msg.IsSuccess())
 	{

	}
});
	//Initialize SDK
	QiyuPlugin.InitQiyuSDK(
	 "", //AppId 从开发者后台的APP页面获取
	 ""); //App秘钥 从开发者后台的APP页面获取
  • Platform v1.0.0及以后的版本:
using Qiyu.Sdk.Platform;
			QiyuXRPlatform.InitQiyuSDK(QiyuMessage.GetRequestResult<QiyuMessage.SDKInit>((msg) =>
	{
		if (msg.IsSuccess())
		{
		 Debug.Log( $" InitQiyuSDK OK!");
		}
		else
		{
		Debug.Log( $" InitQiyuSDK Failed! code:{msg.code}");
		}
	}),
	 "", //AppId 从开发者后台的APP页面获取 例:23068292
	 ""); //App秘钥 从开发者后台的APP页面获取 例:d4093dadce6fa082d2727ebd7bb9eab1

注意:SDK 升级到v1.2.1 及以上版本后,需要从“开发者平台-管理 - 我的应用 - API”获取应用密钥(app_secret),并更新初始化接口中的App Secret信息

# 3. 用户信息获取

  • v1.2.1及以前的版本:
// Get Qiyu Account information
public void GetIQIYIAccountInfo()
    {
        if (QiyuPlugin.IsQiyuAccountLogin())
        {
            QiyuPlugin.GetQiyuAccountInfo(
           RequestCallbackByJson<QiyuPlugin.MessageResult<QiyuPlugin.QiyuAccountInfo>>.Create((QiyuPlugin.MessageResult<QiyuPlugin.QiyuAccountInfo> msg) =>
           {
               if (msg.IsSuccess())
               {
                   uid.text = msg.data.uid;
                   name.text = msg.data.name;
                   pic.text = msg.data.icon;
               }
           }));
        }
        else
        {
            //跳转到Home进行登录
            QiyuPlugin.LaunchHome("login", "");
        }
    }
  • Platform v1.0.0及以后的版本:
// Get Qiyu Account information
public void GetQiyuAccountInfo()
    {
        if (QiyuXRPlatform.IsQiyuAccountLogin())
        {
            QiyuXRPlatform.GetQiyuAccountInfo(QiyuMessage.GetRequestResult<QiyuMessage.QiyuAccountInfo>((msg) =>
            {
                if (msg.IsSuccess())
                {
                    uid.text = msg.data.uid;
                    nickName.text = msg.data.name;
                    pic.text = msg.data.icon;
                    Debug.Log(string.Format( " GetQiyuAccountInfo uid is {0},name is {1}", msg.data.uid, msg.data.name));
                }
            }));
        }
        else
        {
            //跳转到Home进行登录
            QiyuXRPlatform.LaunchHome("login", "");
        }
    }

# 4. 支付初始化接口

新版本支付初始化增加回调函数,并且类名有QiyuPlugin变为QiyuPay。其他支付接口的类名也统一使用QiyuPay

  • v1.2.1及以前的版本:
QiyuPlugin.InitQiyuPay();
QiyuPlugin.GetSkuList(QiyuPlugin.GetRequestResult<List<QiyuPlugin.QiyuPaySkuInfo>>(...)QiyuPlugin.PlaceOrder(QiyuPlugin.GetRequestResult<string>(...)
QiyuPlugin.QueryOrderResult(QiyuPlugin.GetRequestResult<QiyuPlugin.QiyuPayOrderResult>(...)
QiyuPlugin.QueryHistoryOrders(QiyuPlugin.GetRequestResult<QiyuPlugin.QiyuPayHistoryOrders>(...)
  • Platform v1.0.0及以后的版本:
using Qiyu.Sdk.Platform;

QiyuPay.InitQiyuPay(QiyuMessage.GetRequestResult<QiyuMessage.SDKInit>((msg) =>
{
  if (msg.IsSuccess())
  {
   Debug.Log( $" InitQiyuPay OK!");
   textField.text = $"InitQiyuPay OK!";
  }
  else
  {
   Debug.Log( $" InitQiyuPay Failed! code:{msg.code}");
   textField.text = $"InitQiyuPay Failed! code:{msg.code}";
  }
}));
QiyuPay.GetSkuList(QiyuMessage.GetRequestResult<List<QiyuMessage.QiyuPaySkuInfo>>(...)
QiyuPay.PlaceOrder(QiyuMessage.GetRequestResult<string>(...)
QiyuPay.QueryOrderResult(QiyuMessage.GetRequestResult<QiyuMessage.QiyuPayOrderResult>(...)
QiyuPay.QueryHistoryOrders(QiyuMessage.GetRequestResult<QiyuMessage.QiyuPayHistoryOrders>(...)

# 5. QiyuPrefs类

已弃用初始化接口Init(),即开发者在使用数据存档接口时,不再需要优先调用初始化。升级Platform SDK 后,如出现报错(下图5.1.5),请重新导入Sample(下图6.1.6),并去掉游戏中的调用初始化接口的代码。

图6.1.5 升级后报错
图6.1.6 升级sample
  • v1.2.1及以前的版本:
public void GetDeeplinkCallBack(QiyuPlugin.MessageResult<QiyuPlugin.DeepLinkParam> ret)
    {
        Debug.Log(string.Format("QVRDemo:GetDeeplinkCallBack key is {0},value is {1}", ret.data.key, ret.data.value));
    }

public void OnApplicationPause(bool pause)
    {
       if (pause == false)
       {
            if (QiyuPlatform.IsAndroid)
                QiyuPlugin.GetDeepLink(RequestCallbackByJson<QiyuPlugin.MessageResult<QiyuPlugin.DeepLinkParam>>.Create(GetDeeplinkCallBack));
        }
    }

public void GoHomeLogin()
    {
        QiyuPlugin.LaunchHome("login", "");
   }
  • Platform v1.0.0及以后的版本:
void Start()
    {
//其他代码

//Get Deeplink Param
 QiyuXRPlatform.GetDeepLink(QiyuMessage.GetRequestResult<QiyuMessage.DeepLinkParam>(OnGetDeepLink));
}

void OnGetDeepLink(QiyuMessage.MessageResult<QiyuMessage.DeepLinkParam> msg)
    {
        if (msg.IsSuccess() && msg.data != null)
        {
            Debug.Log(string.Format( " OnGetDeepLink key is {0},value is {1}", msg.data.key, msg.data.value));
        }
    }

public void OnApplicationPause(bool pause)
    {
        if (pause == false)
        {
           QiyuXRPlatform.GetDeepLink(QiyuMessage.GetRequestResult<QiyuMessage.DeepLinkParam>(OnGetDeepLink));
       }
    }

public void GoHomeLogin()
    {
       QiyuXRPlatform.LaunchHome("login", "");
    }