Exemple #1
0
        private void Start()
        {
            var mainCamera     = Camera.main;
            var prefabProvider = FindObjectOfType <PrefabProvider>();
            var remotePlayerInstantiationProvider = FindObjectOfType <RemotePlayerInstantiationProvider>();
            var nicknameDisplay = FindObjectOfType <NicknameDisplay>();

            _world   = new EcsWorld();
            _systems = new EcsSystems(_world);
#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif
            _systems
            .Add(new PlayerInstanceControlSystem())
            .Add(new CameraControlSystem())
            .Add(new UserInputSystem())
            .Add(new PlayerMovementSystem())
            .Add(new PlayerCooldownSystem())
            .Add(new PlayerShootSystem())
            .Add(new NicknameDisplaySystem())
            .Add(new GameStartSystem())
            .Add(new ScoreboardSystem())

            .OneFrame <PlayerInput>()
            .OneFrame <PlayerAddedEvent>()

            .Inject(mainCamera)
            .Inject(prefabProvider)
            .Inject(remotePlayerInstantiationProvider)
            .Inject(nicknameDisplay)

            .Init();
        }
        private void OnEnable()
        {
            ecsWorld     = new EcsWorld();
            systems      = new EcsSystems(ecsWorld);
            fixedSystems = new EcsSystems(ecsWorld);
            gameState    = new GameState();
            unitsPool    = gameObject.GetComponent <UnitsPool>();
            unitsPool.Prewarm(1000, configuration.unitView);

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

            systems
            .Add(new UnitsInitSystem())
            .Add(new ClickMoveSystem())
            .Add(new UnitSelectionSystem())
            .Add(new DebugInputsSystem())
            .Add(new DynamicNavSystem())
            .Inject(gameState)
            .Inject(configuration)
            .Inject(unitsPool)
            .Init();

            fixedSystems
            .Add(new SpawnCommandSystem())
            .Add(new MoveCommandSystem())
            .Inject(gameState)
            .Inject(configuration)
            .Inject(unitsPool)
            .Init();
        }
Exemple #3
0
    void OnEnable()
    {
        _world = new EcsWorld();
#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
#endif
        _gameplaySystems = new EcsSystems(_world)
                           //.Add(jitEmitter)
                           .Add(new InitializePlayerSystem())
                           .Add(new InitializeCameraSystem())
                           .Add(new InputSystem(joystick, jumpButton))
                           //.Add(new FrameSelectionSystem())
                           //.Add(new RecorderSystem())
                           //.Add(new ReplaySystem())
                           .Add(new CameraFollowSystem())
                           .Add(new PlayerDieSystem());
        _gameplaySystems.Initialize();

        _physicsSystems = new EcsSystems(_world)
                          .Add(new PlayerMoveSystem())
                          .Add(new PlayerJumpSystem());
        _physicsSystems.Initialize();

#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_gameplaySystems);
#endif
    }
Exemple #4
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            NaturalMotionMessagesDictComponent dict = _dict.Components1[0];

            var nmMessages = EcsWorld.GetComponent <NaturalMotionMessagesComponent>(woundEntity);

            if (nmMessages == null || nmMessages.MessageList.Count <= 0)
            {
                return;
            }

            var permanentRagdoll = EcsWorld.GetComponent <PermanentRagdollComponent>(pedEntity);

            if (permanentRagdoll != null && !nmMessages.PlayInPermanentRagdoll)
            {
                return;
            }
            if (permanentRagdoll != null && !permanentRagdoll.DisableOnlyOnHeal)
            {
                NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, 0, 0, 1, 0, 0, 0);
            }

            foreach (string messageName in nmMessages.MessageList)
            {
                NaturalMotionMessage nmMessage = dict.MessageDict[messageName];
                PlayNaturalMotionMessage(nmMessage, ped, _random);
            }
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} have got NM-message {nmMessages}");
#endif
        }
