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}");
}
}
}
}