1.后台数据获取可能会分为好几级,打开关闭想到Toggle会好用点,首先先扩展注册UI事件的脚本
public class EventListenerTrigger :MonoBehaviour, IPointerClickHandler,
IPointerDownHandler,
IPointerEnterHandler,
IPointerExitHandler,
IPointerUpHandler,
ISelectHandler,
IUpdateSelectedHandler,
IDeselectHandler,
IDragHandler,
IEndDragHandler,
IDropHandler,
IBeginDragHandler,
IScrollHandler,
IMoveHandler {
public delegate void VoidDelegate(GameObject go,object obj);
public VoidDelegate onClick;
public VoidDelegate onDown;
public VoidDelegate onEnter;
public VoidDelegate onExit;
public VoidDelegate onUp;
public VoidDelegate onSelect;
public VoidDelegate onUpdateSelect;
public VoidDelegate onDeSelect;
public VoidDelegate onDrag;
public VoidDelegate onDragEnd;
public VoidDelegate onDrop;
public VoidDelegate onScroll;
public VoidDelegate onMove;
public VoidDelegate onBeginDrag;
public VoidDelegate ToggleEvent;
ScrollRect scrollRect;
Toggle tg;
object obj;
bool isDrag = false;
void Start () {
scrollRect= GetParentScrollRect(transform);
tg = GetComponent<Toggle>();
if (tg)
{
tg.onValueChanged.AddListener((isOn) => {
if (ToggleEvent!=null)
{
Unity中使用Toggle动态创建UI

本文介绍了在Unity中如何动态生成与Toggle相关的UI界面,包括扩展注册UI事件的脚本,利用ToggleEvent进行事件监听,以及如何创建Toggle列表。同时,针对Toggle的单选需求,提出了给ToggleGroup添加Toggle并判断点击同一物体来实现效果的方法。
最低0.47元/天 解锁文章
2473

被折叠的 条评论
为什么被折叠?



