private void InitObject( LevelObjectView obj, ObjectTypeInfo objectTypeInfo, ObjectProtoInfo objectProtoInfo, SpawnLocation spawnLocation, LevelSettings levelSettings) { obj.transform.rotation = Quaternion.Euler(0f, spawnLocation.IsXFlipped ? 180f : 0f, 0f); var alternating = obj.GetComponent <AlternatingView>(); if (alternating != null) { int materialIndex = UnityEngine.Random.Range( 0, objectProtoInfo.AvailableMaterials.Length); alternating.Material = objectProtoInfo.AvailableMaterials[materialIndex]; } if (objectTypeInfo.Type == playerObjectType) { List <int> skillIds = playerStateStorage.Get().SkillIds; for (int i = 0; i < skillIds.Count; ++i) { Skill skill = skillStorage.Get(skillIds[i]); BaseSkill baseSkill = skillStorage.GetBase(skill.BaseId); ISkillHelper skillHelper = skillHelperStorage.Get(baseSkill.Type); skillHelper.AddSkill(skill, obj.gameObject); } } }
private void NewObject() { // DebugUtils.Log("LevelAreaGeneratorView.NewObject()"); Profiler.BeginSample("LevelAreaGeneratorView.NewObject()"); LevelObjectType objectType = spawnsInfos[spawnsInfosIndex].ObjectType; List <SpawnLocation> spawnLocations = envTypeInfo.SpawnMap.GetLocations(objectType); ObjectTypeInfo objectTypeInfo = objectTypeInfoStorage.Get(objectType); Vector3 spawnPoint; SpawnLocation spawnLocation; bool isFreeSpaceExists = true; do { spawnLocation = spawnLocations[ UnityEngine.Random.Range(0, spawnLocations.Count)]; spawnPoint = GetRandomSpawnPoint( spawnLocation.Bounds, objectTypeInfo); if (spawnTriesCount == 0) { isFreeSpaceExists = false; break; } --spawnTriesCount; } while (IsSpawnPointReserved(spawnPoint)); if (isFreeSpaceExists) { int objectProtoIndex = UnityEngine.Random.Range( 0, objectTypeInfo.ProtoInfos.Length); ObjectProtoInfo objectProtoInfo = objectTypeInfo.ProtoInfos[objectProtoIndex]; LevelObjectView obj = level.NewObject( objectProtoInfo.View, spawnPoint, area.Index); InitObject(obj, objectTypeInfo, objectProtoInfo, spawnLocation, levelSettings); ReserveSpawnPoint(spawnPoint); } --objectsCountToSpawn; Profiler.EndSample(); if (objectsCountToSpawn <= 0 || spawnTriesCount <= 0) { ++spawnsInfosIndex; if (spawnsInfosIndex >= spawnsInfos.Count) { CancelInvoke("NewObject"); if (onDone != null) { onDone(area); } return; } NextObjectType(); } }