Пример #1
0
        /**
         * @return Can be null
         */
        public ObjectLevelSettings GetObjectSettings(
            LevelObjectType objectType)
        {
            ObjectLevelSettings result = null;

            objectSettings.TryGetValue((int)objectType, out result);
            return(result);
        }
Пример #2
0
        private List <SpawnsInfo> GetSpawnsInfos(
            LevelSettings levelSettings,
            EnvTypeInfo envTypeInfo,
            bool spawnPlayer,
            PlayerView player = null)
        {
            Profiler.BeginSample("LevelGenerator.GetSpawnsInfos()");
            LevelObjectType[] objectTypes =
                envTypeInfo.SpawnMap.ObjectTypes;
            Array.Sort(objectTypes, objectTypeComparer);
            spawnsInfosBuffer.Clear();
            int objectTypesCount = objectTypes.Length;

            for (int i = 0; i < objectTypesCount; ++i)
            {
                LevelObjectType objectType     = objectTypes[i];
                ObjectTypeInfo  objectTypeInfo =
                    objectTypeInfoStorage.Get(objectType);
                ObjectLevelSettings objectLevelSettings =
                    levelSettings.GetObjectSettings(objectType);
                int spawnsCount = 0;

                if (objectType == playerObjectType)
                {
                    spawnsCount = spawnPlayer ? 1 : 0;
                    spawnPlayer = false;
                }
                else if (objectLevelSettings != null &&
                         UnityEngine.Random.value <=
                         objectLevelSettings.SpawnChance)
                {
                    LevelObjectView objectProto = objectTypeInfo.ProtoInfo.View;
                    spawnsCount = UnityEngine.Random.Range(
                        objectLevelSettings.MinSpawnsPerArea,
                        objectLevelSettings.MaxSpawnsPerArea + 1);
                    var bonus = objectProto.GetComponent <BonusView>();

                    if (bonus != null)
                    {
                        if (player == null ||
                            !bonusSpawnResolver.IsTimeToSpawn(
                                bonus, player))
                        {
                            spawnsCount = 0;
                        }
                        else
                        {
                            bonusSpawnResolver.ActiveBonusObjects +=
                                spawnsCount;
                        }
                    }
                }

                spawnsInfosBuffer.Add(new SpawnsInfo(objectType, spawnsCount));
            }

            return(spawnsInfosBuffer);
        }