Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
@@ -53,6 +53,7 @@ //transform.Find("Panel/Button (1)").GetComponent<Button>().onClick.AddListener(OnClickResetBtn); if (Application.platform == RuntimePlatform.Android) { //GetetDeviceIMEI();//获取安卓手机IMEI @@ -74,15 +75,27 @@ { waitTime = 2f; OnClickLoginBtn(); loginNext(); } else { waitTime = 0f; //第一次启动,初始化并且埋点 TDAA_SDKManager.Ins.SDKInit(ChannelID.Gm.ToString()); TDAA_SDKManager.Ins.Statistics(1);//成功加载登陆界面的人数 //TDAA_SDKManager.Ins.SDKInit(ChannelID.Gm.ToString()); //TDAA_SDKManager.Ins.Statistics(1);//成功加载登陆界面的人数 } } void loginNext() { progressSlider.gameObject.SetActive(true); startBtn.gameObject.SetActive(false); AudioSourceManager.Ins.Play(AudioEnum.UI); TDAA_SDKManager.Ins.Statistics(2);//埋点 GameConfig.isFirstStart = false; StartCoroutine(loginMy()); } float waitTime; @@ -129,14 +142,18 @@ { if (!isLogining) { progressSlider.gameObject.SetActive(true); startBtn.gameObject.SetActive(false); // CoderM: 在这里要使用SDK来进行登录了 SDKCallBack.ins.setNextAction("login", loginNext); SDKManager.ins.sdk.login(); AudioSourceManager.Ins.Play(AudioEnum.UI); TDAA_SDKManager.Ins.Statistics(2);//埋点 //progressSlider.gameObject.SetActive(true); //startBtn.gameObject.SetActive(false); GameConfig.isFirstStart = false; StartCoroutine(loginMy()); //AudioSourceManager.Ins.Play(AudioEnum.UI); //TDAA_SDKManager.Ins.Statistics(2);//埋点 //GameConfig.isFirstStart = false; //StartCoroutine(loginMy()); } else { Assets/Scripts/GameSdk.meta
New file @@ -0,0 +1,8 @@ fileFormatVersion: 2 guid: 455084f426849e349a389fc3420b5d03 folderAsset: yes DefaultImporter: externalObjects: {} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/BaseSdk.cs
New file @@ -0,0 +1,177 @@ namespace UKTSDK { public class BaseSdk { public virtual void changeAccount() { throw new System.NotImplementedException(); } public virtual void enterShareAndFeed(string arg) { throw new System.NotImplementedException(); } public virtual void getGameFriends() { throw new System.NotImplementedException(); } public virtual void getUserInfo() { throw new System.NotImplementedException(); } public virtual void initSdk() { throw new System.NotImplementedException(); } public virtual void killGame() { throw new System.NotImplementedException(); } public virtual void login() { throw new System.NotImplementedException(); } public virtual void logout() { throw new System.NotImplementedException(); } public virtual void recharge(string arg) { throw new System.NotImplementedException(); } public virtual void sendMessageToPlatform(string arg) { throw new System.NotImplementedException(); } public virtual void setCallBackClazz(string caller,string funcName) { throw new System.NotImplementedException(); } public virtual void showUserAuthentication() { throw new System.NotImplementedException(); } } /** 角色相关信息 */ public class RoleInfo { /** 事件类型 */ public int dataType = 1; /** 角色ID */ public string roleID = ""; /** 角色名称 */ public string roleName = ""; /** 角色等级 */ public string roleLevel = ""; /** 服务器id */ public int zoneId = 1; /** 服务器名称 */ public string zoneName = ""; /** 创建角色时间 */ public string roleCTime = ""; /** 角色升级时间 */ public string roleLevelMTime = ""; /** 角色当前元宝数量 */ public int goldNum = 0; /** vip等级 */ public int vipLevel = 0; /** 战斗力 */ public int power = 0; /** 自定义事件 */ public string selfMsg = ""; } /** 角色操作类型 */ public enum RoleInfoCtrlType { /** 自定义数据 */ sendSelfMsg = 0, /** 选择服务器 */ selectServer = 1, /** 创建角色 */ createRole = 2, /** 进入游戏 */ JoinGame = 3, /** 等级提升 */ lvUp = 4, /** 退出游戏 */ logOut = 5, /** 点击登录按钮 */ clickLoginBtn = 6, /** 到达选服页面 */ selectSvrView = 7 } /** 设备相关信息 */ public class DeviceInfo { /** 网络类型 */ public string net_type = ""; /** 设备类型 */ public string device_type = "android"; /** ip地址 */ public string ip = ""; /** 系统版本号 */ public string os_version = ""; /** 系统类型 */ public string os_type = "android"; /** 手机内存 */ public string ram = ""; /** 渠道标识 */ public string channel = ""; /** 安卓设备IMEI */ public string imei = ""; /** 安卓设备安卓ID */ public string android_id = ""; } public class PayVo { /** 商品ID */ public int itemID = 0; /** 商品内购id */ public string productid = ""; /** 商品名 */ public string itemName = ""; /** 商品价格/分 */ public int amount = 0; /** 大区ID */ public int areaID = 0; /** 服务器ID */ public int svrID = 0; /** 服务器名 */ public string svrName = ""; /** 渠道ID */ public int channelId = 0; /** 角色ID */ public string userId = ""; /** 角色名 */ public string userName = ""; /** 角色等级 */ public int userLvl = 0; /** 账号ID */ public string accountId = ""; /** 扩展参数 */ public string otherExt = ""; /** 第三方支付类型 */ public string payExt = ""; /** 自定义订单 */ public string payForm = ""; public string getJsonStr() { return ConvertJson.ToJson(this); } } } Assets/Scripts/GameSdk/BaseSdk.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 3d2701e8106807041b01275526d437b1 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/IUKTSdk.cs
New file @@ -0,0 +1,45 @@ /** * CoderM: 这个接口类,用来定义与安卓交互必须实现的一些接口内容 * * */ public interface IUKTSdk { // 初始化SDK void initSdk(); // 登录 void login(); // 登出 void logout(); // 切换账号 void changeAccount(); // 获取用户信息 void getUserInfo(); // 获取好友列表 void getGameFriends(); // 发送自定义消息 void sendMessageToPlatform(string arg); // 支付 void recharge(string arg); // 分享 void enterShareAndFeed(string arg); void killGame(); // 拉起实名认证 void showUserAuthentication(); // 设置一个回调类 (//这个方法暂时有争议,先保留,不一定会用到) void setCallBackClazz(string caller, string funcName); } Assets/Scripts/GameSdk/IUKTSdk.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 919c87c05e1998e4492ea16e35a9f163 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/JSON.cs
New file @@ -0,0 +1,318 @@ using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Reflection; using System.Collections; using System.Data.Common; public class ConvertJson { #region 私有方法 /// <summary> /// 过滤特殊字符 /// </summary> private static string String2Json(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.Length; i++) { char c = s.ToCharArray()[i]; switch (c) { case '\"': sb.Append("\\\""); break; case '\\': sb.Append("\\\\"); break; case '/': sb.Append("\\/"); break; case '\b': sb.Append("\\b"); break; case '\f': sb.Append("\\f"); break; case '\n': sb.Append("\\n"); break; case '\r': sb.Append("\\r"); break; case '\t': sb.Append("\\t"); break; default: sb.Append(c); break; } } return sb.ToString(); } /// <summary> /// 格式化字符型、日期型、布尔型 /// </summary> private static string StringFormat(string str, Type type) { if (type == typeof(string)) { str = String2Json(str); str = "\"" + str + "\""; } else if (type == typeof(DateTime)) { str = "\"" + str + "\""; } else if (type == typeof(bool)) { str = str.ToLower(); } else if (type != typeof(string) && string.IsNullOrEmpty(str)) { str = "\"" + str + "\""; } return str; } #endregion #region List转换成Json /// <summary> /// List转换成Json /// </summary> public static string ListToJson<T>(IList<T> list) { object obj = list[0]; return ListToJson<T>(list, obj.GetType().Name); } /// <summary> /// List转换成Json /// </summary> public static string ListToJson<T>(IList<T> list, string jsonName) { StringBuilder Json = new StringBuilder(); if (string.IsNullOrEmpty(jsonName)) jsonName = list[0].GetType().Name; Json.Append("{\"" + jsonName + "\":["); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { T obj = Activator.CreateInstance<T>(); PropertyInfo[] pi = obj.GetType().GetProperties(); Json.Append("{"); for (int j = 0; j < pi.Length; j++) { Type type = pi[j].GetValue(list[i], null).GetType(); Json.Append("\"" + pi[j].Name.ToString() + "\":" + StringFormat(pi[j].GetValue(list[i], null).ToString(), type)); if (j < pi.Length - 1) { Json.Append(","); } } Json.Append("}"); if (i < list.Count - 1) { Json.Append(","); } } } Json.Append("]}"); return Json.ToString(); } #endregion #region 对象转换为Json /// <summary> /// 对象转换为Json /// </summary> /// <param name="jsonObject">对象</param> /// <returns>Json字符串</returns> public static string ToJson(object jsonObject) { string jsonString = "{"; PropertyInfo[] propertyInfo = jsonObject.GetType().GetProperties(); for (int i = 0; i < propertyInfo.Length; i++) { object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject, null); string value = string.Empty; if (objectValue is DateTime || objectValue is Guid || objectValue is TimeSpan) { value = "'" + objectValue.ToString() + "'"; } else if (objectValue is string) { value = "'" + ToJson(objectValue.ToString()) + "'"; } else if (objectValue is IEnumerable) { value = ToJson((IEnumerable)objectValue); } else { value = ToJson(objectValue.ToString()); } jsonString += "\"" + ToJson(propertyInfo[i].Name) + "\":" + value + ","; } jsonString.Remove(jsonString.Length - 1, jsonString.Length); return jsonString + "}"; } #endregion #region 对象集合转换Json /// <summary> /// 对象集合转换Json /// </summary> /// <param name="array">集合对象</param> /// <returns>Json字符串</returns> public static string ToJson(IEnumerable array) { string jsonString = "["; foreach (object item in array) { jsonString += ToJson(item) + ","; } jsonString.Remove(jsonString.Length - 1, jsonString.Length); return jsonString + "]"; } #endregion #region 普通集合转换Json /// <summary> /// 普通集合转换Json /// </summary> /// <param name="array">集合对象</param> /// <returns>Json字符串</returns> public static string ToArrayString(IEnumerable array) { string jsonString = "["; foreach (object item in array) { jsonString = ToJson(item.ToString()) + ","; } jsonString.Remove(jsonString.Length - 1, jsonString.Length); return jsonString + "]"; } #endregion #region DataSet转换为Json /// <summary> /// DataSet转换为Json /// </summary> /// <param name="dataSet">DataSet对象</param> /// <returns>Json字符串</returns> public static string ToJson(DataSet dataSet) { string jsonString = "{"; foreach (DataTable table in dataSet.Tables) { jsonString += "\"" + table.TableName + "\":" + ToJson(table) + ","; } jsonString = jsonString.TrimEnd(','); return jsonString + "}"; } #endregion #region Datatable转换为Json /// <summary> /// Datatable转换为Json /// </summary> /// <param name="table">Datatable对象</param> /// <returns>Json字符串</returns> public static string ToJson(DataTable dt) { StringBuilder jsonString = new StringBuilder(); jsonString.Append("["); DataRowCollection drc = dt.Rows; for (int i = 0; i < drc.Count; i++) { jsonString.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { string strKey = dt.Columns[j].ColumnName; string strValue = drc[i][j].ToString(); Type type = dt.Columns[j].DataType; jsonString.Append("\"" + strKey + "\":"); strValue = StringFormat(strValue, type); if (j < dt.Columns.Count - 1) { jsonString.Append(strValue + ","); } else { jsonString.Append(strValue); } } jsonString.Append("},"); } jsonString.Remove(jsonString.Length - 1, 1); jsonString.Append("]"); return jsonString.ToString(); } /// <summary> /// DataTable转换为Json /// </summary> public static string ToJson(DataTable dt, string jsonName) { StringBuilder Json = new StringBuilder(); if (string.IsNullOrEmpty(jsonName)) jsonName = dt.TableName; Json.Append("{\"" + jsonName + "\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Type type = dt.Rows[i][j].GetType(); Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + StringFormat(dt.Rows[i][j].ToString(), type)); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); return Json.ToString(); } #endregion #region DataReader转换为Json /// <summary> /// DataReader转换为Json /// </summary> /// <param name="dataReader">DataReader对象</param> /// <returns>Json字符串</returns> public static string ToJson(DbDataReader dataReader) { StringBuilder jsonString = new StringBuilder(); jsonString.Append("["); while (dataReader.Read()) { jsonString.Append("{"); for (int i = 0; i < dataReader.FieldCount; i++) { Type type = dataReader.GetFieldType(i); string strKey = dataReader.GetName(i); string strValue = dataReader[i].ToString(); jsonString.Append("\"" + strKey + "\":"); strValue = StringFormat(strValue, type); if (i < dataReader.FieldCount - 1) { jsonString.Append(strValue + ","); } else { jsonString.Append(strValue); } } jsonString.Append("},"); } dataReader.Close(); jsonString.Remove(jsonString.Length - 1, 1); jsonString.Append("]"); return jsonString.ToString(); } #endregion } Assets/Scripts/GameSdk/JSON.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 62e17fc04d92a34449fe42e836914a16 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/SDKCallBack.cs
New file @@ -0,0 +1,71 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using LitJson; public class SDKCallBack : MonoBehaviour { public static SDKCallBack ins; public List<Action> list_Action = new List<Action>(); public List<string> list_callBackName = new List<string>(); public Dictionary<string, Action> dic = new Dictionary<string, Action>(); public void Awake() { ins = this; SDKManager.ins.sdk.setCallBackClazz("SDKCallBack", "AndroidCallBack"); // 在这里开始初始化SDK SDKManager.ins.sdk.initSdk(); } public void setNextAction(string act,Action func) { if (!dic.ContainsKey(act)) { dic.Add(act, func); } } // 安卓所有的回调方法都通过这里通知Unity public void AndroidCallBack(string arg) { Debug.Log("安卓返回值===>"+arg); JsonData data = JsonMapper.ToObject(arg); //loginData = JsonMapper.ToObject(value); if (data.ContainsKey("action")) { string act = data["action"].ToString(); Debug.Log(act); if(act == "login") { LoginResult(act); } } } void LoginResult(string act) { Action func = dic[act]; func?.Invoke(); } void Chongzhi() { } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } } Assets/Scripts/GameSdk/SDKCallBack.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 0639fa72bc8665d4faaed2dfea0c467b MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/SDKManager.cs
New file @@ -0,0 +1,53 @@ using UKTSDK; using UnityEngine; public sealed class SDKManager { private int sdkType = 0; private BaseSdk _sdk; public BaseSdk sdk { set { } get { if (_sdk == null) { Debug.Log(sdkType); if (sdkType == 0) { _sdk = new SDK_PC(); } else if(sdkType == 1) { _sdk = new SDK_AND(); } else { _sdk = new SDK_IOS(); } } return _sdk; } } private SDKManager() { // 宏定义应该是预编译的,这里在预编译的时候保存一下 #if UNITY_IOS sdkType = 2; #elif UNITY_ANDROID sdkType = 1; #elif UNITY_EDITOR sdkType = 0; #endif } public static SDKManager ins { get { return Nested.instance; } } private class Nested { // 显式静态构造告诉C#编译器 // 未标记类型BeforeFieldInit static Nested() { } internal static readonly SDKManager instance = new SDKManager(); } } Assets/Scripts/GameSdk/SDKManager.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 55006010cd9179d4ca1559c668c3949b MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/SDK_AND.cs
New file @@ -0,0 +1,83 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UKTSDK; using System; public class SDK_AND : BaseSdk, IUKTSdk { AndroidJavaClass jc; AndroidJavaObject androidInstance; //单例 public SDK_AND() { try { jc = new AndroidJavaClass("com.unity3d.player.UnityPlayerActivity"); androidInstance = jc.GetStatic<AndroidJavaObject>("instance"); Debug.Log("获取SDK成功"); } catch (Exception e) { Debug.LogError("初始化错误:" + e.ToString()); } } public override void changeAccount() { androidInstance.Call<int>("unityCall", "changeAccount","",""); } public override void enterShareAndFeed(string arg) { androidInstance.Call<int>("unityCall", "enterShareAndFeed", "string arg",""); } public override void getGameFriends() { androidInstance.Call<int>("unityCall", "getGameFriends", "", ""); } public override void getUserInfo() { androidInstance.Call<int>("unityCall", "getUserInfo", "", ""); } public override void initSdk() { androidInstance.Call<int>("unityCall","initSdk", "", ""); } public override void killGame() { androidInstance.Call<int>("unityCall", "killGame", "", ""); } public override void login() { androidInstance.Call<int>("unityCall", "login", "", ""); } public override void logout() { androidInstance.Call<int>("unityCall", "logout", "", ""); } public override void recharge(string arg) { androidInstance.Call<int>("unityCall", "recharge","testArg",""); } public override void sendMessageToPlatform(string arg) { androidInstance.Call<int>("unityCall", "sendMessageToPlatform", arg,""); } public override void setCallBackClazz(string caller, string funcName) { androidInstance.Call<int>("unityCall", "setCallBackClazz", caller, funcName); } public override void showUserAuthentication() { androidInstance.Call<int>("unityCall", "showUserAuthentication"); } } Assets/Scripts/GameSdk/SDK_AND.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 361ba94a20a390747ba42e4f3843cca6 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/SDK_IOS.cs
New file @@ -0,0 +1,54 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UKTSDK; public class SDK_IOS : BaseSdk, IUKTSdk { public override void changeAccount() { } public override void enterShareAndFeed(string arg) { } public override void getGameFriends() { } public override void getUserInfo() { } public override void initSdk() { } public override void killGame() { } public override void login() { } public override void logout() { } public override void recharge(string arg) { } public override void sendMessageToPlatform(string arg) { } public override void setCallBackClazz(string caller, string funcName) { } public override void showUserAuthentication() { } } Assets/Scripts/GameSdk/SDK_IOS.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 71caea59036684b40876d9a4a0abb400 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/GameSdk/SDK_PC.cs
New file @@ -0,0 +1,60 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UKTSDK; public class SDK_PC : BaseSdk, IUKTSdk { public override void changeAccount() { } public override void enterShareAndFeed(string arg) { } public override void getGameFriends() { } public override void getUserInfo() { } public override void initSdk() { Debug.Log("模拟初始化SDK"); } public override void killGame() { } public override void login() { Debug.Log("模拟PC登录游戏"); SDKCallBack.ins.AndroidCallBack("{\"action\":\"login\"}"); } public override void logout() { } public override void recharge(string arg) { Debug.Log("模拟充值===> \n" + arg); } public override void sendMessageToPlatform(string arg) { Debug.Log("模拟上报数据===> \n" + arg); } public override void setCallBackClazz(string caller, string funcName) { Debug.Log("设置回调调用方式===>" + caller + " ==> " + funcName); } public override void showUserAuthentication() { } } Assets/Scripts/GameSdk/SDK_PC.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 56c81444ab8c10540ba8a4178dc464c0 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Assets/Scripts/Manager/ManagerRoot.cs
@@ -18,6 +18,7 @@ DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10); root = new GameObject("ManagerRoot"); root.AddComponent<SDKCallBack>(); root.AddComponent<DoNotDestory>(); root.AddComponent<MasterSocket>(); root.AddComponent<TDAA_SDKManager>(); Assets/Scripts/UI/FinalPanel/FinalHttp.cs
@@ -55,6 +55,8 @@ keyValues.Add("level", level);//等级,默认1就行 keyValues.Add("extra", waveInfo);//1关 1波 HttpHelper.Request(this, url, HttpHelper.MethodType.POST, keyValues, delegate (object value) { if (value != null)