Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShowPanelData 应该如何使用,能给个示例代码吗 #10

Closed
sosloop opened this issue Feb 2, 2023 · 3 comments
Closed

ShowPanelData 应该如何使用,能给个示例代码吗 #10

sosloop opened this issue Feb 2, 2023 · 3 comments

Comments

@sosloop
Copy link

sosloop commented Feb 2, 2023

No description provided.

@IcePower
Copy link
Owner

IcePower commented Feb 3, 2023

这个参数我是从字母哥的EUI里抄过来的。ShowPanelData 里只有一个参数 Entity ContextData,我猜测它的用法是向打开的界面传递参数。也可以根据需要往 ShowPanelData 里加入其他的字段,比如控制界面的弹出方式、释放策略等。
比如我现在要向 LobbyPanel 传个参数 LobbyPanelContext

[ChildOf(typeof(ShowPanelData))]
public class LobbyPanelContext: Entity, IAwake
{
    public string Name { get; set; }
}

在打开界面的地方这样使用:

ShowPanelData showPanelData = fuiComponent.AddChild<ShowPanelData>();
LobbyPanelContext lobbyPanelContext = showPanelData.AddChild<LobbyPanelContext>();
lobbyPanelContext.Name = "参数";
showPanelData.ContextData = lobbyPanelContext;
await fuiComponent.ShowPanelAsync(PanelId.LobbyPanel, showPanelData);

这样在 LobbyPanelSystem.OShow 里就可以打印出 lobbyPanelContext.Name 了:

LobbyPanelContext lobbyPanelContext = contextData as LobbyPanelContext;
Log.Info(lobbyPanelContext.Name);

其他地方可能还需要根据你的需求做一些修改。
不过我们项目里这块的代码有了一些改动,之后我可以提交一下。

@sosloop
Copy link
Author

sosloop commented Feb 3, 2023

那 ShowPanelData 在哪销毁呢,每次打开都会创建

@IcePower
Copy link
Owner

IcePower commented Feb 4, 2023

fuiComponent.ShowPanelAsync 函数里会把 ShowPanelData 挂到界面上,界面销毁的时候 ShowPanelData 跟着销毁。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants