案例:Assets/Scripts/Example/3.UIFrame/UIEvent/UIEventExample.unity
1).UI脚本注册事件
UIMainEvent脚本RegisterUIEvent函数 :
protected override void RegisterUIEvent()
{
trans.onClick.AddListener(()=>
{
UIManager.Instance.OpenUI<UIChildEvent>((int)eventUITag.UIChildEvent, null, panelLayer: PanelLayer.Load, isClear: true);
});
RegisterEvent((int)eventID.changeMainColor, ChangeColor);
}
//事件响应
private void ChangeColor(int key,MsgInfo param)
{
if (param != null && param.DataList.Count > 0)
{
Color color = (Color)param.DataList[0];
bg.color = color;
}
}
2).发送UI消息
这个案例时打开子面板然后点击子面板按钮改变父面板背景颜色
子面板UIChildEvent :
protected override void RegisterUIEvent()
{
button.onClick.AddListener(() =>
{
SendMsg((int)eventID.changeMainColor,new MsgInfo(Color.red));
});
}