void ReuseEnemy(int fromGroupId, ref JSonEnemySpawnData spawnData)
        {
            //take the first entity (with all its entity views and implementors) from the group
            var egid = _entityFunctions.SwapFirstEntityGroup <EnemyEntityDescriptor>(fromGroupId, (int)ECSGroups.ActiveEnemies);

            //reset some components after the recycle
            entitiesDB.ExecuteOnEntity(egid,
                                       (ref HealthEntityStruct healthStruct) => {
                healthStruct.currentHealth = 100;
                healthStruct.dead          = false;
            });
            entitiesDB.ExecuteOnEntity(egid, ref spawnData,
                                       (ref EnemyEntityViewStruct entityView,
                                        ref JSonEnemySpawnData spawnDataInfo) =>
            {
                int spawnPointIndex = UnityEngine
                                      .Random.Range(0, spawnDataInfo.enemySpawnData.spawnPoints.Length);

                var spawnInfo = spawnDataInfo.enemySpawnData.spawnPoints[spawnPointIndex];

                entityView.transformComponent.position = spawnInfo.position;
                entityView.transformComponent.rotation = spawnInfo.rotation;

                entityView.animationComponent.reset();
                entityView.movementComponent.navMeshEnabled      = true;
                entityView.movementComponent.setCapsuleAsTrigger = false;
                entityView.layerComponent.layer = GAME_LAYERS.ENEMY_LAYER;
            });
        }
예제 #2
0
    public void SerializeData()
    {
        serializedOnce = true;
        var data = GetComponents <EnemySpawnDataSource>();

        JSonEnemySpawnData[] spawningdata = new JSonEnemySpawnData[data.Length];

        for (int i = 0; i < data.Length; i++)
        {
            spawningdata[i] = new JSonEnemySpawnData(data[i].spawnData);
        }

        var json = JsonHelper.arrayToJson(spawningdata);

        Utility.Console.Log(json);

        File.WriteAllText(Application.persistentDataPath + "/EnemySpawningData.json", json);
    }
예제 #3
0
    public void SerializeSpawnData()
    {
        serializedSpawnDataOnce = true;

        var data         = GetComponents <EnemyData>();
        var spawningdata = new JSonEnemySpawnData[data.Length];

        for (var i = 0; i < data.Length; i++)
        {
            spawningdata[i] = new JSonEnemySpawnData(data[i].spawnData);
        }

        var json = JsonHelper.arrayToJson(spawningdata);

        Console.Log(json);

        File.WriteAllText("EnemySpawningData.json", json);
    }
예제 #4
0
        /// <summary>
        ///     Reset all the component values when an Enemy is ready to be recycled.
        ///     it's important to not forget to reset all the states.
        ///     note that the only reason why we pool it the entities here is to reuse the implementors,
        ///     pure entity structs entities do not need pool and can be just recreated
        /// </summary>
        /// <param name="spawnData"></param>
        /// <returns></returns>
        void ReuseEnemy(ExclusiveGroup.ExclusiveGroupStruct fromGroupId, JSonEnemySpawnData spawnData)
        {
            var healths = entitiesDB.QueryEntities <HealthEntityStruct>(fromGroupId, out var count);

            if (count > 0)
            {
                var enemystructs = entitiesDB.QueryEntities <EnemyEntityViewStruct>(fromGroupId, out count);
                healths[0].currentHealth = 100;
                healths[0].dead          = false;

                var spawnInfo = spawnData.enemySpawnData.spawnPoint;

                enemystructs[0].transformComponent.position           = spawnInfo;
                enemystructs[0].movementComponent.navMeshEnabled      = true;
                enemystructs[0].movementComponent.setCapsuleAsTrigger = false;
                enemystructs[0].layerComponent.layer     = GAME_LAYERS.ENEMY_LAYER;
                enemystructs[0].animationComponent.reset = true;

                _entityFunctions.SwapEntityGroup <EnemyEntityDescriptor>(enemystructs[0].ID, ECSGroups.ActiveEnemies);
            }
        }
예제 #5
0
        /// <summary>
        ///     Reset all the component values when an Enemy is ready to be recycled.
        ///     it's important to not forget to reset all the states.
        ///     note that the only reason why we pool it the entities here is to reuse the implementors,
        ///     pure entity structs entities do not need pool and can be just recreated
        /// </summary>
        /// <param name="spawnData"></param>
        /// <returns></returns>
        void ReuseEnemy(ExclusiveGroupStruct fromGroupId, JSonEnemySpawnData spawnData)
        {
            Svelto.Console.LogDebug("reuse enemy " + spawnData.enemySpawnData.enemyPrefab);

            var(healths, enemyViews, count) =
                entitiesDB.QueryEntities <HealthComponent, EnemyEntityViewComponent>(fromGroupId);

            if (count > 0)
            {
                healths[0].currentHealth = 100;

                var spawnInfo = spawnData.enemySpawnData.spawnPoint;

                enemyViews[0].transformComponent.position           = spawnInfo;
                enemyViews[0].movementComponent.navMeshEnabled      = true;
                enemyViews[0].movementComponent.setCapsuleAsTrigger = false;
                enemyViews[0].layerComponent.layer     = GAME_LAYERS.ENEMY_LAYER;
                enemyViews[0].animationComponent.reset = true;

                _entityFunctions.SwapEntityGroup <EnemyEntityDescriptor>(enemyViews[0].ID, ECSGroups.EnemiesGroup);
            }
        }