Example #1
0
        void Start()
        {
            world   = new EcsWorld();
            systems = new EcsSystems(world);

#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(systems);
#endif
            // order is important
            systems.Add(new GameMatchLauncherSystem());
            systems.Add(new AiSystem());

            systems.Add(new OrderingSystem());

            systems.Add(new MovableSystem());
            systems.Add(new TurretSystem());
            systems.Add(new AttackSystem());
            systems.Add(new HarvestingSystem());

            systems.Add(new NavMeshSystem());
            systems.Add(new ProductionSystem());

            systems.Add(new SelectionSystem());

            systems.Add(new SpawnUnitsSystem());
            systems.Add(new ChangeUnitOwnerSystem());
            systems.Add(new SearchEnemySystem());
            systems.Add(new UnitsEffectsSystem());

            systems.Add(new PlayersSystem());
            systems.Add(new CameraSystem());

            systems.Add(new UI.FloatingSystem()); // todo move to UI init system?
            systems.Add(new UI.HealthbarsSystem());
            systems.Add(new UI.GameInfoSystem());

            systems.Add(new ProcessDamageSystem());

            systems.Inject(StartData);
            systems.Inject(Camera.main);
            systems.Inject(UICanvas);

            systems.OneFrame <TakeDamageEvent>();
            systems.OneFrame <ChangeUnitOwnerEvent>();
            systems.OneFrame <MoveOrderEvent>();
            systems.OneFrame <SpawnUnitEvent>();
            systems.OneFrame <ShootEvent>();
            systems.OneFrame <RequestBuyUnitEvent>();

            systems.OneFrame <UI.RemoveHealthbarEvent>();
            systems.OneFrame <UI.AddHealthbarEvent>();
            systems.OneFrame <SpendPlayerResourcesEvent>();
            systems.OneFrame <SpendFieldResourcesEvent>();
            systems.OneFrame <AddPlayerResourcesEvent>();

            systems.Init();
        }
Example #2
0
    void Awake()
    {
        scoreService.Init();
        Service <ScoreService> .Set(scoreService);



        World              = new EcsWorld();
        systemsUpdate      = new EcsSystems(World);
        systemsFixedUpdate = new EcsSystems(World);
#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(World);
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(systemsUpdate);
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(systemsFixedUpdate);
#endif

        //Init Systems:

        //Update Systems:
        systemsUpdate.Add(new ECS.Systems.InputSystem());
        systemsUpdate.Add(new ECS.Systems.DelaySystem());
        systemsUpdate.Add(new ECS.Systems.MovementPlayerSystem());
        systemsUpdate.Add(new ECS.Systems.MovementSystem());
        systemsUpdate.Add(new ECS.Systems.ShootPlayerSystem());
        systemsUpdate.Add(new ECS.Systems.GeneratorSystem());
        systemsUpdate.Add(new ECS.Systems.ShootSystem());
        systemsUpdate.Add(new ECS.Systems.ScoreSystem());
        systemsUpdate.Add(new ECS.Systems.ScoreOutSystem());



        //Events:
        systemsUpdate.Add(new ECS.Systems.Events.CollisionPlayerEvent());
        systemsUpdate.Add(new ECS.Systems.Events.CollisionBulletEvent());
        systemsUpdate.Add(new ECS.Systems.Events.HitEventSystem());
        systemsUpdate.Add(new ECS.Systems.Events.RestartGameEventSystem());
        systemsUpdate.Add(new ECS.Systems.Events.DestroyEntityEventSystem());

        //Events UI:

        // register one-frame components (order is important), for example:
        // .OneFrame<TestComponent1> ()
        // .OneFrame<TestComponent2> ()

        // inject service instances here (order doesn't important), for example:
        // .Inject (new CameraService ())
        // .Inject (new NavMeshSupport ())


        systemsUpdate.Inject(gameData);
        systemsUpdate.Inject(scoreService);
        systemsUpdate.InjectUi(uiEmitter);
        systemsUpdate.Init();

        systemsFixedUpdate.Init();
    }