Exemple #5
0
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement enable = partRoot.Element("EnableFacialAnimation");

            if (enable != null)
            {
                var component = EcsWorld.AddComponent <EnableFacialAnimationComponent>(partEntity);
                component.MaleDict   = enable.GetAttributeValue("MaleDict");
                component.FemaleDict = enable.GetAttributeValue("FemaleDict");
                component.Permanent  = enable.GetBool("Permanent");

                foreach (string animation in enable.GetAttributeValue("Animations").Split(';'))
                {
                    if (!string.IsNullOrEmpty(animation))
                    {
                        component.Animations.Add(animation);
                    }
                }

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} have got {component}");
#endif
            }

            XElement disable = partRoot.Element("DisableFacialAnimation");
            if (disable != null)
            {
                EcsWorld.AddComponent <DisableFacialAnimationComponent>(partEntity);

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} will disable facial animation");
#endif
            }
        }
        public static GameObject Create(EcsWorld world, string name = null)
        {
            if (world == null)
            {
                throw new ArgumentNullException(nameof(world));
            }
            var go = new GameObject(name != null ? $"[ECS-WORLD {name}]" : "[ECS-WORLD]");

            DontDestroyOnLoad(go);
            go.hideFlags = HideFlags.NotEditable;
            var observer = go.AddComponent <EcsWorldObserver> ();

            observer._world = world;
            var worldTr = observer.transform;

            // entities root.
            observer._entitiesRoot = new GameObject("Entities").transform;
            observer._entitiesRoot.gameObject.hideFlags = HideFlags.NotEditable;
            observer._entitiesRoot.SetParent(worldTr, false);
            // filters root.
            observer._filtersRoot = new GameObject("Filters").transform;
            observer._filtersRoot.gameObject.hideFlags = HideFlags.NotEditable;
            observer._filtersRoot.SetParent(worldTr, false);
            // subscription to events.
            world.AddDebugListener(observer);
            return(go);
        }
Exemple #7
0
        public void RemoveComponentThrowExceptionTest()
        {
            EcsWorld   world  = new EcsWorld();
            IEcsEntity entity = world.CreateEntity();

            entity.RemoveComponent <ComponentA>();
        }
Exemple #8
0
        void Start()
        {
            // void can be switched to IEnumerator for support coroutines.
            _world   = new EcsWorld();
            _systems = new EcsSystems(_world);
#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif
            _systems
            .Add(new ResourceSystem())
            .Add(new StructureInitSystem())
            .Add(new StructureRunSystem())
            .Add(new BuildingMenuSystem())
            .Add(new ClickManagerSystem())
            .Add(new StabilitySystem())
            .Add(new DangerSystem())
            .Add(new ActionSystem())
            .InjectUi(_uiEmitter)


            // 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 ())
            .Init();
        }
Exemple #9
0
 private void OnDisable()
 {
     _systems.Dispose();
     _systems = null;
     _world.Dispose();
     _world = null;
 }
Exemple #10
0
        public override void Init(EcsWorld world)
        {
            UIPlayerStatsComponent stats = world.NewEntity().Set <UIPlayerStatsComponent>();

            stats.HP    = HP;
            stats.Power = Power;
        }
Exemple #11
0
    private void OnEnable()
    {
        _world   = new EcsWorld();
        _systems = new EcsSystems(_world);

#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif

        _systems
        .Add(new WorldInitSystem())
        .Add(new PlayerInitSystem())
        .Add(new GhostInitSystem())
        .Add(new WallInitSystem())
        .Add(new PortalInitSystem())
        .Add(new FoodInitSystem())
        .Add(new ScoreTableInitSystem())
        .Add(new GameStateInitSystem())
        .Add(new PlayerInputSystem())
        .Add(new GhostSystem())
        .Add(new UpdateDirectionSystem())
        .Add(new MoveSystem())
        .Add(new ItemSystem())
        .Add(new FoodSystem())
        .Add(new EnergizerSystem())
        .Add(new GhostFearStateSystem())
        .Add(new DeathSystem())
        .Add(new PortalSystem())
        .Add(new TeleportSystem())
        .Add(new WorldSystem())
        .Add(new ScoreTableSystem())
        .Add(new GameStateSystem())
        .Initialize();
    }
