WXGame/box1/Assets/Script/UI/HomePanel/BuildButton.cs
2024-11-26 15:44:50 +08:00

129 lines
4.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using cfg;
using UnityEngine;
using UnityEngine.UI;
public class BuildButton : MonoBehaviour
{
public BuildEnum build;
[SerializeField] private HomePanel _homePanel;
[SerializeField] private Button _button;
private void Awake()
{
_button = GetComponent<Button>();
}
private void OnEnable()
{
_button.onClick.AddListener(PayItem);
}
private void OnDisable()
{
_button.onClick.RemoveListener(PayItem);
}
private void PayItem()
{
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);
BoxDebug.Log(windowData);
gameObject.SetActive(windowData.Buildingup != 0 && windowData.Buildingup<=DataManager.GetStar());
break;
case BuildEnum.light:
var lightLv = DataManager.GetHomeFurnitureID("light");
var lightData = JsonTab.Instance.tables.BuildLevelUp.Get(lightLv);
BoxDebug.Log(lightData);
gameObject.SetActive(lightData.Buildingup != 0 && lightData.Buildingup<=DataManager.GetStar());
break;
case BuildEnum.carpet:
var carpetLv = DataManager.GetHomeFurnitureID("carpet");
var carpetData = JsonTab.Instance.tables.BuildLevelUp.Get(carpetLv);
BoxDebug.Log(carpetData);
gameObject.SetActive(carpetData.Buildingup != 0 && carpetData.Buildingup<=DataManager.GetStar());
break;
case BuildEnum.closet:
var closetLv = DataManager.GetHomeFurnitureID("closet");
var closetData = JsonTab.Instance.tables.BuildLevelUp.Get(closetLv);
BoxDebug.Log(closetData);
gameObject.SetActive(closetData.Buildingup != 0 && closetData.Buildingup<=DataManager.GetStar());
break;
case BuildEnum.chair:
var chairLv = DataManager.GetHomeFurnitureID("chair");
var chairData = JsonTab.Instance.tables.BuildLevelUp.Get(chairLv);
BoxDebug.Log(chairData);
gameObject.SetActive(chairData.Buildingup != 0 && chairData.Buildingup<=DataManager.GetStar());
break;
default:
throw new ArgumentOutOfRangeException();
}
}
// 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
}