121 lines
3.2 KiB
C#
121 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
namespace SuperTreeView
|
|
{
|
|
public class ItemScript2 : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
|
|
{
|
|
public Button mExpandBtn;
|
|
public Image mIcon;
|
|
public Image mSelectImg;
|
|
public Image mHoverImg;
|
|
public Button mClickBtn;
|
|
public Text mLabelText;
|
|
public Text mSelectText;
|
|
public Text mHoverText;
|
|
|
|
public Image mLineHorizontal;
|
|
public Image mLineVertical;
|
|
public Image mLineVertical_2;
|
|
public Image mExpandImg;
|
|
public string mdata;
|
|
|
|
public Sprite expand_minus;
|
|
public Sprite expand_add;
|
|
|
|
void Start()
|
|
{
|
|
mExpandBtn.onClick.AddListener(OnExpandBtnClicked);
|
|
mClickBtn.onClick.AddListener(OnItemClicked);
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
SetExpandBtnVisible(false);
|
|
SetExpandStatus(true);
|
|
IsSelected = false;
|
|
}
|
|
|
|
void OnExpandBtnClicked()
|
|
{
|
|
TreeViewItem item = GetComponent<TreeViewItem>();
|
|
item.DoExpandOrCollapse();
|
|
}
|
|
|
|
|
|
public void SetItemInfo(string iconSpriteName, string labelTxt,string data = "")
|
|
{
|
|
Init();
|
|
if (!string.IsNullOrEmpty(iconSpriteName))
|
|
{
|
|
mIcon.sprite = SpriteResMgr.Instance.GetSpriteByName(iconSpriteName);
|
|
}
|
|
mLabelText.text = labelTxt;
|
|
mSelectText.text = labelTxt;
|
|
mHoverText.text = labelTxt;
|
|
mdata = data;
|
|
}
|
|
|
|
void OnItemClicked()
|
|
{
|
|
TreeViewItem item = GetComponent<TreeViewItem>();
|
|
item.RaiseCustomEvent(CustomEvent.ItemClicked, mdata);
|
|
}
|
|
|
|
public void SetExpandBtnVisible(bool visible)
|
|
{
|
|
if (visible)
|
|
{
|
|
mExpandBtn.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
mExpandBtn.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public bool IsSelected
|
|
{
|
|
get
|
|
{
|
|
return mSelectImg.gameObject.activeSelf;
|
|
}
|
|
set
|
|
{
|
|
mSelectImg.gameObject.SetActive(value);
|
|
mIcon.gameObject.SetActive(!value);
|
|
if (value)
|
|
{
|
|
mHoverImg.gameObject.SetActive(!value);
|
|
}
|
|
}
|
|
}
|
|
public void SetExpandStatus(bool expand)
|
|
{
|
|
if (expand)
|
|
{
|
|
mExpandImg.sprite = expand_minus;
|
|
}
|
|
else
|
|
{
|
|
mExpandImg.sprite = expand_add;
|
|
}
|
|
}
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (!mSelectImg.gameObject.activeSelf && !string.IsNullOrEmpty(mdata))
|
|
{
|
|
mHoverImg.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
mHoverImg.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
} |