Exemple #12
0
        public override EcsEntity CreateEntity(EcsWorld world)
        {
            var entity = world.NewEntity();

            entity.Get <IsEnemyComponent>();

            entity.Get <MoveComponent>() = new MoveComponent()
            {
                Data = moveSettings
            };
            entity.Get <MoveComponent>().StopSqrDistance     = math.pow(entity.Get <MoveComponent>().Data.StopDistance, 2);
            entity.Get <MoveComponent>().NodeIndex           = -1;
            entity.Get <MoveComponent>().Destination         = Vector3.zero;
            entity.Get <MoveComponent>().LookInMoveDirection = true;

            entity.Get <HealthBaseComponent>()                    = healthBaseComponent;
            entity.Get <HealthCurrentComponent>().Value           = healthBaseComponent.Value;
            entity.Get <ContainerDamageComponent>().DamageRequest = new MakeDamageRequest()
            {
                Damage = damage
            };

            entity.Get <GoldComponent>().Value = (healthBaseComponent.Value / 20) + damage * 5;

            return(entity);
        }
    void OnEnable()
    {
        _world = new EcsWorld();
#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
#endif

        var sharedData = EcsFilterSingle <SharedGameState> .Create(_world);

        _systems = new EcsSystems(_world)
                   .Add(new GameSystems())
                   .Add(new TanksControlSystem())
                   .Add(new BulletControlSystem())
                   .Add(new DataSystem(this))
                   .Add(new MainCameraSystem());/*
                                                 * .Add(new NpcMovementSystem())
                                                 * .Add(new PlayerMovementSystem())
                                                 * .Add(new DamageSystem())
                                                 * .Add(new SquadSystem())
                                                 * .Add(new SelectionSystem());*/
        _systems.Initialize();
#if UNITY_EDITOR
        Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
#endif
    }
        protected override void ExecuteState(WoundedPedComponent woundedPed, int pedEntity)
        {
            base.ExecuteState(woundedPed, pedEntity);

            ChangeWalkingAnimation(pedEntity, woundedPed.IsPlayer
                ? Config.Data.PlayerConfig.IntensePainAnim
                : Config.Data.NpcConfig.IntensePainAnim);

            if (woundedPed.Crits.HasFlag(CritTypes.ARMS_DAMAGED))
            {
                return;
            }
            var pain        = EcsWorld.GetComponent <PainComponent>(pedEntity);
            var backPercent = 1f - pain.CurrentPain / woundedPed.MaximalPain;

            if (woundedPed.IsPlayer)
            {
                EcsWorld.CreateEntityWith <AddCameraShakeEvent>().Length     = CameraShakeLength.PERMANENT;
                EcsWorld.CreateEntityWith <ChangeSpecialAbilityEvent>().Lock = true;
            }
            else
            {
                woundedPed.ThisPed.Accuracy = (int)(backPercent * woundedPed.DefaultAccuracy);
            }
        }
Exemple #15
0
        public void ArchetypeRemoveHolesTest()
        {
            EcsWorld      world     = new EcsWorld();
            IEcsArchetype archetype = world.GetArchetype <ComponentA, ComponentB>();

            IEcsEntity entity0 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity1 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity2 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity3 = world.CreateEntity(new ComponentA(), new ComponentB());

            entity1.RemoveComponent <ComponentA>();
            entity2.RemoveComponent <ComponentA>();
            Assert.AreEqual(2, archetype.EntitiesCount);
            Assert.AreEqual(entity0, archetype[0]);
            Assert.AreEqual(entity3, archetype[1]);

            entity0.RemoveComponent <ComponentA>();
            Assert.AreEqual(1, archetype.EntitiesCount);
            Assert.AreEqual(entity3, archetype[0]);


            entity1.AddComponent(new ComponentA());
            entity2.AddComponent(new ComponentA());
            Assert.AreEqual(3, archetype.EntitiesCount);
            Assert.AreEqual(entity3, archetype[0]);
            Assert.AreEqual(entity1, archetype[1]);
            Assert.AreEqual(entity2, archetype[2]);
        }
    protected override void CreateEntity()
    {
        EcsWorld ecsWorld = Service <EcsWorld> .Get();

        entity = ecsWorld.NewEntity();

        ref AllLimits allLimitsComponent = ref entity.Get <AllLimits>();
Exemple #17
0
 void Init()
 {
     if (_world == null)
     {
         _world = World.Value;
     }
 }
Exemple #18
0
 public void Destroy()
 {
     _systems?.Destroy();
     _systems = null;
     _world?.Destroy();
     _world = null;
 }
Exemple #19
0
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement ragdoll = partRoot.Element("EnableRagdoll");

            if (ragdoll != null)
            {
                var component = EcsWorld.AddComponent <EnableRagdollComponent>(partEntity);
                component.LengthInMs        = ragdoll.GetInt("LengthInMs");
                component.Type              = ragdoll.GetInt("Type");
                component.Permanent         = ragdoll.GetBool("Permanent");
                component.DisableOnlyOnHeal = ragdoll.GetBool("DisableOnlyOnHeal");

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} have got {component}");
#endif
            }

            XElement disable = partRoot.Element("DisablePermanentRagdoll");
            if (disable != null)
            {
                EcsWorld.AddComponent <DisablePermanentRagdollComponent>(partEntity);

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} will disable permanent ragdoll");
#endif
            }
        }
 void IEcsWorldDebugListener.OnWorldDestroyed(EcsWorld world)
 {
     // for immediate unregistering this MonoBehaviour from ECS.
     OnDestroy();
     // for delayed destroying GameObject.
     Destroy(gameObject);
 }
