您的位置:首页 > 移动开发 > Unity3D

Unity3D渠道接入系列:(一)移动游戏基地

2014-12-17 18:22 176 查看
声明:保留所有权利,任何网络转载行为,必须通过邮件取得作者许可。

前言:

最近做Unity渠道接入,挺简单的事还是研究了2、3天。

把花费了我的生命研究获得的一点经验分享一下,如果能帮到你,节约了你的研究时间,等于消耗在我生命的时间从你那获得了补偿。

所以写这个系列,希望能帮到大家。

移动游戏基地在网上的资料,相较来说是最少的,所以做为系列的开篇。

参考资料:

1、自填集成移动和游戏单机sdk的小坑(http://www.unitymanual.com/blog-19372-1861.html

2、Android支付接入(二):移动游戏基地(http://blog.sina.com.cn/s/blog_9498c8b60101bclq.html

相关配置:

移动游戏基地sdk版本:安卓网游V21119版SDK,发布日期:2014/10/17

开发平台和工具:windows,unity3D4.5.2,ADT-bundle-windows-x86_64-20140702

要点:

1、自己定义java类的Application,导出为jar包。并在AndroidManifest.xml配置对应的Application定义。

步骤:

1、编写java类定义Application,并导出为jar包“unity_sojoys_cmgcV21119.1.20141216.jar”,放入unity工程目录:\Plugins\Android\bin\

注意包名:com.sojoys.example

2、在unity中\Plugins\Android\AndroidManifest.xml文件修改定义。

注意:application一节[android:name=".CmgameApplication"]定义为之前jar包中定义的application名称。

<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:name=".CmgameApplication" android:debuggable="true">
<activity android:name="cn.cmgame.billing.api.GameOpenActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CHINAMOBILE_OMS_GAME" />
<category android:name="android.intent.category.CHINAMOBILE_GAMES" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>


3、因为移动基地sdk提供相应的unity实现类CmBillingAndroid,所以直接实现逻辑调用即可。

以下代码举例实际的使用

public void _init ()
{
#if CMGC && UNITY_ANDROID
CmBillingAndroid.Instance.InitializeApp();
CmBillingAndroid.Instance.SetLoginListener(this.gameObject.name,"OnLoginResult");
#endif
}

void OnLoginResult (string result)
{
log.logDebug ("LoginResult=" + result);
int resultCode = CmBillingAndroid.LoginResult.UNKOWN;
int.TryParse (result, out resultCode);
if (resultCode == CmBillingAndroid.LoginResult.SUCCESS_IMPLICIT || resultCode == CmBillingAndroid.LoginResult.SUCCESS_EXPLICIT) {
OnLoginSuccess (result);
} else {
OnLoginFail (result);
}
}

void OnLoginSuccess (string result)
{
log.logDebug ("OnLoginSuccess");
if (result == null || result.Trim () == "") {
<span style="white-space:pre">	</span>	return;
}
ChannelModel.Channel_Logined = true;
}
/// <summary>
/// 登陆失败回调
/// </summary>
/// <param name="msg">Message.</param>
void OnLoginFail (string msg)
{
log.logWarnning ("OnLoginFail:{0}", msg);
ChannelModel.Channel_Logined = false;
}


4、Unity打包。

注意包名和第一步定义的包名一致: com.sojoys.example



5、至此,移动基地unity接入完成。

=============

Nick

2014年12月23日
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: