132 lines
3.9 KiB
C#
132 lines
3.9 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HomeBuildBtn : MonoBehaviour, IUIRedPoint
|
|
{
|
|
string key;
|
|
public GameObject redPoint;
|
|
public GameObject redpoint_big;
|
|
public GameObject bubble_tips;
|
|
public TMP_Text text_redpoint_big;
|
|
public Button btn_building;
|
|
public CanvasGroup homeCanvasGroup;
|
|
CampDataMM campData;
|
|
private void Awake()
|
|
{
|
|
campData = GContext.container.Resolve<CampDataMM>();
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_building.onClick.AddListener(OnBuildingClick);
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
if (campData.IsCanSkyscraper)
|
|
{
|
|
SetKey(RedPointName.Home_Skyscraper);
|
|
}
|
|
else
|
|
{
|
|
SetKey(RedPointName.Home_Build);
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(key);
|
|
key = "";
|
|
}
|
|
}
|
|
public void SetKey(string _key)
|
|
{
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(key);
|
|
}
|
|
key = _key;
|
|
RedPointManager.Instance.AddRedPoint(key, this);
|
|
SetRedPointState(RedPointManager.Instance.GetRedPointState(key));
|
|
}
|
|
|
|
public void SetRedPointState(bool state)
|
|
{
|
|
int count = RedPointManager.Instance.GetRedPointCount(key);
|
|
if (count > 1)
|
|
{
|
|
redpoint_big.SetActive(true);
|
|
if (count > 99)
|
|
{
|
|
text_redpoint_big.text = "99+";
|
|
}
|
|
else
|
|
{
|
|
text_redpoint_big.text = count.ToString();
|
|
}
|
|
state = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
redPoint.SetActive(state);
|
|
if (state && !campData.IsCanSkyscraper)
|
|
{
|
|
bubble_tips.SetActive(campData.GoBuilding());
|
|
}
|
|
}
|
|
void OnBuildingClick()
|
|
{
|
|
homeCanvasGroup.blocksRaycasts = false;
|
|
if (campData.IsCanSkyscraper)
|
|
{
|
|
InfiniteBuildingAct();
|
|
}
|
|
else
|
|
{
|
|
InBuildAct();
|
|
}
|
|
|
|
}
|
|
async void InfiniteBuildingAct()
|
|
{
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Load("InfiniteBuildingAct");
|
|
if (isCanEnter)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct")));
|
|
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
|
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, () => GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct")));
|
|
}
|
|
homeCanvasGroup.blocksRaycasts = true;
|
|
}
|
|
async void InBuildAct()
|
|
{
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Loads(campData.AllPrefabs);
|
|
if (isCanEnter)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("BuildAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
|
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
}
|
|
homeCanvasGroup.blocksRaycasts = true;
|
|
}
|
|
|
|
}
|