Example #3
0
        /// <summary>
        /// Injects named UI objects and Emitter to all systems added to EcsSystems.
        /// </summary>
        /// <param name="ecsSystems">EcsSystems group.</param>
        /// <param name="emitter">EcsUiEmitter instance.</param>
        /// <param name="skipNoExists">Not throw exception if named action not registered in emitter.</param>
        /// <param name="skipOneFrames">Skip OneFrame-event cleanup registration.</param>
        public static EcsSystems InjectUi(this EcsSystems ecsSystems, EcsUiEmitter emitter, bool skipNoExists = false, bool skipOneFrames = false)
        {
            if (!skipOneFrames)
            {
                InjectOneFrames(ecsSystems);
            }
            ecsSystems.Inject(emitter);
            emitter.World = ecsSystems.World;
            var uiNamedType   = typeof(EcsUiNamedAttribute);
            var goType        = typeof(GameObject);
            var componentType = typeof(Component);
            var systems       = ecsSystems.GetAllSystems();

            for (int i = 0, iMax = systems.Count; i < iMax; i++)
            {
                var system     = systems.Items[i];
                var systemType = system.GetType();
                foreach (var f in systemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    // skip statics or fields without [EcsUiNamed] attribute.
                    if (f.IsStatic || !Attribute.IsDefined(f, uiNamedType))
                    {
                        continue;
                    }
                    var name = ((EcsUiNamedAttribute)Attribute.GetCustomAttribute(f, uiNamedType)).Name;
#if DEBUG
                    if (string.IsNullOrEmpty(name))
                    {
                        throw new Exception($"Cant Inject field \"{f.Name}\" at \"{systemType}\" due to [EcsUiNamed] \"Name\" parameter is invalid.");
                    }
                    if (!(f.FieldType == goType || componentType.IsAssignableFrom(f.FieldType)))
                    {
                        throw new Exception($"Cant Inject field \"{f.Name}\" at \"{systemType}\" due to [EcsUiNamed] attribute can be applied only to GameObject or Component type.");
                    }
                    if (!skipNoExists && !emitter.GetNamedObject(name))
                    {
                        throw new Exception($"Cant Inject field \"{f.Name}\" at \"{systemType}\" due to there is no UI action with name \"{name}\".");
                    }
#endif
                    var go = emitter.GetNamedObject(name);
                    // GameObject.
                    if (f.FieldType == goType)
                    {
                        f.SetValue(system, go);
                        continue;
                    }
                    // Component.
                    if (componentType.IsAssignableFrom(f.FieldType))
                    {
                        f.SetValue(system, go != null ? go.GetComponent(f.FieldType) : null);
                    }
                }
            }
            return(ecsSystems);
        }
Example #4
0
    void Awake()
    {
        // void can be switched to IEnumerator for support coroutines.

        scoreService.Init();
        Debug.Log(scoreService.BestResult);
        Service <ScoreService> .Set(scoreService);

        Debug.Log(Service <ScoreService> .Get().BestResult);


        World         = new EcsWorld();
        systemsUpdate = new EcsSystems(World);
#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(World);
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(systemsUpdate);
#endif

        //Init Systems:
        systemsUpdate.Add(new ECS.Systems.MenuUiInitSystem());

        //Update Systems:

        //Events:

        //Events UI:
        systemsUpdate.Add(new ECS.Systems.Events.MenuButtonsClicksSystem());

        // register one-frame components (order is important), for example:
        // .OneFrame<TestComponent1> ()
        // .OneFrame<TestComponent2> ()

        // inject service instances here (order doesn't important), for example:
        // .Inject (new CameraService ())
        // .Inject (new NavMeshSupport ())
        systemsUpdate.Inject(scoreService);

        systemsUpdate.Inject(MenuUi);
        systemsUpdate.InjectUi(uiEmitter);
        systemsUpdate.Init();
    }
Example #5
0
        public void Initialize()
        {
            _systems = new EcsSystems(_world);

            _systems

            .Inject(PhotonServer)
            .Inject(SceneDescription)
            .Inject(PlayerCache)
            .Initialize()
            ;
        }
