|
本帖最后由 夜行的猫仔 于 2014-9-30 10:53 编辑
360的支付SDK支持unity,但是官方网站一直没详细的介绍如何使用,(针对android本身开发的文档也不详细)。
通过与360工程师的一段时间的甲流,用NGUI完成了支付SDK的接入,做完以后发现其实挺简单的。
最新 unity使用奇虎360 API登陆充值demo!
1.首先实现QiHoo支付类
这个类是我按照demo自己写的,不复。
[mw_shl_code=csharp,true]using UnityEngine;
using System.Collections;
public class Qihoo : MonoBehaviour {
string mStrUserInfo;
private string mPayOrderId = "abcccccccc";
UILabel l;
// Use this for initialization
void Start ()
{
Application.runInBackground = true;
Application.targetFrameRate = 60;
callAndroidJava ("unityCallOnSceneLoad");
callAndroidJava ("unityCallSetOrientation", false);
}
// Update is called once per frame
public void OnButtonLogin ()
{
callAndroidJava ("unityCallSdkLogin");
}
// Update is called once per frame
public void OnButtonChange ()
{
callAndroidJava ("unityCallSdkSwitchAccount");
}
// Update is called once per frame
public void OnFixedPay (int mount)
{
callAndroidJava ("unityCallSdkFixedPayNumber", mount);
callAndroidJava ("unityCallSdkFixedPay", mPayOrderId);
}
// Update is called once per frame
public void OnFreePay ()
{
callAndroidJava ("unityCallSdkNotFixedPay", mPayOrderId);
}
public void OnOpenBBS ()
{
callAndroidJava ("unityCallSdkBBS");
}
// Update is called once per frame
public void Onphone()
{
callAndroidJava ("unityCallSdkBindNumber");
}
public void OnBBSpost ()
{
callAndroidJava ("unityCallSdkBBSPost");
}
// Update is called once per frame
public void OnQuite ()
{
callAndroidJava ("unityCallSdkQuit");
}
void setUserInfo (string strUserInfo)
{
mStrUserInfo = strUserInfo;
}
void callAndroidJava (string methodName, params object[] args)
{
#if UNITY_ANDROID
AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
jo.Call (methodName, args);
#endif
}
}
[/mw_shl_code]
其中callAndroidJava()函数是Unity调用java的中转站。
2.绑定QiHoo类在Main Camera上
这个设定可以在eclipse修改参数实现的,我才用了默认值。
|
|