导入Entitas插件
创建一个Unity空项目,然后导入Entitas-1.13.0.unitypackage资源文件 附包下载地址
Entitas插件导入之后,按快捷键 Ctrl + Shift + G
生成Generated文件目录,再创建一个Features目录存放游戏逻辑代码,Scenes存放场景资源文件。
最终框架结构如下:
![]()
接入框架驱动类
通过MonoBehavior的生命周期函数驱动框架内的游戏控制器。
GameControllerBehavior.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| using System; using UnityEngine;
public class GameControllerBehaviour : MonoBehaviour { private GameController _gameController;
private void Awake() { _gameController = new GameController(Contexts.sharedInstance); }
private void Start() { _gameController.Initialize(); }
private void Update() { _gameController.Execute(); } }
|
GameController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| using Entitas;
public class GameController { private readonly Systems _systems; private readonly Contexts _contexts;
public GameController(Contexts contexts) { _contexts = contexts; _systems = new GameSystems(_contexts); }
public void Initialize() { _systems.Initialize(); }
public void Execute() { _systems.Execute(); _systems.Cleanup(); } }
|
GameSystem.cs
1 2 3 4 5 6 7 8 9
|
public class GameSystems : Feature { public GameSystems(Contexts contexts) { } }
|
上面三个类实现初始化所有Systems,并从MonoBehavior中驱动所有的Systems。
参考代码:commit
嵌入全局配置文件
在Jenny配置的Contexts中加入Configuration
关键字,然后点击Generate按钮生成相关代码。
![]()