Example #6
0
        private void Start()
        {
            var camera = Camera.main;

            _world       = new EcsWorld();
            _mainSystems = new EcsSystems(_world);
#if UNITY_EDITOR
            if (_createDebugObserversOnStartup)
            {
                Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
                Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_mainSystems);
            }
#endif

            var boardGenSystems = new EcsSystems(_world, "board_gen")
                                  .Add(new BoardGen.BoardLayoutInitSystem())
                                  .Add(new BoardGen.BoardGenerationInitSystem())
                                  .Add(new BoardGen.BoardTilePairCreateSystem(_tileSet.TileCount))
                                  .Add(new BoardGen.BoardGenerationStepSystem())
                                  .Add(new BoardGen.BoardGenerationCompleteSystem())

                                  .Add(new CameraSetupSystem(camera))

                                  .Inject((IMapService) new TextMapService(_mapFile.text));

            boardGenSystems.Inject(boardGenSystems);

            _mainSystems
            .Add(boardGenSystems)

            .Add(new TileLockSystem())
            .Add(new TileSelectionSystem(camera))
            .Add(new TileMatchSystem())

            .Add(new TileViewCreateSystem())
            .Add(new TileViewUpdateSystem())

            .Add(new TileDestroyMatchedSystem())

            .OneFrame <Locked>()
            .OneFrame <Matched>()
            .OneFrame <Mismatched>()

            .Inject(GetComponent <ITileViewService>())

            .Init();
        }
Example #7
0
        void OnEnable()
        {
            _world   = new EcsWorld();
            _systems = new EcsSystems(_world);

            _worldStatusInject     = new WorldStatus();
            _entitiesPresetsInject = new EntitiesPresetsInject(presets);

#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif
            _systems
            //.Add(new TestsSystem())
            .Add(new ProjectileSystem())

            .Add(new QueueSystem())
            .Add(new PhaseManagerSystem())
            .Add(new NextTurnSystem())
            .Add(new ZonesSystem())
            .Add(new LevelManagerSystem())
            .Add(new TargetSystem())
            .Add(new InputUserPhaseSystem())
            .Add(new InputNPCPhaseSystem())
            .Add(new ActionPhaseSystem())
            .Add(new ActionMoveSystem())
            .Add(new ActionAttackSystem())
            .Add(new ActionAnimationSystem())
            .Add(new EnvironmentPhaseSystem())
            .Add(new SpellSystem())
            .Add(new ModificationPhaseSystem())
            .Add(new DamageSystem())
            .Add(new AppearanceSystem())
            .Add(new GameOverSystem())
            .Add(new EffectSystem())
            .Add(new UISystem())
            .Add(new CameraSystem());

            _systems
            .Inject(_worldStatusInject)
            .Inject(_entitiesPresetsInject);


            _systems.Init();
        }
Example #8
0
        void Injected()
        {
            updateSystems
            .Inject(dataGame)
            .Inject(dataLevel)
            .Inject(mainCamera)
            .Inject(playerSpawnPoint)
            .Inject(enemySpawnPoints)
            .Inject(waitpoints)
            .Inject(new GamePool())
            .Inject(new PlayerTankBuilder())
            .Inject(new EnemyTankBuilder())
            .ProcessInjects();

            fixedSystems
            .Inject(dataGame)
            .ProcessInjects();
        }
Example #9
0
        IEnumerator Start()
        {
            yield return(null);

            yield return(null);

            yield return(null);

            _world   = new EcsWorld();
            _systems = new EcsSystems(_world, "room");
#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif
            _systems
            .Add(new RoomSystem())
            .Add(new RoomEventCourierSystem())
            .Add(new MovementSystem())
            .Add(new ResurrectionSystem())
            .Add(new JoystickInputSystem())
            .Add(new PushSystem())
            .Add(new CameraSystem())
            .Add(new RoomEventReceiverSystem());

            // Events
            _systems
            .OneFrame <PushEvent>()
            .OneFrame <StayEvent>();

            _systems
            .Inject(_definition)
            .Inject(Game.JoystickBehaviour)
            .Inject(Game.CameraBehaviour)
            .Inject(Game.TeeBehaviour)
            .Inject(Game.HoleBehaviour)
            .Inject(new RoomService())
            .ProcessInjects()
            .Init();

            Game.room = new Room(_world);
        }
