62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class DutyItem : MonoBehaviour
|
|
{
|
|
public Image dutyImage;
|
|
public Text dutyNameText;
|
|
public Button button;
|
|
public int leader;
|
|
public int dutyId;
|
|
public Color defaultColor = Color.white; // 默认颜色
|
|
public Color addedColor = Color.gray; // 已添加颜色
|
|
public Color selectedColor = Color.yellow; // 选中颜色
|
|
|
|
public string dutyName { get; private set; } // 角色名字
|
|
private bool isAdded; // 是否已添加
|
|
private bool isSelected; // 是否选中
|
|
|
|
public delegate void ClickHandler();
|
|
public event ClickHandler onClick; // 点击事件
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
public void Setup(string name, bool added)
|
|
{
|
|
dutyName = name;
|
|
dutyNameText.text = name;
|
|
SetAdded(added);
|
|
button.onClick.AddListener(OnButtonClick);
|
|
}
|
|
// 设置已添加状态
|
|
public void SetAdded(bool added)
|
|
{
|
|
isAdded = added;
|
|
dutyNameText.color = isAdded ? addedColor : defaultColor;
|
|
}
|
|
|
|
// 设置选中状态
|
|
public void SetSelected(bool selected)
|
|
{
|
|
isSelected = selected;
|
|
dutyNameText.fontSize = isSelected ? 24 : 14; // 选中后字体增大
|
|
dutyNameText.color = isSelected ? selectedColor : (isAdded ? addedColor : defaultColor);
|
|
}
|
|
|
|
// 按钮点击事件
|
|
private void OnButtonClick()
|
|
{
|
|
onClick?.Invoke();
|
|
}
|
|
|
|
} |