JasonXuDeveloper / JEngine

The solution that allows unity games to update in runtime. 使Unity开发的游戏支持热更新的解决方案。
https://docs.xgamedev.net/
MIT License
2k stars 332 forks source link

JBehaviour Loop Failed #511

Open manbaaa opened 5 months ago

manbaaa commented 5 months ago

在热更方法 RunGame 里动态创建JBehaviour,最开始创建的前几个的Loop方法不会执行。

需要打包环境测试,在JBehaviour.cs里屏蔽掉如下代码:

//编辑器下可视化 if (Application.isEditor) { var id = AddClassBind(gameObject, activeAfter, typeof(T)); var ret = (T)JBehaviours[id]; ret.Check(); return ret; }

可以在Unity编辑器下重现,前提是FpsMonitor里的_backupFrames初始化为0;

manbaaa commented 5 months ago

public JBehaviour Activate() { //主线程 ThreadMgr.QueueOnMainThread(() => { Awake(); var duration = 1f / ((float)Application.targetFrameRate <= 0 ? FpsMonitor.FPS : Application.targetFrameRate); duration = duration / TimeScale; ThreadMgr.QueueOnMainThread(() => { OnEnable(); Start(); }, duration); }); return this; }

测试下来是因为在 JBehaviour 执行 Activate是 FpsMonitor.FPS值为0,导致duration值很大。