Advertisement
NormanRich

LeoECSRetroBlitGame

Jun 19th, 2019
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. using Leopotam.Ecs;
  6.  
  7. public class LeoECSGame : RB.IRetroBlitGame
  8. {
  9.     EcsWorld _world;
  10.     EcsSystems _systemsUpdate;
  11.     EcsSystems _systemsRender;
  12.     public RB.HardwareSettings QueryHardware()
  13.     {
  14.         var hw = new RB.HardwareSettings();
  15.         hw.DisplaySize = new Vector2i(320, 320);
  16.         return hw;
  17.     }
  18.  
  19.     public bool Initialize()
  20.     {
  21.         _world = new EcsWorld();
  22.  
  23. #if UNITY_EDITOR
  24.         Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
  25. #endif  
  26.         //
  27.         _systemsUpdate = new EcsSystems(_world)
  28.             .Add(new Client.CommonFilters())
  29.             .Add(new Client.GameInit())
  30.             .Add(new Client.GameInput());
  31.         _systemsRender = new EcsSystems(_world)
  32.             .Add(new Client.CommonFilters())
  33.             .Add(new Client.Prerender())
  34.             .Add(new Client.DrawSprites());
  35.         //
  36. #if UNITY_EDITOR
  37.         Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systemsUpdate);
  38.         Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systemsRender);
  39. #endif
  40.         //
  41.         _systemsUpdate.Initialize();
  42.         _systemsRender.Initialize();
  43.         return true;
  44.     }
  45.     public void Update()
  46.     {
  47.         _systemsUpdate.Run();
  48.     }
  49.     public void Render()
  50.     {
  51.         _systemsRender.Run();
  52.         _world.RemoveOneFrameComponents();
  53.     }
  54.     public void GameEnd()
  55.     {
  56.         _systemsUpdate.Dispose();
  57.         _systemsUpdate = null;
  58.         _systemsRender.Dispose();
  59.         _systemsRender = null;
  60.         _world.Dispose();
  61.         _world = null;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement