sdk 代码合并

This commit is contained in:
LYP
2024-08-06 16:22:00 +08:00
parent 4f80b73fd0
commit de5c781bd7
15 changed files with 1470 additions and 250 deletions

View File

@@ -7,7 +7,7 @@ using UnityEngine;
namespace tysdk
{
public class TYSdkFacade : MonoBehaviour
public partial class TYSdkFacade : MonoBehaviour
{
public class AccountInfo
{
@@ -30,11 +30,18 @@ namespace tysdk
if (_instance == null)
{
_instance = new GameObject("TYSdkFacade").AddComponent<TYSdkFacade>();
Init();
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
public static void Init()
{
UnityBridgeFunc.InitSDK();
}
/*================================================
@@ -139,190 +146,5 @@ namespace tysdk
UnityBridgeFunc.UnitySetAdBoxUserInfo(strUserId);
UnityBridgeFunc.UnityInitADSConfig();
}
/*================================================
_____ _ _____ _
| ____|_ _____ _ __ | |_ |_ _| __ __ _ ___| | __
| _| \ \ / / _ \ '_ \| __| | || '__/ _` |/ __| |/ /
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
|_____| \_/ \___|_| |_|\__| |_||_| \__,_|\___|_|\_\
=================================================*/
public void EventTrack(int type, string name, string content)
{
#if UNITY_IOS || UNITY_ANDROID
UnityBridgeFunc.GAReportParams(type, name, content);
#endif
}
/*================================================
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
| |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __|
| __/ (_| | |_| | | | | | | __/ | | | |_
|_| \__,_|\__, |_| |_| |_|\___|_| |_|\__|
|___/
=================================================*/
//TODO
public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string orderId, string extraInfo)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
#if UNITY_EDITOR
await Task.Yield();
var result = new PaymentInfo()
{
code = "0",
msg = "success",
count = count,
orderId = orderId,
productId = prodId,
price = prodPrice
};
return result;
#elif UNITY_ANDROID
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnow(_accountInfo.strUserId, prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnow(_accountInfo.strUserId, prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#endif
}
//支付的回调
public void PayResult(string json)
{
Debug.Log("[TYSdkFacade] pay callback:");
var jresult = JObject.Parse(json);
var result = new PaymentInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["errStr"].ToString();
if (callbacks.TryGetValue("PayResult", out var action))
{
action.Invoke(result);
callbacks.Remove("PayResult");
}
}
/*================================================
_ _____ _____
/ \|_ _|_ _|
/ _ \ | | | |
/ ___ \| | | |
/_/ \_\_| |_|
=================================================*/
public bool IsAttAccepted()
{
return UnityBridgeFunc.GetATT() == 1;
}
public async Task<ATTInfo> RequestATT()
{
#if UNITY_EDITOR || UNITY_ANDROID
await Task.Yield();
return new ATTInfo(){isAccepted = true};
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<ATTInfo>();
callbacks.Add("RequestATT", (ITYSdkCallback callback) =>
{
taskSource.SetResult((ATTInfo)callback);
});
UnityBridgeFunc.RequestATT();
return await taskSource.Task;
#endif
}
public void RequestATTResult(string r)
{
if (callbacks.TryGetValue("RequestATT", out var action))
{
action.Invoke(new ATTInfo(){isAccepted = r == "1"});
callbacks.Remove("RequestATT");
}
}
/*================================================
_ ____
/ \ | _ \
/ _ \ | | | |
/ ___ \| |_| |
/_/ \_\____/
=================================================*/
public void InitAdCallback(string jstr)
{
try{
var jobj = JObject.Parse(jstr);
if(jobj["code"].ToString() == "0")
UnityEngine.Debug.Log($"[TYSdkFacade] InitAdCallback Success");
else
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback Failed ");
}
catch(Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback error: {e.Message}");
}
}
public void LoadAdCallback(string jstr)
{
try
{
var adLoadinfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ADLoadInfo>(jstr);
GContext.Publish(adLoadinfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] LoadAdCallback error: {e.Message}");
}
}
public void ShowAdCallback(string jstr)
{
try
{
var adShowInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ShowADInfo>(jstr);
GContext.Publish(adShowInfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] ShowAdCallback error: {e.Message}");
}
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using asap.core;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
_ ____
/ \ | _ \
/ _ \ | | | |
/ ___ \| |_| |
/_/ \_\____/
=================================================*/
public void InitAdCallback(string jstr)
{
try{
var jobj = JObject.Parse(jstr);
if(jobj["code"].ToString() == "0")
UnityEngine.Debug.Log($"[TYSdkFacade] InitAdCallback Success");
else
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback Failed ");
}
catch(Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback error: {e.Message}");
}
}
public void LoadAdCallback(string jstr)
{
try
{
var adLoadinfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ADLoadInfo>(jstr);
GContext.Publish(adLoadinfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] LoadAdCallback error: {e.Message}");
}
}
public void ShowAdCallback(string jstr)
{
try
{
var adShowInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ShowADInfo>(jstr);
GContext.Publish(adShowInfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] ShowAdCallback error: {e.Message}");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 179ddafea9354cadbfabca342e552139
timeCreated: 1722855804

View File

@@ -0,0 +1,49 @@
using System.Threading.Tasks;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
_ _____ _____
/ \|_ _|_ _|
/ _ \ | | | |
/ ___ \| | | |
/_/ \_\_| |_|
=================================================*/
public bool IsAttAccepted()
{
return UnityBridgeFunc.GetATT() == 1;
}
public async Task<ATTInfo> RequestATT()
{
#if UNITY_EDITOR || UNITY_ANDROID
await Task.Yield();
return new ATTInfo(){isAccepted = true};
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<ATTInfo>();
callbacks.Add("RequestATT", (ITYSdkCallback callback) =>
{
taskSource.SetResult((ATTInfo)callback);
});
UnityBridgeFunc.RequestATT();
return await taskSource.Task;
#endif
}
public void RequestATTResult(string r)
{
if (callbacks.TryGetValue("RequestATT", out var action))
{
action.Invoke(new ATTInfo(){isAccepted = r == "1"});
callbacks.Remove("RequestATT");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8f92075f5f98490ca94ae4984ac0aa21
timeCreated: 1722855901

View File

@@ -0,0 +1,131 @@
using System;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
_____ _ _____ _
| ____|_ _____ _ __ | |_ |_ _| __ __ _ ___| | __
| _| \ \ / / _ \ '_ \| __| | || '__/ _` |/ __| |/ /
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
|_____| \_/ \___|_| |_|\__| |_||_| \__,_|\___|_|\_\
=================================================*/
public void EventTrack(int type, string name, string content)
{
#if UNITY_IOS || UNITY_ANDROID
UnityBridgeFunc.GAReportParams(type, name, content);
#endif
}
}
public enum GATrackType
{
GA_TRACK = 1, //默认类型
GA_CION = 2, //金流相关事件
GA_PAY = 3, //支付相关事件
GA_GAME = 4, //游戏行为
GA_LOGIN = 5, //登录注册相关事件
GA_PUSH = 6, //推送相关事件
GA_ADBOX = 7, //adbox相关事件
GA_PREFORMANCE = 8, //性能上报相关事件
GA_SDK = 9, //SDK相关事件
GA_ABTest = 10, //abtest相关事件
}
public class GAEvent : IDisposable
{
private GATrackType eventType;
private string eventName;
bool AFSend = true;
public static string ABTestValue = "0";
private JObject content = new JObject();
public GAEvent(GATrackType eventType, string eventName, bool AFSend = true)
{
this.eventType = eventType;
this.eventName = eventName;
this.AFSend = AFSend;
}
public GAEvent AddContent(string key, string value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, int value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, bool value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, float value)
{
content[key] = value;
return this;
}
public void Dispose()
{
content["ABTestValue"] = ABTestValue;
TYSdkFacade.Instance.EventTrack((int)eventType, eventName, content.ToString());
}
/*
*GA_TRACK默认类型
*GA_CION金流相关事件
*GA_PAY支付相关事件
*GA_GAME游戏行为
*GA_LOGIN登录注册相关事件
*GA_PUSH推送相关事件
*GA_ADBOXadbox相关事件
*GA_PREFORMANCE性能上报相关事件
*GA_SDKSDK相关事件
*GA_ABTestabtest相关事件
*GA_PROFILE设置用户特征
*/
//TOD SDK
public static GAEvent TackEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_TRACK, eventName, afSend);
}
public static GAEvent PushEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_PUSH, eventName, afSend);
}
public static GAEvent CionEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_CION, eventName, afSend);
}
public static GAEvent PayEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_PAY, eventName, afSend);
}
public static GAEvent GameEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_GAME, eventName, afSend);
}
public static GAEvent LoginEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_LOGIN, eventName, afSend);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 18459dcf8d5a40dc80ffae5333a6b0c9
timeCreated: 1722855439

View File

@@ -0,0 +1,36 @@
// using System;
// using AppLovinMax;
// using UnityEngine;
//
// namespace tysdk
// {
// public partial class TYSdkFacade : MonoBehaviour
// {
// #if UNITY_IOS
// public const string AppOpenAdUnitId = "4cea568d96f9c9d3";
// #else
// public const string AppOpenAdUnitId = "4cea568d96f9c9d3";
// #endif
// public string[] TestIds = new string[] { "4cea568d96f9c9d3","cd71530d3089c3ec","1a2e78ad8aa5690f"};
// public int adIndex = 0;
// public async void PlayAd()
// {
// await AppMaxManager.Instance().MaxInit();
// if (adIndex >= TestIds.Length - 1)
// {
// adIndex = 0;
// }
//
// adIndex++;
// Debug.LogError("广告id::::::::" + TestIds[adIndex]);
// if (MaxSdk.IsRewardedAdReady(TestIds[adIndex]))
// {
// MaxSdk.ShowRewardedAd(TestIds[adIndex]);
// }
// else
// {
// MaxSdk.LoadRewardedAd(TestIds[adIndex]);
// }
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d16ab34307a144e0bf15b770e3824309
timeCreated: 1722854562

View File

@@ -0,0 +1,133 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
| |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __|
| __/ (_| | |_| | | | | | | __/ | | | |_
|_| \__,_|\__, |_| |_| |_|\___|_| |_|\__|
|___/
=================================================*/
public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count,string pType)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
var orderId = System.Guid.NewGuid().ToString();
var extraDic = new Dictionary<string,object>() {
{"paytime" , System.DateTime.UtcNow.Ticks},
{"sum" , float.Parse(prodPrice) * count},
};
string extraInfo = Newtonsoft.Json.JsonConvert.SerializeObject(extraDic);
//to base64
extraInfo = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(extraInfo));
#if UNITY_EDITOR
await Task.Yield();
var result = new PaymentInfo()
{
code = "0",
msg = "success",
count = count,
orderId = orderId,
productId = prodId,
price = prodPrice
};
return result;
#elif UNITY_ANDROID
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo,pType);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#elif UNITY_IOS
var taskSource = new TaskCompletionSource<PaymentInfo>();
callbacks.Add("PayResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((PaymentInfo)callback);
});
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo,pType);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;
result.productId = prodId;
result.price = prodPrice;
return result;
#endif
}
//支付的回调
public void PayResult(string json)
{
Debug.Log("[TYSdkFacade] pay callback:" + json);
var jresult = JObject.Parse(json);
var result = new PaymentInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["errStr"].ToString();
if (callbacks.TryGetValue("PayResult", out var action))
{
action.Invoke(result);
callbacks.Remove("PayResult");
}
}
// Get Pay list
public async Task<SKUDetail> ThirdExtend()
{
if (!IsLoggedIn) return new SKUDetail() { code = "-1", msg = "未登录" };
#if UNITY_EDITOR
await Task.Yield();
var result = new SKUDetail();
return result;
#elif UNITY_ANDROID
var taskSource = new TaskCompletionSource<SKUDetail>();
callbacks.Add("PayTypeResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((SKUDetail)callback);
});
UnityBridgeFunc.ThirdExtend();
var result = await taskSource.Task;
return result;
#endif
}
//商品列表的回调
public void PayTypeResult(string json)
{
Debug.Log("[thirdExtend] pay callback:");
var jresult = JObject.Parse(json);
var result = new SKUDetail();
result.code = jresult["code"].ToString();
result.msg = jresult["thirdExtend_errStr"].ToString();
if (callbacks.TryGetValue("PayTypeResult", out var action))
{
action.Invoke(result);
callbacks.Remove("PayTypeResult");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41b6dc16dbab43388317bf9ff032cdca
timeCreated: 1722855703

View File

@@ -1,6 +1,13 @@
namespace tysdk
{
public enum EAccoutType
{
hwGoogle,
hwFacebook,
hwGuest,
none
}
public interface ITYSdkCallback { }
public class LoginInfo : ITYSdkCallback
@@ -28,6 +35,18 @@ namespace tysdk
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
public class SKUDetail: ITYSdkCallback
{
public string code;
public string msg;
public string name;
public string description;
public string price;
public string productId;
public string ourProductId;
public string currency_code;
}
public class ATTInfo : ITYSdkCallback
{

View File

@@ -4,16 +4,12 @@ using UnityEngine;
namespace tysdk
{
public enum EAccoutType
{
hwGoogle,
hwFacebook,
hwGuest,
}
public static class UnityBridgeFunc
{
#if UNITY_EDITOR
//初始化sdk
public static void InitSDK(){}
//更新登录支付域名
public static void UnityResetServerUrl(string url){}
@@ -24,13 +20,20 @@ namespace tysdk
public static void UnityGetIdentityFun(string type){}
public static void UnityLoginOut(){}
//支付new
public static void UnityKnowNew(string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo, string pType) { }
//支付
public static void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo){}
//获取商品列表
public static void ThirdExtend() { }
//打点
public static void SetGaUserInfo(string userId){}
public static void SetGaCommonInfo(string SetGaCommonInfo){}
@@ -49,11 +52,23 @@ namespace tysdk
public static void UnityLoadRvADS(){}
public static void UnityShowRVAD(){}
#elif UNITY_ANDROID
private static string SDK_CLASS = "com.unity3d.player.SDKManager";
//初始化sdk
public static void InitSDK(){
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var activity = activityCls.GetStatic<AndroidJavaObject>("currentActivity");
sdkManager.CallStatic("InitSDK", activity);
}
}
}
//更新登录支付域名
public static void UnityResetServerUrl(string url)
{
@@ -108,6 +123,17 @@ namespace tysdk
}
}
//支付new
public static void UnityKnowNew(string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo,string pType)
{
Debug.LogError("[UnityKnowNew] pType:" + pType);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityKnowNew", productId, productPrice, productName,
productCount, prodorderId, appInfo,pType);
}
}
//支付
public static void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo)
@@ -119,6 +145,15 @@ namespace tysdk
}
}
//获取商品列表
public static void ThirdExtend()
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("thirdExtend");
}
}
//打点
public static void SetGaUserInfo(string userId)
{
@@ -205,6 +240,13 @@ namespace tysdk
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo);
//支付new
[DllImport("__Internal")]
public static extern void UnityKnowNew(string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo, string pType);
//获取商品列表
[DllImport("__Internal")]
public static extern void ThirdExtend();
//打点
[DllImport("__Internal")]
public static extern void SetGaUserInfo(string userId);