512 lines
16 KiB
C#
512 lines
16 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
#if USE_IAP
|
||
using UnityEngine.Purchasing;
|
||
#endif
|
||
using UnityEngine.UI;
|
||
|
||
|
||
namespace Touka
|
||
{
|
||
public class ToukaSDKDemo : MonoBehaviour
|
||
{
|
||
public Image nativeImage;
|
||
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
InitSDK();
|
||
|
||
SetFunctionSwitchListener();
|
||
}
|
||
|
||
#region function swtich listener
|
||
|
||
// set function switch listener
|
||
private void SetFunctionSwitchListener()
|
||
{
|
||
List<FunctionType> list = new List<FunctionType>();
|
||
list.Add(FunctionType.Function_bing);
|
||
list.Add(FunctionType.Function_IA);
|
||
|
||
//TKGSDKManager.Instance.SetFunctionSwitchListener(list, OnFunsSwitchCallback);
|
||
|
||
TKGSDKManager.Instance.SetFunctionSwitchListener(new List<Touka.FunctionType>() { FunctionType.Function_wangz, FunctionType.Function_bing }, OnFunsSwitchCallback);
|
||
}
|
||
|
||
private void OnFunsSwitchCallback(FunctionType _type, bool result)
|
||
{
|
||
Debug.Log("[ToukaSDKDemo]:FunctionType:" + _type + "result:" + result);
|
||
if (_type == FunctionType.Function_wangz)
|
||
{
|
||
|
||
}
|
||
else if(_type == FunctionType.Function_bing)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
public void removeNativeAd()
|
||
{
|
||
TKGSDKManager.Instance.RemoveNative();
|
||
}
|
||
|
||
public void OnShowNativeAd()
|
||
{
|
||
TKGSDKManager.Instance.ShowNative(nativeImage.rectTransform);
|
||
}
|
||
|
||
public void OnButton_Init()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_Init click, InitSDK auto Callfirst");
|
||
InitSDK();
|
||
}
|
||
|
||
|
||
#region Init
|
||
|
||
private void InitSDK()
|
||
{
|
||
OnButton_UserSource();
|
||
OnButton_SetLogEnable();
|
||
|
||
TKGSDKManager.Instance.InitSDK(initCallback);
|
||
TKGSDKManager.Instance.SetLogEnable(true);
|
||
TKGSDKManager.Instance.SetRewardClickListener(ClickRewardCallback);
|
||
TKGSDKManager.Instance.SetAdsRevenueCallback(AdsRevenueCallback);
|
||
}
|
||
|
||
private void ClickRewardCallback()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] click reward callback");
|
||
}
|
||
|
||
/// <summary>
|
||
/// Ads Revenue callback
|
||
/// </summary>
|
||
/// <param name="_adsType"></param>
|
||
/// <param name="_price"></param>
|
||
/// <param name=""></param>
|
||
private void AdsRevenueCallback(AdsType _adsType, string _price, string _currency)
|
||
{
|
||
Debug.Log("AdsRevenueCallback, _adsType : " + _adsType + " , _price : " + _price + " , _currency : " + _currency);
|
||
}
|
||
|
||
private void initCallback()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] init callback");
|
||
}
|
||
|
||
public void OnButton_SetLogEnable()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] SetLogEnable btn click");
|
||
//TKGSDKManager.Instance.SetLogEnable(true);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Ads
|
||
|
||
public void OnButton_ShowInterstitialAd()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_ShowInterstitialAd click");
|
||
|
||
|
||
TKGSDKManager.Instance.ShowInterstitialAd(TKGIVAdPositionName.IV_Spin, IVCallback);
|
||
|
||
|
||
Dictionary<string,string> dic = TKGSDKManager.Instance.GetIAPProductList();
|
||
foreach (var item in dic)
|
||
{
|
||
Debug.Log("dic key:"+item.Key+",value:"+item.Value);
|
||
}
|
||
}
|
||
|
||
|
||
private void IV2Callback()
|
||
{
|
||
Debug.Log("unity [ToukaSDKDemo] IVCallback");
|
||
}
|
||
|
||
private void IVCallback()
|
||
{
|
||
Debug.Log("unity [ToukaSDKDemo] IVCallback 2" );
|
||
}
|
||
|
||
public void OnButton_ShowRewardAd()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_ShowRewardAd click");
|
||
TKGSDKManager.Instance.ShowRewardAd(TKGRVPositionName.RV_GetDoubleCoin, RewardResult, RvShowFailed,true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Reward result
|
||
/// </summary>
|
||
/// <param name="pSucceed"> true:reward succ, false: reward failed </param>
|
||
private void RewardResult(bool pSucceed)
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] Reward result:" + pSucceed);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Callback of reward ad show fail
|
||
/// </summary>
|
||
private void RvShowFailed()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] Reward ads show failed");
|
||
}
|
||
|
||
public void OnButton_IsReadyIV()
|
||
{
|
||
|
||
Debug.Log("[ToukaSDKDemo] OnButton_IsReadyIV click");
|
||
bool isReadyIV = TKGSDKManager.Instance.IsReadyInterstitialAd();
|
||
Debug.Log("[ToukaSDKDemo] isReadyIV : " + isReadyIV);
|
||
}
|
||
|
||
public void OnButton_IsReadyRV()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_IsReadyRV click");
|
||
bool isReadyRV = TKGSDKManager.Instance.IsReadyRewardAd();
|
||
Debug.Log("[ToukaSDKDemo] isReadyRV : " + isReadyRV);
|
||
}
|
||
|
||
public void OnButton_ShowBanner()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_ShowBanner click");
|
||
TKGSDKManager.Instance.ShowBanner(TKGBannerAlign.BannerCenterBottomAlign);
|
||
}
|
||
|
||
public void OnButton_HideBanner()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_HideBanner click");
|
||
TKGSDKManager.Instance.HideBanner();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Event Tracking
|
||
|
||
public void OnButton_LevelStart()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LevelStart click");
|
||
TKGSDKManager.Instance.LevelStart(1);
|
||
}
|
||
|
||
public void OnButton_LevelSucc()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LevelSucc click");
|
||
TKGSDKManager.Instance.LevelEnd(1, StageResult.StageSucc);
|
||
}
|
||
|
||
public void OnButton_LevelFailed()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LevelFailed click");
|
||
TKGSDKManager.Instance.LevelEnd(2, StageResult.StageFail);
|
||
}
|
||
|
||
public void OnButton_LevelRetry()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LevelRetry click");
|
||
TKGSDKManager.Instance.LevelEnd(3, StageResult.StageRetry);
|
||
}
|
||
|
||
public void OnButton_LevelBack()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LevelBack click");
|
||
TKGSDKManager.Instance.LevelEnd("S_1", StageResult.StageBack);
|
||
}
|
||
|
||
public void OnButton_LogEventClick()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_LogEventClick click");
|
||
TKGSDKManager.Instance.LogEvent("logEvent01");
|
||
TKGSDKManager.Instance.LogEvent("logEvent02", "key02", "value02");
|
||
TKGSDKManager.Instance.LogEvent("logEvent03", "key03-1", "value03-1", "key03-2", "value03-2");
|
||
TKGSDKManager.Instance.LogEvent("logEvent04", new Dictionary<string, string> { { "DicKey04", "DicKey04" } });
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Get Remote Config
|
||
|
||
public void OnButton_GetConfigInt()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_GetConfigInt click");
|
||
int onlineIntValue = TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShowCount);
|
||
Debug.Log("online int value : " + onlineIntValue);
|
||
}
|
||
|
||
public void OnButton_GetConfigStr()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_GetConfigStr click");
|
||
string onlineStrValue = TKGSDKManager.Instance.GetConfigStr(TKGParamKey.LevelList);
|
||
Debug.Log("online string value : " + onlineStrValue);
|
||
}
|
||
|
||
public void OnButton_GetConfigBool()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_GetConfigBool click");
|
||
bool onlineBoolValue = TKGSDKManager.Instance.GetConfigBool(TKGParamKey.HasBlock);
|
||
Debug.Log("online bool value : " + onlineBoolValue);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Privacy Compliance
|
||
|
||
public void OnButton_OpenPrivacyUrl()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_OpenPrivacyUrl click");
|
||
TKGSDKManager.Instance.OpenPolicyPop();
|
||
}
|
||
|
||
public void OnButton_OpenUserTermBtn()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_OpenUserTermBtn click");
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Others
|
||
|
||
public void OnButton_OpenMoreGame()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_OpenMoreGame click");
|
||
//TKGSDKManager.Instance.OpenMoreGame();
|
||
}
|
||
|
||
public void OnButton_ReviewBtn()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_ReviewBtn click");
|
||
TKGSDKManager.Instance.Review();
|
||
}
|
||
|
||
public void OnButton_showPictureCross()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_showPictureCross click");
|
||
TKGSDKManager.Instance.showPictureCross();
|
||
}
|
||
|
||
public void OnButton_removePictureCross()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_removePictureCross click");
|
||
TKGSDKManager.Instance.removePictureCross();
|
||
}
|
||
|
||
public void OnButton_showMoreGameIcon()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_showMoreGameIcon click");
|
||
TKGSDKManager.Instance.showMoreGameIcon();
|
||
}
|
||
|
||
public void OnButton_removeMoreGameIcon()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_removeMoreGameIcon click");
|
||
TKGSDKManager.Instance.removeMoreGameIcon();
|
||
}
|
||
|
||
public void OnButton_GuidGpComment()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_GuidGpComment click");
|
||
TKGSDKManager.Instance.GuidGpComment();
|
||
}
|
||
|
||
public void OnButton_SetGameFocusListener()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_SetGameFocusListener click");
|
||
TKGSDKManager.Instance.SetGameFocusListener((_flg) => {
|
||
if (_flg)
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_SetGameFocusListener false flg");
|
||
PauseGame();
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OnButton_SetGameFocusListener true flg");
|
||
ResumeGame();
|
||
}
|
||
});
|
||
}
|
||
|
||
private void PauseGame()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] pause game callback");
|
||
}
|
||
|
||
private void ResumeGame()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] resume game callback");
|
||
}
|
||
|
||
public void OnButton_OpenLocalPush()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] OpenLocalPush click");
|
||
|
||
/*
|
||
* Assets/TKGSDK/Config/Scripts/StaticOtherConfig.cs
|
||
1. set LocalNotitcifaction_Switch = true;
|
||
2. set pushContent; // copy from product requirements
|
||
MorrowMsgCN = "";
|
||
Day357MsgCN = "";
|
||
Day468MsgCN = "";
|
||
*/
|
||
}
|
||
|
||
public void OnButton_UserSource()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] Set UserSource Click, call before init");
|
||
|
||
TKGSDKManager.Instance.SetUserSourceListener((_isOrigin, _source) =>
|
||
{
|
||
Debug.Log("usersource"+_isOrigin+_source);
|
||
if (_isOrigin)
|
||
{
|
||
Debug.Log("is origin user");
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("is not origin user");
|
||
}
|
||
});
|
||
}
|
||
|
||
public void OnButton_CommonCallback()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] Set commonCallback Click");
|
||
TKGSDKManager.Instance.SetTKGCommonCallback((code, msg) => {
|
||
Debug.Log("common callback, code : " + code + " , msg : " + msg);
|
||
});
|
||
}
|
||
|
||
public void OnButton_GetChannel()
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] getChannel click");
|
||
Debug.Log("channel : " + TKGSDKManager.Instance.GetChannel());
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 用户登录
|
||
public void Login()
|
||
{
|
||
SceneManager.LoadScene("ToukaAccountSDKDemo");
|
||
}
|
||
|
||
public void Logout()
|
||
{
|
||
TKGSDKManager.Instance.Logout(null);
|
||
}
|
||
#endregion
|
||
|
||
#region IAP Event
|
||
|
||
/// <summary>
|
||
/// Log IAP button show
|
||
/// </summary>
|
||
public void LogIAPBtnShow()
|
||
{
|
||
TKGSDKManager.Instance.LogIAPBtnShow("Gem100","com.xx.gem100");
|
||
}
|
||
|
||
//#if USE_IAP
|
||
|
||
/// <summary>
|
||
/// 购买商品
|
||
/// </summary>
|
||
public void BuyProduct()
|
||
{
|
||
// 设置回调
|
||
TKGSDKManager.Instance.SetOnPurchaseDone(OnPurchaseResult);
|
||
string productID = "com.tkkk.unitysdk.demo.a1";
|
||
string productName = "a1";
|
||
string gameExtra = "a1GameExtraParam";
|
||
Debug.Log("[ToukaSDKDemo] ButProduct clickProductID: " + productID);
|
||
#if USE_IAP
|
||
TKGSDKManager.Instance.BuyProductByID(productID, productName, gameExtra);
|
||
#endif
|
||
}
|
||
#if USE_IAP
|
||
public void OnGetProductsInfo(Product[] products)
|
||
{
|
||
foreach (var product in products)
|
||
{
|
||
TKGDebugger.LogDebug("[ToukaSDKDemo] "+product.metadata.localizedTitle
|
||
+ "|" + product.metadata.localizedPriceString
|
||
+ "|" + product.metadata.localizedDescription
|
||
+ "|" + product.metadata.isoCurrencyCode);
|
||
}
|
||
}
|
||
#endif
|
||
public void OnPurchaseDone(string procuctID,bool isSucc,string orderID,string token)
|
||
{
|
||
if (isSucc)
|
||
{
|
||
//add gold
|
||
TKGDebugger.LogDebug("[ToukaSDKDemo] Pay success,add gold, procuctID : " + procuctID + " , isSucc : " + isSucc + " , orderID :" + orderID + ", ");
|
||
}
|
||
else
|
||
{
|
||
// purchase failed
|
||
TKGDebugger.LogDebug("[ToukaSDKDemo] Pay success,add gold");
|
||
}
|
||
}
|
||
|
||
public void AddProducts()
|
||
{
|
||
#if USE_IAP
|
||
Dictionary<string, ProductType> products = new Dictionary<string, ProductType>();
|
||
products.Add("com.tkkk.unitysdk.demo.a1",ProductType.NonConsumable);
|
||
products.Add("com.tkkk.unitysdk.demo.a12",ProductType.NonConsumable);
|
||
products.Add("com.magicalcreatures.gems8",ProductType.NonConsumable);
|
||
products.Add("com.magicalcreatures.newpackage1",ProductType.NonConsumable);
|
||
TKGSDKManager.Instance.AddProducts(products);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 购买后面添加的商品
|
||
/// </summary>
|
||
public void BuyProduct2()
|
||
{
|
||
// 设置回调
|
||
TKGSDKManager.Instance.SetOnPurchaseDone(OnPurchaseResult);
|
||
// string productID = "com.tkkk.unitysdk.demo.a12";
|
||
string productID = "com.magicalcreatures.gems8";
|
||
string productName = "a12";
|
||
string gameExtra = "a12GameExtraParam";
|
||
Debug.Log("[ToukaSDKDemo] ButProduct2 click :ProductID: "+ productID);
|
||
#if USE_IAP
|
||
TKGSDKManager.Instance.BuyProductByID(productID, productName, gameExtra);
|
||
#endif
|
||
}
|
||
|
||
private void OnPurchaseResult(string pOrderID, string pProductName, string pID, bool pResult, string gameExtra)
|
||
{
|
||
Debug.Log("[ToukaSDKDemo] ButProduct pOrderID:"+ pOrderID + " pProductName:"+ pProductName + " pID:"+ pID + " OnPurchaseResult:" + pResult + " , gameExtra : " + gameExtra);
|
||
}
|
||
#endregion
|
||
|
||
#region for wz
|
||
|
||
/// <summary>
|
||
/// SetUserIDAndThirdAccount
|
||
/// </summary>
|
||
public void SetUserIDAndThirdAccountBtnClick()
|
||
{
|
||
TKGSDKManager.Instance.SetUserIDAndThirdAccount("TK_001", "paypal_a001", ThirdAccountType.Paypal);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |