|
|
@@ -0,0 +1,443 @@
|
|
|
+#if UNITY_ANDROID
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class YouYiSDKAndroid : SDKBase
|
|
|
+{
|
|
|
+ private AndroidJavaObject m_AJO;
|
|
|
+ private YouYiListener m_YouYiListener;
|
|
|
+ private SDKGameRoleInfo mSDKGameRoleInfo;
|
|
|
+ public YouYiSDKAndroid()
|
|
|
+ {
|
|
|
+ using (AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
|
|
+ {
|
|
|
+ m_AJO = ajc.GetStatic<AndroidJavaObject>("currentActivity");
|
|
|
+ }
|
|
|
+ m_YouYiListener = SDKMgr.Instance.gameObject.AddComponent<YouYiListener>();
|
|
|
+ SDKName = "MIAN_YOU_Android";
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Init()
|
|
|
+ {
|
|
|
+ base.Init();
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("init", "SDKMgr");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_YouYiListener.OnInitFailed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public override void Login()
|
|
|
+ {
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("login");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_YouYiListener.OnLoginFailed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Logout()
|
|
|
+ {
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("switchAccountLogin");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SwitchAccount()
|
|
|
+ {
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("switchAccountLogin");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Pay(int goodsId, string goodsName, string goodsDesc, int count, float amount, string cpOrderId, string extrasParams)
|
|
|
+ {
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ string gameRoleInfo = GetCurRoleInfo();
|
|
|
+ if (gameRoleInfo != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ Dictionary<string, SDKMgr.ProductInfo> cfgs = SDKMgr.Instance.ProductInfos;
|
|
|
+
|
|
|
+ int itemp = Mathf.FloorToInt(amount);
|
|
|
+ string pice = "";
|
|
|
+ if ((itemp + 0.005f) > amount)
|
|
|
+ {
|
|
|
+ pice = itemp.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pice = amount.ToString("F2");
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log("价格 = "+ pice);
|
|
|
+ if (cfgs.ContainsKey(pice))
|
|
|
+ {
|
|
|
+ Debug.Log("有 价格 = " + pice);
|
|
|
+ SDKMgr.ProductInfo productInfo = cfgs[pice];
|
|
|
+
|
|
|
+ GameOrderInfo gameOrderInfo = new GameOrderInfo()
|
|
|
+ {
|
|
|
+ cpOrderId = cpOrderId,
|
|
|
+ goodsId = productInfo.ID,
|
|
|
+ goodsName = productInfo.Name,
|
|
|
+ goodsDesc = goodsDesc,
|
|
|
+ orderAmount = pice,
|
|
|
+ goodsNum = count.ToString(),
|
|
|
+ goinNum = "",
|
|
|
+ cpExtra = extrasParams,
|
|
|
+ callbackUrl = goodsName,
|
|
|
+ };
|
|
|
+ string gameOderString = JsonUtility.ToJson(gameOrderInfo);
|
|
|
+
|
|
|
+
|
|
|
+ m_AJO.Call("pay", gameRoleInfo, gameOderString);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log("没有 价格 = " + pice);
|
|
|
+ m_YouYiListener.OnPayFailed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //m_AJO.Call("pay", cpOrderId, amount.ToString(), goodsId.ToString(), goodsName, gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, extrasParams);
|
|
|
+ else
|
|
|
+ m_YouYiListener.OnPayFailed();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_YouYiListener.OnPayFailed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void CreateRole()
|
|
|
+ {
|
|
|
+ GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+ if (gameRoleInfo == null || !gameRoleInfo.Valid())
|
|
|
+ {
|
|
|
+ Debug.LogError("[YouYiSDK][CreateRole] GameRoleInfo is null or not valid !!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ SetSDKGameRoleInfo(gameRoleInfo);
|
|
|
+ string data = JsonUtility.ToJson(mSDKGameRoleInfo);
|
|
|
+ m_AJO.Call("createRoleLog", data);
|
|
|
+ //m_AJO.Call("createRoleLog", gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, gameRoleInfo.openServerTime.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void EnterGame()
|
|
|
+ {
|
|
|
+ GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+ if (gameRoleInfo == null || !gameRoleInfo.Valid())
|
|
|
+ {
|
|
|
+ Debug.LogError("[YouYiSDK][EnterGame] GameRoleInfo is null or not valid !!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ SetSDKGameRoleInfo(gameRoleInfo);
|
|
|
+ string data = JsonUtility.ToJson(mSDKGameRoleInfo);
|
|
|
+ m_AJO.Call("loginRoleLog", data);
|
|
|
+ // m_AJO.Call("loginRoleLog", gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, gameRoleInfo.openServerTime.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void UpdateRoleLv()
|
|
|
+ {
|
|
|
+ GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+ if (gameRoleInfo == null || !gameRoleInfo.Valid())
|
|
|
+ {
|
|
|
+ Debug.LogError("[YouYiSDK][UpdateRoleLv] GameRoleInfo is null or not valid !!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ SetSDKGameRoleInfo(gameRoleInfo);
|
|
|
+ string data = JsonUtility.ToJson(mSDKGameRoleInfo);
|
|
|
+ m_AJO.Call("levelLog", data);
|
|
|
+ //m_AJO.Call("levelLog", gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, gameRoleInfo.openServerTime.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void ExitGame()
|
|
|
+ {
|
|
|
+ m_AJO.Call("exit");
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Exit()
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Quit()
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void CallInitSuccessCB()
|
|
|
+ {
|
|
|
+ m_YouYiListener.OnInitSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void CallLoginSuccessCB()
|
|
|
+ {
|
|
|
+ m_YouYiListener.StartCheckLogin();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool CheckHasModul(SDKModulType needCheckModulType)
|
|
|
+ {
|
|
|
+ if (needCheckModulType == SDKModulType.EXIT_VIEW)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return base.CheckHasModul(needCheckModulType);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OpenModul(SDKModulType sDKModulType)
|
|
|
+ {
|
|
|
+ if (sDKModulType == SDKModulType.EXIT_VIEW)
|
|
|
+ {
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("exit");
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ base.OpenModul(sDKModulType);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool IsReportAction() { return true; }
|
|
|
+
|
|
|
+ public override void ReportAction(Dictionary<object, object> datas)
|
|
|
+ {
|
|
|
+ base.ReportAction(datas);
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ using (AndroidJavaObject hashMapAJO = DictionaryToJavaHashMap(datas))
|
|
|
+ {
|
|
|
+ m_AJO.Call("reportAction", hashMapAJO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool HasCanEnterServerJudge() { return true; }
|
|
|
+ public override void CanEnterServerJudge(string serverId, string serverName)
|
|
|
+ {
|
|
|
+ base.CanEnterServerJudge(serverId, serverName);
|
|
|
+ if (m_AJO != null)
|
|
|
+ {
|
|
|
+ m_AJO.Call("canEnterServerJudge", serverId, serverName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private AndroidJavaObject DictionaryToJavaHashMap(Dictionary<object, object> datas)
|
|
|
+ {
|
|
|
+ AndroidJavaObject hashMapAJO = new AndroidJavaObject("java.util.HashMap");
|
|
|
+ object[] args = new object[2];
|
|
|
+ System.IntPtr putMethod = AndroidJNIHelper.GetMethodID(
|
|
|
+ hashMapAJO.GetRawClass(), "put",
|
|
|
+ "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
|
|
+ foreach (var data in datas)
|
|
|
+ {
|
|
|
+ AndroidJavaObject key = GetAndroidJavaObject(data.Key);
|
|
|
+ if (key == null) continue;
|
|
|
+ AndroidJavaObject value = GetAndroidJavaObject(data.Value);
|
|
|
+ if (value == null) continue;
|
|
|
+ args[0] = key;
|
|
|
+ args[1] = value;
|
|
|
+ AndroidJNI.CallObjectMethod(
|
|
|
+ hashMapAJO.GetRawObject(),
|
|
|
+ putMethod,
|
|
|
+ AndroidJNIHelper.CreateJNIArgArray(args));
|
|
|
+ key.Dispose();
|
|
|
+ value.Dispose();
|
|
|
+ }
|
|
|
+ return hashMapAJO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AndroidJavaObject GetAndroidJavaObject(object value)
|
|
|
+ {
|
|
|
+ System.Type type = value.GetType();
|
|
|
+ if (type.IsPrimitive)
|
|
|
+ {
|
|
|
+ if (type.Equals(typeof(int)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Integer", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(bool)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Boolean", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(byte)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Byte", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(short)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Short", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(long)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Long", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(float)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Float", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(double)))
|
|
|
+ {
|
|
|
+ double dVal = (double)value;
|
|
|
+ if (dVal > int.MinValue && dVal < int.MaxValue)
|
|
|
+ {
|
|
|
+ int intVal = (int)dVal;
|
|
|
+ if (intVal == dVal)
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Integer", intVal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new AndroidJavaObject("java.lang.Double", value);
|
|
|
+ }
|
|
|
+ if (type.Equals(typeof(char)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.Character", value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (type.Equals(typeof(string)))
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("java.lang.String", value);
|
|
|
+ }
|
|
|
+ else if (type.Equals(typeof(AndroidJavaObject)))
|
|
|
+ {
|
|
|
+ return value as AndroidJavaObject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string GetCurRoleInfo()
|
|
|
+ {
|
|
|
+ string ret = null;
|
|
|
+ SetSDKGameRoleInfo();
|
|
|
+ //GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+ if (mSDKGameRoleInfo != null)
|
|
|
+ {
|
|
|
+ ret = JsonUtility.ToJson(mSDKGameRoleInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetSDKGameRoleInfo(GameRoleInfo gameRoleInfo = null)
|
|
|
+ {
|
|
|
+ if (gameRoleInfo == null)
|
|
|
+ gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+ if (gameRoleInfo == null) return;
|
|
|
+ if (mSDKGameRoleInfo == null)
|
|
|
+ {
|
|
|
+ mSDKGameRoleInfo = new SDKGameRoleInfo(gameRoleInfo);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mSDKGameRoleInfo.Set(gameRoleInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+public class GameOrderInfo
|
|
|
+{
|
|
|
+ public string cpOrderId;
|
|
|
+ public string goodsId;
|
|
|
+ public string goodsName;
|
|
|
+ public string goodsDesc;
|
|
|
+ public string orderAmount;
|
|
|
+ public string goodsNum;
|
|
|
+ public string goinNum;
|
|
|
+ public string cpExtra;
|
|
|
+ public string callbackUrl;
|
|
|
+}
|
|
|
+public class SDKGameRoleInfo
|
|
|
+{
|
|
|
+ // 必填参数
|
|
|
+ public String openId;
|
|
|
+ public int serverId;
|
|
|
+ public String serverName;
|
|
|
+ public String roleId;
|
|
|
+ public String roleName;
|
|
|
+
|
|
|
+ public int roleLv;
|
|
|
+ public long roleCreateTime;
|
|
|
+ public long roleUpLvTime;
|
|
|
+
|
|
|
+ // 非必填参数
|
|
|
+ public int vipLv;
|
|
|
+ public int gender;
|
|
|
+ public int jobId;
|
|
|
+ public String jobName;
|
|
|
+ public long guildId;
|
|
|
+ public String guildName;
|
|
|
+ public int fightPower;
|
|
|
+ public String balance;
|
|
|
+
|
|
|
+
|
|
|
+ // 其它参数
|
|
|
+ public long lastLogoutTime;
|
|
|
+ public long loginTime;
|
|
|
+ public long openServerTime;
|
|
|
+
|
|
|
+ public SDKGameRoleInfo()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ public SDKGameRoleInfo(GameRoleInfo roleInfo)
|
|
|
+ {
|
|
|
+ Set(roleInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Set(GameRoleInfo roleInfo)
|
|
|
+ {
|
|
|
+ // 必填参数
|
|
|
+ openId = roleInfo.openId;
|
|
|
+ serverId = roleInfo.serverId;
|
|
|
+ serverName = roleInfo.serverName;
|
|
|
+ roleId = roleInfo.roleId;
|
|
|
+ roleName = roleInfo.roleName;
|
|
|
+
|
|
|
+ roleLv = roleInfo.roleLv;
|
|
|
+ roleCreateTime = roleInfo.roleCreateTime;
|
|
|
+ roleUpLvTime = roleInfo.roleUpLvTime;
|
|
|
+
|
|
|
+ // 非必填参数
|
|
|
+ vipLv = roleInfo.vipLv;
|
|
|
+ gender = roleInfo.gender;
|
|
|
+ jobId = roleInfo.jobId;
|
|
|
+ jobName = roleInfo.jobName;
|
|
|
+ guildId = roleInfo.guildId;
|
|
|
+ guildName = roleInfo.guildName;
|
|
|
+ fightPower = roleInfo.fightPower;
|
|
|
+ balance = roleInfo.balance;
|
|
|
+
|
|
|
+
|
|
|
+ // 其它参数
|
|
|
+ lastLogoutTime = roleInfo.lastLogoutTime;
|
|
|
+ loginTime = roleInfo.loginTime;
|
|
|
+ openServerTime = roleInfo.openServerTime;
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|