using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PeopleItem : MonoBehaviour { public Text nameText; // 人员名字显示 public Button button; // 按钮,用来选择人员 public Color defaultColor = Color.white; // 默认颜色 public Color addedColor = Color.gray; // 已添加颜色 public Color selectedColor = Color.yellow; // 选中颜色 public string Name { get; private set; } // 角色名字 private bool isAdded; // 是否已添加 private bool isSelected; // 是否选中 public string peopleId; public delegate void ClickHandler(); public event ClickHandler onClick; // 点击事件 // 设置人员项 public void Setup(string name, bool added) { Name = name; nameText.text = name; SetAdded(added); button.onClick.AddListener(OnButtonClick); } // 设置已添加状态 public void SetAdded(bool added) { isAdded = added; nameText.color = isAdded ? addedColor : defaultColor; } // 设置选中状态 public void SetSelected(bool selected) { isSelected = selected; nameText.fontSize = isSelected ? 24 : 14; // 选中后字体增大 nameText.color = isSelected ? selectedColor : (isAdded ? addedColor : defaultColor); } // 按钮点击事件 private void OnButtonClick() { onClick?.Invoke(); } }