94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster.PerfectWorld.Scripts.Task.UI
|
|
{
|
|
public class TaskTreeViewItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text m_text;
|
|
[SerializeField] private Button m_Button;
|
|
|
|
[Header("DEBUG")]
|
|
[SerializeField] private uint m_uItemData;
|
|
|
|
|
|
public UnityEvent<uint> OnClick = new UnityEvent<uint>();
|
|
|
|
#region UNITY_METHODS
|
|
|
|
private void Awake()
|
|
{
|
|
m_Button.onClick.AddListener(OnBtnClick);
|
|
|
|
|
|
}
|
|
|
|
// private void Start()
|
|
// {
|
|
// RectTransform parent = transform.parent.GetComponent<RectTransform>();
|
|
// if (parent != null && parent.GetComponent<ContentSizeFitter>())
|
|
// {
|
|
// // Force Unity to rebuild layout immediately
|
|
// parent.ForceUpdateRectTransforms();
|
|
// LayoutRebuilder.ForceRebuildLayoutImmediate(parent);
|
|
// }
|
|
// }
|
|
|
|
#endregion
|
|
public void SetItemData(uint uItemData)
|
|
{
|
|
m_uItemData = uItemData;
|
|
gameObject.name = $"Task_{uItemData}";
|
|
}
|
|
|
|
public uint GetItemData()
|
|
{
|
|
return m_uItemData;
|
|
}
|
|
|
|
public void SetItemTextColor(Color color)
|
|
{
|
|
|
|
if (m_text != null)
|
|
{
|
|
m_text.color = color;
|
|
}
|
|
}
|
|
|
|
public void SetItemText(string text)
|
|
{
|
|
if (m_text != null)
|
|
{
|
|
m_text.text = text;
|
|
}
|
|
}
|
|
|
|
// public void OnPointerClick(PointerEventData eventData)
|
|
// {
|
|
// OnClick.Invoke(m_uItemData);
|
|
// EventBus.Publish(new TaskItemClickEvent() { Data = m_uItemData });
|
|
// // TaskWindow.Instance.OnEventLButtonDown_Tv_Quest(m_uItemData);
|
|
// }
|
|
|
|
void OnBtnClick()
|
|
{
|
|
OnClick.Invoke(m_uItemData);
|
|
EventBus.Publish(new TaskItemClickEvent() { Data = m_uItemData });
|
|
}
|
|
|
|
}
|
|
|
|
public struct TaskItemClickEvent
|
|
{
|
|
public uint Data;
|
|
|
|
public TaskItemClickEvent(uint data)
|
|
{
|
|
Data = data;
|
|
}
|
|
}
|
|
} |