3.4.2 建议:多 Scene 支持和多 PhysicScene 支持

需求背景

Unity 提供了以下特性:

这对于多人游戏场景下,实现 实现物理同步时的客户端预测 非常实用。

例子:https://github.com/spectre1989/unity_physics_csp

目前的问题

  1. Cocos 仅支持单 Scene 运行,并且 PhysicSystem 是全局单例
  2. 目前 PhysicSystem 的更新和视图层更新绑定(都由 director.tick 驱动)

这些导致想离屏单独运行一个物理场景,来单独完成物理的预测计算,变得困难

建议

  1. PhysicSystem 不再是一个单例,而是与 Scene 绑定,一个 Scene 有一个 PhysicSystem (叫 PhysicScene 可能更贴切)
  2. 支持多个 Scene 同时运行(以叠加方式 loadScene),某些 Scene 可能不跑渲染(没有 Camera)
  3. 增加 PhysicSystem.autoUpdate 的选项,来支持手动更新物理系统,如 Physics-autoSimulation - Unity 脚本 API

例如:

// 以叠加方式 loadScene
let scene = await director.loadSceneAdditive('XXXScene');

// Physic 不再是全局单例,跟着场景走
let physicScene = scene1.getPhysicScene();

// 手动步进物理
physicScene.autoUpdate = false;
physicScene.update(dt);
2赞