Exemple #21
0
        public SceneFeature(EcsWorld world, string name = null, bool isEnable = true) : base(world, name, isEnable)
        {
            Add(new LoadScenesSystem());
            Add(new LoadingScenesProgressSystem());

            Add(new UnloadScenesByNamesSystem());
            Add(new UnloadAllScenesSystem());
            Add(new UnloadNonNewScenesSystem());
            Add(new UnloadSceneSystem());

            OneFrame <SceneChangedStateComponent>();

            Add(new ChangeSceneStateByNameSystem());
            Add(new ActivateSceneSystem());
            Add(new DeactivateSceneSystem());

            OneFrame <ActivateSceneComponent>();
            OneFrame <DeactivateSceneComponent>();
            OneFrame <SceneLoadedComponent>();

            OneFrame <LoadScenesEvent>();
            OneFrame <ActivateSceneByNameEvent>();
            OneFrame <DeactivateSceneByNameEvent>();
            OneFrame <UnloadNonNewScenesEvent>();
            OneFrame <UnloadAllScenesEvent>();
            OneFrame <UnloadScenesByNamesEvent>();
        }
Exemple #22
0
        private void InitializeECS()
        {
            // Initialize ECS
            _world = new EcsWorld();

            _systems = new EcsSystems(_world);

            _renderingSystems = new EcsSystems(_world, "Rendering Systems");
            _renderingSystems.Add(new SpriteRenderingSystem(graphics, GraphicsDevice));


            _gameplaySystems = new EcsSystems(_world, "Gameplay Systems");
            _gameplaySystems.Add(_timingSystem = new TimingSystem());
            _gameplaySystems.Add(new StateSystem());
            _gameplaySystems.Add(new InputSystem());
            _gameplaySystems.Add(new PaddleMovementSystem());
            _gameplaySystems.Add(new MovementSystem());
            _gameplaySystems.Add(new CollisionSystem());
            _gameplaySystems.Add(new BrickBreakingSystem());
            _gameplaySystems.Add(new CameraShakeSystem());
            _gameplaySystems.Add(new BallBounceSystem());

            _systems.Add(_renderingSystems);
            _systems.Add(_gameplaySystems);

            _systems.Initialize();
        }
Exemple #23
0
        IEnumerator GetOwnedData(string uri, EcsWorld ecsWorld)
        {
            using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
            {
                // Request and wait for the desired page.
                yield return webRequest.SendWebRequest();

                string[] pages = uri.Split('/');
                int page = pages.Length - 1;

                if (webRequest.isNetworkError)
                {
                    Debug.Log(pages[page] + ": Error: " + webRequest.error);
                }
                else
                {
                    JSONNode world = JSON.Parse(webRequest.downloadHandler.text);
                    OwnedData = new Dictionary<int, string>();
                    foreach (var point in world["data"])
                    {
                        OwnedData.Add(int.Parse(point.Key), point.Value);
                    }
                    ecsWorld.NewEntity().Set<UpdateOwnersTag>();
                }
            }
        }
