Files
tysdk-intergration/sdk-intergration/Assets/Scripts/SDKTest.cs
2024-08-07 20:22:28 +08:00

127 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using ThinkingData.Analytics;
using tysdk;
using UnityEngine;
using UnityEngine.UI;
public class SDKTest : MonoBehaviour
{
[SerializeField]
private Button _InitBtn;
[SerializeField]
private Button _loginGuestBtn;
[SerializeField]
private Button _loginGoogleBtn;
[SerializeField]
private Button _loginFbBtn;
[SerializeField]
private Button _logOutBtn;
[SerializeField]
private Button _payTestBtn;
[SerializeField]
private Button _payListBtn;
[SerializeField]
private Button _gaTestBtn;
[SerializeField]
private Button _gaAppMaxBtn;
[SerializeField]
private Button _taBtn;
[SerializeField]
private Text _messageTxt;
void Start()
{
//UnityBridgeFunc.UnityResetServerUrl("http://128-hwsfsdk-sdk-test01.qijihdhk.com ");
_InitBtn.onClick.AddListener(TYSdkFacade.Instance.Init);
_loginGuestBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwGuest));
_loginGoogleBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwGoogle));
_loginFbBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwFacebook));
_logOutBtn.onClick.AddListener(OnLogout);
_payTestBtn.onClick.AddListener(OnPayTestBtn);
_payListBtn.onClick.AddListener(OnPayListBtn);
_gaTestBtn.onClick.AddListener(OnGaBtn);
_gaAppMaxBtn.onClick.AddListener(OnAppMaxBtn);
_taBtn.onClick.AddListener(OnTaBtn);
}
private async void OnLogin(EAccoutType accoutType)
{
_messageTxt.text = string.Empty;
Debug.LogError($"[AggSdk::OnLogin] accoutType : {accoutType}");
var info = await TYSdkFacade.Instance.Login(accoutType);
_messageTxt.text = $"Login: {info.isSuccess}";
if(info.isSuccess)
{
_messageTxt.text += $"\n{info.msg}";
_messageTxt.text += $"\n{TYSdkFacade.Instance.TYAccountInfo.token}";
}
}
private void OnLogout()
{
TYSdkFacade.Instance.Logout();
}
public async void OnPayTestBtn()
{
string prodId = "comarkgameft1chooseone0199";
string pType = "googleiab.global.app";
string prodPrice = "2,616";
string prodName = "test:₩2,616";
int count = 1;
Debug.LogError($"[AggSdk::Pay] prodId : {prodId} prodPrice : {prodPrice} prodName : {prodName} ");
PaymentInfo payResult = await TYSdkFacade.Instance.Pay(prodId, prodPrice, prodName, count, pType);
}
public async void OnPayListBtn()
{
Debug.LogError("PayList ask");
var result = await TYSdkFacade.Instance.ThirdExtend();
}
public void OnGaBtn()
{
Debug.LogError("Ga ask");
using ( var e = GAEvent.TackEvent("idcheckdone") )
{
e.AddContent("test ga", true);
}
}
public void OnAppMaxBtn()
{
// TYSdkFacade.Instance.PlayAd();
}
public void OnTaBtn()
{
// 初始化SDK
TDAnalytics.Init("0caf287574bd4a9bb08be8995705ef6f", "https://122-slg-online01.qijihdhk.com:8991");
// //如果用户已登录可以设置用户的账号ID作为身份唯一标识
// TDAnalytics.Login("TA");
//设置公共事件属性以后,每个事件都会带有公共事件属性
// Dictionary<string, object> superProperties = new Dictionary<string, object>();
// superProperties["channel"] = "ta";//字符串
// superProperties["age"] = 1;//数字
// superProperties["isSuccess"] = true;//布尔
// superProperties["birthday"] = DateTime.Now;//时间
// superProperties["object"] = new Dictionary<string, object>(){{ "key", "value"}};//对象
// superProperties["object_arr"] = new List<object>() {new Dictionary<string, object>(){{ "key", "value" }}};//对象组
// superProperties["arr"] = new List<object>() { "value" };//数组
// TDAnalytics.SetSuperProperties(superProperties);//设置公共事件属性
//开启自动采集事件
// TDAnalytics.EnableAutoTrack(TDAutoTrackEventType.AppInstall | TDAutoTrackEventType.AppStart | TDAutoTrackEventType.AppEnd);
//发送事件
// Dictionary<string, object> properties = new Dictionary<string, object>(){{"product_name", "商品名")}};
// TDAnalytics.Track("product_buy", properties);
//设置用户属性
// TDAnalytics.UserSet(new Dictionary<string, object>(){{"user_name", "TA"}});
}
}