2021-04-16 21:07:32 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using UnityExplorer.UI.ObjectPool;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public class ButtonCell : ICell
|
2021-04-16 21:07:32 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public float DefaultHeight => 25f;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
public Action<int> OnClick;
|
|
|
|
|
public int CurrentDataIndex;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public ButtonRef Button;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
#region ICell
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public GameObject UIRoot => uiRoot;
|
|
|
|
|
public GameObject uiRoot;
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public bool Enabled => m_enabled;
|
|
|
|
|
private bool m_enabled;
|
|
|
|
|
|
|
|
|
|
public RectTransform Rect => m_rect;
|
|
|
|
|
private RectTransform m_rect;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = false;
|
|
|
|
|
uiRoot.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Enable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = true;
|
|
|
|
|
uiRoot.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public GameObject CreateContent(GameObject parent)
|
2021-04-16 21:07:32 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
uiRoot = UIFactory.CreateHorizontalGroup(parent, "ButtonCell", true, true, true, true, 2, default,
|
|
|
|
|
new Color(0.11f, 0.11f, 0.11f), TextAnchor.MiddleCenter);
|
|
|
|
|
m_rect = uiRoot.GetComponent<RectTransform>();
|
|
|
|
|
m_rect.anchorMin = new Vector2(0, 1);
|
|
|
|
|
m_rect.anchorMax = new Vector2(0, 1);
|
|
|
|
|
m_rect.pivot = new Vector2(0.5f, 1);
|
|
|
|
|
m_rect.sizeDelta = new Vector2(25, 25);
|
|
|
|
|
UIFactory.SetLayoutElement(uiRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
uiRoot.SetActive(false);
|
|
|
|
|
|
|
|
|
|
this.Button = UIFactory.CreateButton(uiRoot, "NameButton", "Name");
|
|
|
|
|
UIFactory.SetLayoutElement(Button.Button.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
var buttonText = Button.Button.GetComponentInChildren<Text>();
|
|
|
|
|
buttonText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
|
|
buttonText.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
|
|
|
|
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
2021-04-16 21:07:32 +10:00
|
|
|
|
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
|
|
|
|
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
|
|
|
|
Color disabled = new Color(1, 1, 1, 0);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(Button.Button, normal, highlight, pressed, disabled);
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Button.OnClick += () => { OnClick?.Invoke(CurrentDataIndex); };
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
return uiRoot;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|