2025-09-26 16:30:50 +08:00

99 lines
2.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;
using System.Xml.Serialization;
namespace SuperTreeView
{
public class ItemPrefab1 : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public Button mExpandBtn;
public Button mClickBtn;
public TextMeshProUGUI TextName;
public TextMeshProUGUI TextName2;
public Image ImageNormal;
public Image ImageHover;
public Image ImageSelect;
string mData = "";
public string Data
{
get
{
return mData;
}
set
{
mData = value;
}
}
void Start()
{
mExpandBtn.onClick.AddListener(OnExpandBtnClicked);
mClickBtn.onClick.AddListener(OnExpandBtnClicked);
}
void OnExpandBtnClicked()
{
TreeViewItem item = GetComponent<TreeViewItem>();
item.DoExpandOrCollapse();
}
public void SetItemInfo(string labelTxt, string data)
{
TextName.text = labelTxt;
TextName2.text = labelTxt;
mData = data;
}
public bool IsSelected
{
get
{
return ImageSelect.gameObject.activeSelf;
}
set
{
ImageSelect.gameObject.SetActive(value);
}
}
public void SetExpandStatus(bool expand)
{
if (expand)
{
mExpandBtn.transform.localEulerAngles = new Vector3(0, 0, -90);
IsSelected = true;
}
else
{
mExpandBtn.transform.localEulerAngles = new Vector3(0, 0, 0);
IsSelected = false;
}
}
public void OnPointerExit(PointerEventData eventData)
{
ImageHover.gameObject.SetActive(false);
}
public void OnPointerEnter(PointerEventData eventData)
{
ImageHover.gameObject.SetActive(true);
}
public void LockClick()
{
//TextName.color = new Color(1, 1, 1, 0.2f);
//TextName2.color = new Color(1, 1, 1, 0.2f);
mClickBtn.interactable = false;
}
public void UnlockClick()
{
//TextName.color = new Color(1, 1, 1, 1);
//TextName2.color = new Color(1, 1, 1, 1);
mClickBtn.interactable = true;
}
}
}