chicken_dy/Assets/HCMiniSdk/Demo/Scripts/HCDemoScene.cs

353 lines
9.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HC;
using UnityEngine.UI;
using System.Linq;
using Newtonsoft.Json.Linq;
public class HCDemoScene : MonoBehaviour
{
public HCLoginDemoView mLoginDemoView;
public HCCheckSensitiveWordView mCheckSensitiveWordView;
public Text mPurchaseBtn;
public Image nativeImage;
// Start is called before the first frame update
void Start()
{
#if UNITY_EDITOR && WEBGL_BYTEDANCE
StarkSDKSpace.MockSetting.OpenAllMockModule();
#endif
mLoginDemoView.gameObject.SetActive(false);
mCheckSensitiveWordView.gameObject.SetActive(false);
HCSDKManager.Instance.SetOnPurchaseDone(PurchaseCallback);
HCSDKManager.Instance.InitializeSdk();
#if WEBGL_BYTEDANCE
HCSDKManager.Instance.OnShowWithDict(param =>
{
// 抖音首页侧边栏
// launch_from = homepage
// location = sidebar_card
param.TryGetValue("launch_from", out var launchFrom);
param.TryGetValue("location", out var location);
HCDebugger.LogDebug($"[OnShowWithDict] launch_from = {launchFrom} location = {location}");
});
#endif
}
public void Button_InitSDK()
{
HCSDKManager.Instance.InitializeSdk();
HCDebugger.LogDebug("Button_InitSDK");
}
public void Button_ShowIV1()
{
HCDebugger.LogDebug("Button_ShowIV1");
HCSDKManager.Instance.ShowInterstitial(HCIVPositionName.IV_Success, HCIVADType.IV1, IVCloseCallback);
}
private void IVCloseCallback()
{
Debug.Log("IVCloseCallback");
}
public void Button_ShowIV2()
{
HCDebugger.LogDebug("Button_ShowIV2 start auto iv");
// StartCoroutine("AutoIV");
Invoke("AutoIV", 10);
}
private void AutoIV()
{
HCDebugger.LogDebug("自动插屏显示");
HCSDKManager.Instance.ShowInterstitial(HCIVPositionName.IV_Success, HCIVADType.IV2);
Invoke("AutoIV", 10);
}
public void Button_ShowBanner()
{
HCDebugger.LogDebug("Button_ShowBanner");
HCSDKManager.Instance.ShowBanner();
}
public void Button_HideBanner()
{
HCDebugger.LogDebug("Button_HideBanner");
HCSDKManager.Instance.HideBanner();
}
public void Button_ShowNative()
{
HCDebugger.LogDebug($"Button_ShowNative {HCStaticParams.NativeAdUnitID1} = {HCSDKManager.Instance.IsNativeAdReady(HCStaticParams.NativeAdUnitID1)}");
nativeImage.color = Color.blue;
HCSDKManager.Instance.ShowNative(nativeImage.rectTransform, adUnit: HCStaticParams.NativeAdUnitID1, _showFailedCallback: (i, s) =>
{
HCDebugger.LogDebug($"$Button_show callback show fail code = {i} msg = {s}");
nativeImage.color = Color.clear;
}, _closeCallback: () =>
{
HCDebugger.LogDebug($"$Button_show callback close");
nativeImage.color = Color.clear;
});
}
public void Button_RemoveNative()
{
HCDebugger.LogDebug("Button_RemoveNative");
nativeImage.color = Color.clear;
HCSDKManager.Instance.RemoveNative(HCStaticParams.NativeAdUnitID1);
}
public void Button_ShowNative_2()
{
HCDebugger.LogDebug($"Button_ShowNative_2 {HCStaticParams.NativeAdUnitID2} = {HCSDKManager.Instance.IsNativeAdReady(HCStaticParams.NativeAdUnitID2)}");
HCDebugger.LogDebug("Button_ShowNative_2");
HCSDKManager.Instance.ShowNative(null, adUnit: HCStaticParams.NativeAdUnitID2);
}
public void Button_RemoveNative_2()
{
HCDebugger.LogDebug("Button_RemoveNative_2");
HCSDKManager.Instance.RemoveNative(HCStaticParams.NativeAdUnitID2);
}
public void Button_ShowNative_3()
{
HCDebugger.LogDebug($"Button_ShowNative_3 {HCStaticParams.NativeAdUnitID3} = {HCSDKManager.Instance.IsNativeAdReady(HCStaticParams.NativeAdUnitID3)}");
HCDebugger.LogDebug("Button_ShowNative_3");
HCSDKManager.Instance.ShowNative(null, adUnit: HCStaticParams.NativeAdUnitID3);
}
public void Button_RemoveNative_3()
{
HCDebugger.LogDebug("Button_RemoveNative_3");
HCSDKManager.Instance.RemoveNative(HCStaticParams.NativeAdUnitID3);
}
public void Button_ShowNative_4()
{
HCDebugger.LogDebug($"Button_ShowNative_4 {HCStaticParams.NativeAdUnitID4} = {HCSDKManager.Instance.IsNativeAdReady(HCStaticParams.NativeAdUnitID4)}");
HCDebugger.LogDebug("Button_ShowNative_4");
HCSDKManager.Instance.ShowNative(null, adUnit: HCStaticParams.NativeAdUnitID4);
}
public void Button_RemoveNative_4()
{
HCDebugger.LogDebug("Button_RemoveNative_4");
HCSDKManager.Instance.RemoveNative(HCStaticParams.NativeAdUnitID4);
}
public void Button_ShowRV()
{
HCDebugger.LogDebug("Button_ShowRV");
HCSDKManager.Instance.ShowRewardedAd(HCRVPositionName.GetDoubleCoin, RewardCallback);
}
private void RewardCallback(bool success)
{
HCDebugger.LogDebug("RewardCallback result:" + success);
}
public void Button_Event01()
{
HCDebugger.LogDebug("Button_Event01");
HCSDKManager.Instance.LogEvent("TestEvent01");
}
public void Button_Event02()
{
HCDebugger.LogDebug("Button_Event02");
HCSDKManager.Instance.LogEvent("TestEvent02", "key01", "value01");
}
public void Button_Event03()
{
HCDebugger.LogDebug("Button_Event03");
HCSDKManager.Instance.LogEvent("TestEvent03", "key01", "value01", "key02", "value02");
}
public void ButtonBuyNoads()
{
HCDebugger.LogDebug("ButtonBuy");
#if USE_IAP
HCSDKManager.Instance.BuyProductByID(HCPurchaseProducts.NoAds,"RemoveAds");
#endif
}
public void ButtonBuyCoins()
{
HCDebugger.LogDebug("ButtonRestore");
#if USE_IAP
HCSDKManager.Instance.BuyProductByID(HCPurchaseProducts.Product01, "coins");
#endif
}
public void ButtonRestore()
{
#if USE_IAP
HCSDKManager.Instance.RestorePurchases();
#endif
}
public void ButtonWebGL()
{
#if UNITY_WEBGL
HCSDKManager.Instance.Buy(new HCPaymentArgs
{
productId = "boori.cash.1",
productName = "1元商品",
money = 100,
gameExtraParam = "{\\\"player_id\\\":150}"
});
#endif
}
public void ButtonWebGL2()
{
#if UNITY_WEBGL
HCSDKManager.Instance.Buy(new HCPaymentArgs
{
productId = "id.68",
productName = "68元商品",
money = 6800,
gameExtraParam = "拓展字段"
});
#endif
}
public void ButtonWebGL3()
{
#if UNITY_WEBGL
HCSDKManager.Instance.Buy(new HCPaymentArgs
{
productId = "id.3",
productName = "6元商品",
money = 600,
gameExtraParam = "拓展字段"
});
#endif
}
private void PurchaseCallback(string orderID, string productName, string productID, bool purchaseResult, string gameExtra, bool orderAlreadyExists, string serverGameExtra)
{
if (purchaseResult)
{
mPurchaseBtn.text = "购买成功";
#if WEBGL_WX
WeChatWASM.WX.ShowToast(new WeChatWASM.ShowToastOption
{
title = $"购买成功 {productName} {orderID}"
});
HCSDKManager.Instance.Awarded(orderID);
#endif
}
else
{
mPurchaseBtn.text = "购买失败";
#if WEBGL_WX
WeChatWASM.WX.ShowToast(new WeChatWASM.ShowToastOption
{
icon = "error",
title = $"购买失败 {productName} {orderID}"
});
#endif
}
HCDebugger.LogDebug("PurchaseCallback orderID:" + orderID + "productName:" + productName + "productID" + productID + "purResult" + purchaseResult + "gameExtra:" + gameExtra + "\t serverGameExtra : " + serverGameExtra);
}
private void UserSourceListenerCallback(bool isOrganic, string network)
{
HCSDKManager.Instance.ShowToast("isOrganic:" + isOrganic + "===newwotk:" + network);
HCDebugger.LogDebug("SetUserSourceListenerCallback isOrganic:" + isOrganic + "network:" + network);
}
#region Account
/// <summary>
/// Guest Login
/// </summary>
public void ButtonEvent_ShowLoginScreen()
{
HCDebugger.LogDebug("ButtonEvent_ShowLoginScreen");
mLoginDemoView.OpenWithLoginScreen(true);
}
/// <summary>
/// Google Login
/// </summary>
public void ButtonEvent_Directlogin()
{
HCDebugger.LogDebug("ButtonEvent_Directlogin");
mLoginDemoView.OpenWithLoginScreen(false);
}
/// <summary>
/// share
/// </summary>
public void ButtonEvent_Share()
{
HCDebugger.LogDebug("ButtonEvent_Share");
HCSDKManager.Instance.Share("title", null, null, (result) => { HCDebugger.LogDebug($"Share callback result = {result}"); });
}
#endregion
#region Record
/// <summary>
/// StartRecord
/// </summary>
public void ButtonEvent_StartRecord()
{
HCDebugger.LogDebug("StartRecord");
#if WEBGL_BYTEDANCE
// 主调调用结束
HCSDKManager.Instance.StartRecord(true, timeoutCallback: (s) =>
{
HCDebugger.LogDebug($"录制结束 s = {s}");
});
#endif
}
/// <summary>
/// StopRecord
/// </summary>
public void ButtonEvent_StopRecord()
{
HCDebugger.LogDebug("StopRecord");
#if WEBGL_BYTEDANCE
HCSDKManager.Instance.StopRecord(s =>
{
#if WEBGL_BYTEDANCE
HCSDKManager.Instance.DyShareRecordVideo("title test", new[] { "topic 1", "topic 2" }, (result, msg, dict) =>
{
HCDebugger.LogDebug($"[StopRecord] result = ${result} msg = {msg}");
});
#endif
});
#endif
}
public void ButtonEvent_SensitiveWordView()
{
mCheckSensitiveWordView.gameObject.SetActive(true);
}
#endregion
}