|
|
@@ -0,0 +1,297 @@
|
|
|
+#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;
|
|
|
+
|
|
|
+ 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 = "SDKHwQuick";
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (gameRoleInfo != null)
|
|
|
+ {
|
|
|
+ Dictionary<string, SDKMgr.ProductInfo> cfgs = SDKMgr.Instance.ProductInfos;
|
|
|
+
|
|
|
+ string pice = amount.ToString("F2");
|
|
|
+
|
|
|
+ if (cfgs.ContainsKey(pice))
|
|
|
+ {
|
|
|
+ SDKMgr.ProductInfo productInfo = cfgs[pice];
|
|
|
+ m_AJO.Call("pay", cpOrderId, amount.ToString(), productInfo.ID, productInfo.Name, gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, extrasParams, goodsName,productInfo.Other);
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ m_YouYiListener.OnPayFailed();
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ m_AJO.Call("levelLog", gameRoleInfo.roleId.ToString(), gameRoleInfo.roleName, gameRoleInfo.serverId.ToString(), gameRoleInfo.serverName, gameRoleInfo.roleLv, gameRoleInfo.openServerTime.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void ExitGame()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|