2024-11-26 15:44:50 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using cfg;
|
2024-11-29 21:37:01 +08:00
|
|
|
using TMPro;
|
2024-11-26 15:44:50 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class BuildButton : MonoBehaviour
|
|
|
|
{
|
|
|
|
public BuildEnum build;
|
|
|
|
[SerializeField] private HomePanel _homePanel;
|
|
|
|
[SerializeField] private Button _button;
|
2024-11-29 21:37:01 +08:00
|
|
|
[SerializeField] private TextMeshProUGUI _textMeshProUGUI;
|
|
|
|
[SerializeField] private GameObject name;
|
|
|
|
[SerializeField] private GameObject upImage;
|
|
|
|
private bool eventOpen;
|
2024-11-26 15:44:50 +08:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
_button = GetComponent<Button>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
_button.onClick.AddListener(PayItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
_button.onClick.RemoveListener(PayItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PayItem()
|
|
|
|
{
|
2024-11-29 21:37:01 +08:00
|
|
|
if (!eventOpen)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2024-11-26 15:44:50 +08:00
|
|
|
switch(build)
|
|
|
|
{
|
|
|
|
case BuildEnum.window:
|
|
|
|
var windowLv = DataManager.GetHomeFurnitureID("window");
|
|
|
|
var windowData = JsonTab.Instance.tables.BuildLevelUp.Get(windowLv);
|
|
|
|
DataManager.SetSpend(windowData.Buildingup + DataManager.GetSpend());
|
|
|
|
DataManager.SetHomeFurnitureID("window",windowData.Buildingnext);
|
|
|
|
break;
|
|
|
|
case BuildEnum.light:
|
|
|
|
var lightLv = DataManager.GetHomeFurnitureID("light");
|
|
|
|
var lightData = JsonTab.Instance.tables.BuildLevelUp.Get(lightLv);
|
|
|
|
DataManager.SetSpend(lightData.Buildingup + DataManager.GetSpend());
|
|
|
|
DataManager.SetHomeFurnitureID("light",lightData.Buildingnext);
|
|
|
|
break;
|
|
|
|
case BuildEnum.carpet:
|
|
|
|
var carpetLv = DataManager.GetHomeFurnitureID("carpet");
|
|
|
|
var carpetData = JsonTab.Instance.tables.BuildLevelUp.Get(carpetLv);
|
|
|
|
DataManager.SetSpend(carpetData.Buildingup + DataManager.GetSpend());
|
|
|
|
DataManager.SetHomeFurnitureID("carpet",carpetData.Buildingnext);
|
|
|
|
break;
|
|
|
|
case BuildEnum.closet:
|
|
|
|
var closetLv = DataManager.GetHomeFurnitureID("closet");
|
|
|
|
var closetData = JsonTab.Instance.tables.BuildLevelUp.Get(closetLv);
|
|
|
|
DataManager.SetSpend(closetData.Buildingup + DataManager.GetSpend());
|
|
|
|
DataManager.SetHomeFurnitureID("closet",closetData.Buildingnext);
|
|
|
|
break;
|
|
|
|
case BuildEnum.chair:
|
|
|
|
var chairLv = DataManager.GetHomeFurnitureID("chair");
|
|
|
|
var chairData = JsonTab.Instance.tables.BuildLevelUp.Get(chairLv);
|
|
|
|
DataManager.SetSpend(chairData.Buildingup + DataManager.GetSpend());
|
|
|
|
DataManager.SetHomeFurnitureID("chair",chairData.Buildingnext);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
_homePanel.ResetImage();
|
|
|
|
}
|
|
|
|
public void RestGameObject(HomePanel panel)
|
|
|
|
{
|
|
|
|
_homePanel = panel;
|
|
|
|
switch (build)
|
|
|
|
{
|
|
|
|
case BuildEnum.window:
|
|
|
|
var windowLv = DataManager.GetHomeFurnitureID("window");
|
|
|
|
var windowData = JsonTab.Instance.tables.BuildLevelUp.Get(windowLv);
|
2024-11-29 21:37:01 +08:00
|
|
|
ButtonRest(windowData);
|
2024-11-26 15:44:50 +08:00
|
|
|
break;
|
|
|
|
case BuildEnum.light:
|
|
|
|
var lightLv = DataManager.GetHomeFurnitureID("light");
|
|
|
|
var lightData = JsonTab.Instance.tables.BuildLevelUp.Get(lightLv);
|
2024-11-29 21:37:01 +08:00
|
|
|
ButtonRest(lightData);
|
2024-11-26 15:44:50 +08:00
|
|
|
break;
|
|
|
|
case BuildEnum.carpet:
|
|
|
|
var carpetLv = DataManager.GetHomeFurnitureID("carpet");
|
|
|
|
var carpetData = JsonTab.Instance.tables.BuildLevelUp.Get(carpetLv);
|
2024-11-29 21:37:01 +08:00
|
|
|
ButtonRest(carpetData);
|
2024-11-26 15:44:50 +08:00
|
|
|
break;
|
|
|
|
case BuildEnum.closet:
|
|
|
|
var closetLv = DataManager.GetHomeFurnitureID("closet");
|
|
|
|
var closetData = JsonTab.Instance.tables.BuildLevelUp.Get(closetLv);
|
2024-11-29 21:37:01 +08:00
|
|
|
ButtonRest(closetData);
|
2024-11-26 15:44:50 +08:00
|
|
|
break;
|
|
|
|
case BuildEnum.chair:
|
|
|
|
var chairLv = DataManager.GetHomeFurnitureID("chair");
|
|
|
|
var chairData = JsonTab.Instance.tables.BuildLevelUp.Get(chairLv);
|
2024-11-29 21:37:01 +08:00
|
|
|
ButtonRest(chairData);
|
2024-11-26 15:44:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
}
|
2024-11-29 21:37:01 +08:00
|
|
|
|
|
|
|
private void ButtonRest(BBuildLevelUp chairData)
|
|
|
|
{
|
|
|
|
BoxDebug.Log(chairData);
|
|
|
|
if (chairData.Buildingup == 0)
|
|
|
|
{
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
if (chairData.Buildingup<=DataManager.GetStar())
|
|
|
|
{
|
|
|
|
upImage.SetActive(true);
|
|
|
|
eventOpen = true;
|
|
|
|
name.SetActive(false);
|
|
|
|
_textMeshProUGUI.text = "x" + chairData.Buildingup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
upImage.SetActive(false);
|
|
|
|
eventOpen = false;
|
|
|
|
name.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 15:44:50 +08:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum BuildEnum
|
|
|
|
{
|
|
|
|
window,
|
|
|
|
light,
|
|
|
|
carpet,
|
|
|
|
closet,
|
|
|
|
chair
|
|
|
|
}
|