WXGame/box1/Assets/Script/DYSidebarInit.cs
2024-12-18 11:12:52 +08:00

71 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TTSDK;
using UnityEngine.UI;
using System;
public class DYSidebarInit : MonoBehaviour
{
//是否从侧边栏进入:是:点开侧边栏后可以领取奖励;否:跳转到侧边栏
public static bool isEnterFromSidebar = false;
[SerializeField] private GameObject sideBar;
void Awake()
{
TT.InitSDK((code, env) =>
{
Debug.Log("入口场景是:" + env.GetLaunchOptionsSync().Scene);
//如果不是从侧边栏进入的,去判断当前宿主版本是否支持侧边栏
if (!(env.GetLaunchOptionsSync().Scene == "021036"
|| env.GetLaunchOptionsSync().Scene == "021001"
|| env.GetLaunchOptionsSync().Scene == "101036"))
{
TestSidebar();
}
});
TT.GetAppLifeCycle().OnShow += (dir) =>
{
if (dir["location"].ToString() == "sidebar_card" && dir["launchFrom"].ToString() == "homepage")
{
isEnterFromSidebar = true;
}
};
GetComponent<Button>().onClick.AddListener(OnButtonClick);
}
/// <summary>
/// 当前宿主版本是否支持侧边栏
/// </summary>
public void TestSidebar()
{
TT.CheckScene(TTSideBar.SceneEnum.SideBar,
b =>
{
Debug.Log("侧边栏可用吗" + b);
//如果当前宿主版本不支持侧边栏,则隐藏奖励领取按钮;支持侧边栏则可以正常显示
if (!b)
{
gameObject.SetActive(false);
}
},
() =>
{
},
(errCode, errMsg) =>
{
Debug.Log("CheckScene调用失败" + errMsg);
});
}
/// <summary>
/// 侧边栏按钮点击事件,显示侧边栏面板
/// </summary>
private void OnButtonClick()
{
sideBar.SetActive(true);
}
}