You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

1 year ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace BuildSystem
{
[RequireComponent(typeof(Image),typeof(Button))]
public class GridUI : MonoBehaviour
{
[Header("scriptsObject数据 上右下左")]
public PlaceObject_SO[] placeObject_SO;
int dataIndex;
[Header("切换")]
public Button switchBtn;
[Header("四向图 上右下左放置")]
public Sprite[] sprites;
int index = 0;
[Header("组件")]
Image image;
Button btn;
private void Awake()
{
btn = GetComponent<Button>();
image = GetComponent<Image>();
image.sprite = sprites[index];
btn.onClick.AddListener(()=> {
BuildSystemManager.Instance.ChangeChoose(placeObject_SO[dataIndex]);
});
switchBtn.onClick.AddListener(()=> {
IndexChange(1);
image.sprite = sprites[index];
BuildSystemManager.Instance.ChangeChoose(placeObject_SO[dataIndex]);
});
}
void IndexChange(int value) {
index += value;
dataIndex += value;
if (index > sprites.Length - 1) {
index = 0;
} else if (index < 0) {
index = sprites.Length - 1;
}
if (dataIndex > placeObject_SO.Length - 1)
{
dataIndex = 0;
}
else if (dataIndex < 0)
{
dataIndex = placeObject_SO.Length - 1;
}
}
}
}