Example #10
0
 private void InjectDependencies(EcsSystems systems)
 {
     systems.Inject(ConfigurationServiceStub)
     .Inject(DxfServiceStub)
     .Inject(FileSystemServiceStub);
 }
Example #11
0
    private void OnEnable()
    {
        ecsWorld       = new EcsWorld();
        systems        = new EcsSystems(ecsWorld);
        systemsPhysics = new EcsSystems(ecsWorld);
        random         = new System.Random();

#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(ecsWorld);
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(systems);
#endif

        systems
        .Add(new InputControllerSystem())
        .Add(new MovementSystem())
        .Add(new RotationSystem())
        .Add(new CooldownRateSystem())
        .Add(new FireSystem())
        .Add(new ProjectileMoveSystem())
        .Add(new DamageSystem())
        .Add(new HpShowSystem())
        .Add(new PhotonHealthPointSystem())
        .Add(new PlayerSpawnSystems())
        .Add(new DestroySystem())
        .Add(new SpawnCaptureSystem())
        .Add(new SpawnInitSystem())
        .Add(new CrossCaptureSystem())
        .Add(new ProjectileLifetimeSystem())
        .Add(new DestroyedCounter())
        .Add(new PerkInitSystem())
        .Add(new ProgressSystem())
        .Add(new PerkSystem())

        .Add(new AIControllerSystem())
        .Add(new AIMoveDirectionSystem())
        .Add(new AIRotationSystem())
        .Add(new AIFireSystem())
        .Add(new AIPerkSystem())



        .Add(new Perk1System())
        .Add(new Perk2System())
        .Add(new Perk3System())
        //.Add(new AIMoveDirectionSystem())
        //.Add(new AIMoveDirectionSystem())
        .OneFrame <PhotonHealthPointEvent>()
        .OneFrame <ProjectileCollisionEvent>()
        .OneFrame <PlayerSpawnEvent>()
        .OneFrame <DestroyEvent>()
        .OneFrame <ProgressEvent>()

        .OneFrame <Perk1>()
        .OneFrame <Perk2>()
        .OneFrame <Perk3>()

        .Inject(gameManager)
        .Inject(joystick);


        systemsPhysics
        //.Add(new CarAccelerationSystem())
        //.Add(new CarDecelerationSystem())
        .Inject(gameManager);

        systems.ProcessInjects();
        systemsPhysics.ProcessInjects();
    }
Example #12
0
        public void Start()
        {
            var ss       = CreateSharedState(_options);
            var worldCfg = new EcsWorldConfig()
            {
                FilterEntitiesCacheSize = _options.EntitiesMax,
                WorldEntitiesCacheSize  = _options.EntitiesMax,
            };

            _world = new EcsWorld(worldCfg);

            _systems = new EcsSystems(_world, "RUN SYSTEMS");

            _systems
            .Add(new InitSystem())
            .Add(new TimeSystem())
            .Add(new ShootSystem())
            .Add(new BulletSystem())
            .Add(new MoveSystem())
            ;

            AddActorTypeSystemsByTypeCount();

            if (_isRendering)
            {
                _systems
                .Add(new ActorViewUpdateSystem())
                .Add(new BulletViewDeleteSystem())
                .Add(new BulletViewUpdateSystem())
                ;
            }

            _systems
            .Add(new BulletDeleteSystem())
            ;

            _systems
            .Inject(ss)
            .Inject(new TimeService())
            .Inject(new ActorService())
            .Inject(new BulletService())
            ;

            if (_isRendering)
            {
                var bullet            = _options.BulletPrefab;
                var bulletViewService = new BulletViewService()
                {
                    Pool = new Pool <Transform>(
                        () =>
                    {
                        var tr = Object.Instantiate(bullet).transform;
                        tr.gameObject.SetActive(false);
                        return(tr);
                    }, 2),
                    Views = new Dictionary <int, Transform>()
                };
                var actor = _options.ShooterPrefab;

                var actorViewService = new ActorViewService()
                {
                    Pool = new Pool <Transform>(
                        () =>
                    {
                        var tr = Object.Instantiate(actor).transform;
                        tr.gameObject.SetActive(false);
                        return(tr);
                    }, 2),
                    Views = new Dictionary <int, Transform>()
                };

                _systems
                .Inject(bulletViewService)
                .Inject(actorViewService)
                ;
            }

            _systems.ProcessInjects();
            _systems.Init();
        }
