51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class PeopleItem : MonoBehaviour
|
|||
|
{
|
|||
|
public Text nameText; // <20><>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
public Button button; // <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Ա
|
|||
|
public Color defaultColor = Color.white; // Ĭ<><C4AC><EFBFBD><EFBFBD>ɫ
|
|||
|
public Color addedColor = Color.gray; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
public Color selectedColor = Color.yellow; // ѡ<><D1A1><EFBFBD><EFBFBD>ɫ
|
|||
|
|
|||
|
public string Name { get; private set; } // <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
|
|||
|
private bool isAdded; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private bool isSelected; // <20>Ƿ<EFBFBD>ѡ<EFBFBD><D1A1>
|
|||
|
|
|||
|
public delegate void ClickHandler();
|
|||
|
public event ClickHandler onClick; // <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
|
|||
|
public void Setup(string name, bool added)
|
|||
|
{
|
|||
|
Name = name;
|
|||
|
nameText.text = name;
|
|||
|
SetAdded(added);
|
|||
|
button.onClick.AddListener(OnButtonClick);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
public void SetAdded(bool added)
|
|||
|
{
|
|||
|
isAdded = added;
|
|||
|
nameText.color = isAdded ? addedColor : defaultColor;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>״̬
|
|||
|
public void SetSelected(bool selected)
|
|||
|
{
|
|||
|
isSelected = selected;
|
|||
|
nameText.fontSize = isSelected ? 24 : 14; // ѡ<>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
nameText.color = isSelected ? selectedColor : (isAdded ? addedColor : defaultColor);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
private void OnButtonClick()
|
|||
|
{
|
|||
|
onClick?.Invoke();
|
|||
|
}
|
|||
|
}
|