监听下拉选择组件是否打开选项

可以发现下拉组件打开的内容是复制Template的,所以可以利用这个,创建两个脚本,一个用来接受,一个用来监听是不是打开了。

Dropdown挂载接受脚本,Template挂载监听脚本

image.png


using System;

public class ReceiveDropDownStatus : UIMonoViewComponent
{
    public Action<bool> StatusChange;
}


using Frame.Runtime.UI;

public class ListenDropDownStatus : UIMonoViewComponent
{
    private ReceiveDropDownStatus m_Receive;

    // Start is called before the first frame update
    void Start()
    {
        if (m_Receive == null)
        {
            m_Receive = this.transform.parent.GetComponent<ReceiveDropDownStatus>();
        }

        if (this.gameObject.name == "Dropdown List")
        {
            if (m_Receive.StatusChange != null)
            {
                m_Receive.StatusChange(true);
            }
        }
    }

    private void OnDisable()
    {
        if (this.gameObject.name == "Dropdown List")
        {
            if (m_Receive.StatusChange != null)
            {
                m_Receive.StatusChange(false);
            }
        }
    }
}



首页 我的博客
粤ICP备17103704号