Exemple #24
0
 void OnEnable()
 {
     _world = new EcsWorld()
              .AddSystem(new Processing1())
              .AddSystem(new Processing2());
     _world.Initialize();
 }
        private void GunshotWoundInit()
        {
            _ecsWorld = new EcsWorld();

            _mainConfig = EcsFilterSingle <MainConfig> .Create(_ecsWorld);

            LoadConfigsFromXml();

            _updateSystems = new EcsSystems(_ecsWorld);

            LastSystem = "AddNpcSystem";
            if (_mainConfig.NpcConfig.AddingPedRange > 1f)
            {
                _updateSystems
                .Add(new NpcSystem());
            }

            LastSystem = "AddPlayerSystem";
            if (_mainConfig.PlayerConfig.WoundedPlayerEnabled)
            {
                _updateSystems
                .Add(new PlayerSystem());
            }

            LastSystem = "AddAdrenalineSystem";
            if (_mainConfig.PlayerConfig.AdrenalineSlowMotion)
            {
                _updateSystems
                .Add(new AdrenalineSystem());
            }

            LastSystem = "AddOtherSystems";
            _updateSystems
            .Add(new InstantHealSystem())
            .AddHitSystems()
            .AddDamageSystems()
            .AddWoundSystems()
            .AddPainSystems()
            .Add(new HitCleanSystem())
            .Add(new HelmetRequestSystem())
            .Add(new DebugInfoSystem())
            .Add(new CheckSystem())
            .Add(new NotificationSystem())
            .Add(new ArmorSystem())
            .Add(new RagdollSystem())
            .Add(new SwitchAnimationSystem());

            LastSystem = "OnInit";
            _updateSystems.Initialize();

            Tick  += OnTick;
            KeyUp += OnKeyUp;

            Function.Call(Hash.SET_PLAYER_WEAPON_DAMAGE_MODIFIER, Game.Player, 0.00001f);
            Function.Call(Hash.SET_PLAYER_HEALTH_RECHARGE_MULTIPLIER, Game.Player, 0f);

            LastSystem      = "Stopwatch";
            _debugStopwatch = new Stopwatch();
        }
Exemple #26
0
        protected override void PrepareComponentToNetwork(PrepareComponentToSendEvent <TComponent> prepareComponent)
        {
            TComponent componentToSend     = EcsWorld.GetComponent <TComponent>(prepareComponent.LocalEntityUid);
            bool       componentWasRemoved = prepareComponent.ComponentFlags.HasFlag(EcsNetComponentFlags.WAS_REMOVED);

#if DEBUG
            if (!componentWasRemoved && componentToSend == null)
            {
                throw new Exception(string.Format("{0} doesn't exist on this entity", typeof(TComponent).Name));
            }
#endif
            SendNetworkComponentEvent sendEvent;
            EcsWorld.CreateEntityWith(out sendEvent);
            sendEvent.ComponentTypeUid = ComponentUid;
            sendEvent.ComponentFlags   = prepareComponent.ComponentFlags;

            int  localEntity      = prepareComponent.LocalEntityUid;
            bool localEntityExist = NetworkConfig.Data.LocalEntitiesToNetwork.ContainsKey(localEntity);
            long networkEntity;

            if (componentWasRemoved)
            {
#if DEBUG
                if (!localEntityExist)
                {
                    throw new Exception(string.Format("You've tried to send removed {0} for not network entity", typeof(TComponent).Name));
                }
#endif

                networkEntity = NetworkConfig
                                .Data
                                .LocalEntitiesToNetwork[localEntity];
                sendEvent.NetworkEntityUid = networkEntity;

                if (EcsWorld.IsEntityExists(localEntity))
                {
                    return;
                }
                RemoveNetworkToLocalEntity(networkEntity, localEntity);
            }
            else
            {
                sendEvent.ComponentBytes = NetworkConfig.Data.Serializator.GetBytesFromComponent(componentToSend);

                if (localEntityExist)
                {
                    networkEntity = NetworkConfig
                                    .Data
                                    .LocalEntitiesToNetwork[localEntity];
                    sendEvent.NetworkEntityUid = networkEntity;
                }
                else
                {
                    networkEntity = NetworkConfig.Data.Random.NextInt64();
                    AddNetworkToLocalEntity(networkEntity, localEntity);
                    sendEvent.NetworkEntityUid = networkEntity;
                }
            }
        }
Exemple #27
0
        private void OnDisable()
        {
            _systems.Destroy();
            _systems = null;

            _ecsWorld.Destroy();
            _ecsWorld = null;
        }
Exemple #28
0
        public void Init(EcsWorld world, ref ResourceItemComponent resourceItemComponent, ref EcsEntity entity)
        {
            this.world  = world;
            this.entity = entity;
            this.resourceItemComponent = resourceItemComponent;

            initialized = true;
        }
 void OnDestroy()
 {
     if (_world != null)
     {
         _world.RemoveDebugListener(this);
         _world = null;
     }
 }
 public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
 {
     ecsEntity.Set <URotationRoot>().Transform = this._root;
     if (OnScene)
     {
         Destroy(this);
     }
 }