Example #13
0
        void OnEnable()
        {
            _world       = new EcsWorld();
            _systems     = new EcsSystems(_world);
            _viewSystems = new EcsSystems(_world, "UnityView");

            Application.targetFrameRate = 60;
            _gameView.Init();

            UnityIntegration();

            _systems
            .Add(new CoreGameInit())
            .Add(new Utils.UnityTimeSystem())
            // user input
            .Add(new UserInput.TapTrackerSystem())

            // networking
            .Add(new PlayersUpdateIssuingSystem(_playerApi))
            .Add(new SyncWorldSystem(_worldApi))
            .Add(new ConnectSystem(_playerApi))
            .Add(new PlayersUpdateSystem(_playerApi))
            .Add(new DestroyNetSystem(_playerApi))
            .Add(new BuyNetSystem(_playerApi))
            .Add(new MoveNetSystem(_playerApi))
            .Add(new AttackNetSystem(_playerApi))
            .Add(new HealNetSystem(_playerApi))

            // stuff
            .Add(new SpawnPlayerProcessing(_playerApi))
            .Add(new UpdateUserPlanetProcessing())
            .Add(new UpdatePlayerPointProcessing())
            .Add(new UpdateOwnersProcessing(_worldApi))
            .Add(new MoveTargetSys())

            // object rotating system
            .Add(new ObjectRotationSystem())

            // camera
            .Add(new CameraSystem())
            .Add(new FollowPlayerCamera())

            // space objects markers
            .Add(new MarkersControlSystem(_playerApi));

            _viewSystems
            // view allocations
            .Add(new ViewAllocatorSystem(_gameView))

            // view sync
            .Add(new Positioning.Systems.UPositionSyncSystem())
            .Add(new Positioning.Systems.URotationsSyncSystem())

            // rendering
            .Add(new UMeshRenderer.Systems.MatrixPositionUpdate())
            .Add(new UMeshRenderer.Systems.UMeshRenderer())

            //ui
            .Add(new UIUpadteIssuer(0.5f))
            .Add(new UICoreECS.ScreenSwitchSystem(_screens, _uiRoot))
            .Add(new UIPlayerStatsUpdateSystem())
            .Add(new UICurrentPlanetPanelDrawer(_playerApi))
            .Add(new InfoPopUpProcessing())
            .Add(new UISelectedPlanetPanelDrawer(_playerApi));

            _systems
            .OneFrame <Positioning.Components.LazyPositionUpdate>()
            .OneFrame <LoginActionTag>()
            .OneFrame <LoggedInTag>()
            .OneFrame <PlayersUpdateTag>()
            .OneFrame <SpawnPlayerTag>()
            .OneFrame <UpdateOwnersTag>()
            .OneFrame <BuyActionTag>()
            .OneFrame <DestroyActionTag>()
            .OneFrame <MoveActionTag>()
            .OneFrame <PointerClicked>()
            .OneFrame <AttackActionTag>()
            .OneFrame <HealActionTag>();

            _viewSystems
            .OneFrame <AllocateView>()
            .OneFrame <Positioning.Components.LazyPositionUpdate>()
            .OneFrame <UIUpdate>();

            _systems.Add(_viewSystems);

            _systems.Inject(new Utils.TimeService());
            _systems.Init();
        }
Example #14
0
 /// <summary>
 /// Injects data globally (for root system and all child systems).
 /// </summary>
 public void Inject(object data, Type overridenType = null)
 {
     RootSystems.Inject(data, overridenType);
 }