public void onLevelSelected(HUD invokder, LevelDescription data) { selectedLevel = data; SquareSpriteRenderer ssr = new SquareSpriteRenderer(Game.Content.Load <Texture2D>(@"Terrain\" + data.TerrainName), Color.Blue); ssr.size = new Vector2(1, 0); if (mapPreview.childRenderers.Count == 0) { mapPreview.AddChildRenderer(ssr); } else { mapPreview.childRenderers[0] = ssr; ssr.parentRenderer = mapPreview; } }
public override IEnumerator Process() { if (config.LevelGraph == null) { throw new ArgumentException("LevelGraph must not be null."); } if (config.LevelGraph.Rooms.Count == 0) { throw new ArgumentException("LevelGraph must contain at least one room."); } var levelDescription = new LevelDescription(); // Setup individual rooms foreach (var room in config.LevelGraph.Rooms) { levelDescription.AddRoom(room, GetRoomTemplates(room)); } var typeOfRooms = config.LevelGraph.Rooms.First().GetType(); // Add passages foreach (var connection in config.LevelGraph.Connections) { if (config.UseCorridors) { var corridorRoom = (RoomBase)ScriptableObject.CreateInstance(typeOfRooms); if (corridorRoom is Room basicRoom) { basicRoom.Name = "Corridor"; } levelDescription.AddCorridorConnection(connection, corridorRoom, GetRoomTemplates(config.LevelGraph.CorridorRoomTemplateSets, config.LevelGraph.CorridorIndividualRoomTemplates)); } else { levelDescription.AddConnection(connection); } } Payload.LevelDescription = levelDescription; yield return(null); }
// // Heat seeking // public ProjectileInstance(Projectile projectile, Vector3 sourcePos, EnemyInstance enemy, float waveTimeFired, LevelDescription desc) { LevelDesc = desc; ProjectileType = projectile; LastUpdateTime = waveTimeFired; FireTime = waveTimeFired; #if LEVEL_EDITOR Position = new Vector3(sourcePos.X, PROJECTILE_HEIGHT, sourcePos.X); #else Position = new Vector3(sourcePos.x, PROJECTILE_HEIGHT, sourcePos.z); #endif Enemy = enemy; IsComplete = false; go = GameObjectFactory.InstantiateObject(ProjectileType.Asset); GameObjectFactory.SetMapPos(go, Position); heatSeeking = true; }
private IEnumerator NextLevel() { // Release current level. Level level = this.currentLevel; if (level != null) { this.currentLevel = null; yield return(this.StartCoroutine(level.Unload())); } // Get next level description. this.currentLevelIndex++; Debug.Assert(this.currentLevelIndex >= 0); if (this.levelDatabase == null) { Debug.LogWarning("No levels in database"); yield break; } if (this.currentLevelIndex >= this.levelDatabase.Count) { Debug.Log("No remaining level."); yield break; } LevelDescription levelDescription = this.levelDatabase[this.currentLevelIndex]; // Load next level. Debug.Log("Start level " + levelDescription.Name); level = new Level(); yield return(this.StartCoroutine(level.Load(levelDescription))); if (this.LevelChanged != null) { this.LevelChanged.Invoke(this, new LevelChangedEventArgs(level)); } level.Start(); this.currentLevel = level; }
public void AddLevels(LevelsContainer levelsContainer) { for (int i = 0; i < levelsContainer.Levels.Count; i++) { if (i == 0 || (i) % (LevelsOnPage) == 0) { RectTransform lvlPage = Instantiate(PagePrefab); pages.Add(lvlPage); lvlPage.transform.SetParent(PageParent); lvlPage.transform.localScale = Vector3.one; lvlPage.offsetMin = Vector2.zero; lvlPage.offsetMax = Vector2.zero; //CalculateInventoryPanelParameters(lvlPage, LevelsOnPage); } Button btn = Instantiate(LevelButtonPrefab); btn.transform.SetParent(pages[pages.Count - 1]); btn.transform.localScale = Vector3.one; btn.GetComponentInChildren <TextMeshProUGUI>().text = levelsContainer.Levels[i].Name; LevelDescription lvl = levelsContainer.Levels[i]; RecordLevelSave recordLevelSave = FindObjectOfType <RecordLevelSave>(); if (recordLevelSave != null) { int record = recordLevelSave.GetRecordByLevelID(lvl); if (record != 0) { SetPassedLevel(btn.transform, record.ToString()); } } btn.onClick.AddListener(() => { GameManager.Instance.LoadLevel(lvl, levelsContainer); }); } ScrollSnapRect scrollSnapRect = GetComponentInChildren <ScrollSnapRect>(); if (scrollSnapRect != null) { scrollSnapRect.OnPageSwitched += GetCurrentPage; } GetCurrentPage(currentPage); }
public int GetRecordByLevelID(LevelDescription levelDescription) { if (recordsSaves == null) { return(0); } RecordData recordLevelSave = recordsSaves.Find(x => x.LevelID == levelDescription.ID); if (recordLevelSave != null) { return(recordLevelSave.MovesRecord); } else { return(0); } }
void LoadFromXML(TextAsset textAsset) { LevelDescription levelDescription = XmlHelpers.DeserializeFromXML <LevelDescription>(textAsset); gameModeWithHealth = levelDescription.gameModeWithHealth; enemyCooldown = levelDescription.enemyCooldown; collectibleApparitionCooldown = levelDescription.collectibleApparitionCooldown; weaponCollectibleApparitionRatio = levelDescription.weaponCollectibleApparitionRatio; energyCollectibleApparitionRatio = levelDescription.energyCollectibleApparitionRatio; healthCollectibleApparitionRatio = levelDescription.energyCollectibleApparitionRatio; numberOfEnemyInLevel = levelDescription.numberOfEnemyInLevel; timeBetweenThisAndPreviousEnemy = levelDescription.timeBetweenThisAndPreviousEnemy; enemiesVerticalSpawnPositions = levelDescription.enemiesVerticalSpawnPositions; }
//团队成员skill查看 public ActionResult GetSkillById(int uid) { var user = UserInfoService.LoadEntities(u => u.Id == uid).FirstOrDefault(); if (user == null) { throw new Exception("操作非法!"); } var types = TechTypeService.LoadEntities(t => t.Id != 0); List <SkillViewModel> skills = new List <SkillViewModel>(); //必须重新去取 不然用的是session里的缓存数据。不能及时显示更新情况 var currentUser = UserInfoService.LoadEntities(c => c.Id == user.Id).FirstOrDefault(); foreach (var type in types) { SkillViewModel skill = new SkillViewModel(); skill.Techs = new List <TechViewModel>(); skill.TechTypeName = type.TypeName; foreach (var tech in type.Tech) { var level = (from r in currentUser.R_UserInfo_Tech where r.TechId == tech.Id select r.LevelDescription).FirstOrDefault(); if (level == null) { level = new LevelDescription() { Level = 0, Description = "Not Rate" }; } TechViewModel techview = new TechViewModel() { Tech = tech, Level = level }; skill.Techs.Add(techview); } skills.Add(skill); } ViewData.Model = skills; return(View()); }
public IEnumerator Load(LevelDescription levelDescription) { this.description = levelDescription; // Load level scene. AsyncOperation loadSceneAsync = SceneManager.LoadSceneAsync(this.description.Scene, LoadSceneMode.Additive); while (!loadSceneAsync.isDone) { // Wait for the level to be loaded. yield return(null); } this.isEnemySpawned = new EnemyState[this.description.Enemies != null ? this.description.Enemies.Length : 0]; for (int index = 0; index < this.isEnemySpawned.Length; index++) { this.isEnemySpawned[index] = EnemyState.NotSpawned; } }
public Result Run(LevelDescription levelDescription) { var result = new Result(); var mapping = levelDescription.GetPrefabToRoomTemplateMapping(); var problematicRoomTemplates = new Dictionary <GameObject, int>(); foreach (var pair in mapping) { var roomTemplate = pair.Value; var gameObject = pair.Key; var individualResult = RoomTemplateDiagnostics.CheckWrongManualDoors(roomTemplate.Outline, roomTemplate.Doors, out var differentLengthsCount); if (individualResult.HasErrors) { problematicRoomTemplates.Add(gameObject, differentLengthsCount); } } if (problematicRoomTemplates.Count != 0) { result.IsPotentialProblem = true; result.ProblematicRoomTemplates = problematicRoomTemplates; var sb = new StringBuilder(); sb.AppendLine($"There are room templates with a high probability of having an incorrect setup of manual doors."); sb.AppendLine($"The problematic room templates are:"); foreach (var pair in problematicRoomTemplates) { sb.AppendLine($"- \"{pair.Key.name}\" with {pair.Value} different lengths of doors"); } sb.AppendLine($"Please go through these room templates and check that their setup is correct."); result.Summary = sb.ToString(); } else { result.IsPotentialProblem = false; } return(result); }
private void StarNextLevel() { if (currentLevel != null) { currentLevel.Unload(); } this.currentLevelIndex++; if (this.currentLevelIndex >= this.levelDescriptions.Count) { OnGameOver(); return; } currentLevelDescription = this.levelDescriptions[currentLevelIndex]; currentLevel = new Level(); currentLevel.Load(currentLevelDescription); }
public static List <LevelDescription> LoadLevels() { List <LevelDescription> levels = new List <LevelDescription>(); Debug.Log(Application.dataPath); TextAsset txtAss = Resources.Load <TextAsset>("levels") as TextAsset; string[] arrayOfStrings = txtAss.ToString().Split('\n'); foreach (var level in arrayOfStrings) { Debug.Log(level); TextAsset ass = Resources.Load <TextAsset>("Levels/" + level.Trim()) as TextAsset; string levelAsText = ass.ToString(); LevelDescription _gridDescription = JsonUtility.FromJson <LevelDescription>(levelAsText); levels.Add(_gridDescription); } return(levels); }
private void LoadLevel(string levelName) { LevelDesc = LevelManager.ReadLevel(levelName); /* * * Use this code to prepopulate Enemies/Turrets/Projectiles * * * * LevelDesc = LevelLoader.GetTestLevel(); * * LevelManager.WriteLevel("1-1", LevelDesc); * * LevelManager.WriteTurrets(LevelDesc.AllowedTurrets); * * List<EnemyDescription> enemies = new List<EnemyDescription>(); * enemies.Add(LevelDesc.Waves[0].EnemyType); * enemies.Add(LevelDesc.Waves[1].EnemyType); * LevelManager.WriteEnemies(enemies); * * List<Projectile> projectiles = new List<Projectile>(); * projectiles.Add(LevelDesc.AllowedTurrets[0].ProjectileType); * projectiles.Add(LevelDesc.AllowedTurrets[1].ProjectileType); * projectiles.Add(LevelDesc.AllowedTurrets[2].ProjectileType); * LevelManager.WriteProjectiles(projectiles); * * Application.Quit(); */ switch (CurrentMode) { case EditorMode.Level: ((LevelEditLayout)EditorWidget).SetLevel(LevelDesc); break; case EditorMode.Analysis: ((LevelAnalysisLayout)EditorWidget).SetLevel(LevelDesc); break; } }
void CleanupLevel() { if (null != Projectiles) { Projectiles.DestroyAll(); Projectiles = null; } if (null != Turrets) { Turrets.DestroyAll(); Turrets = null; } if (null != Waves) { Waves.DestroyAll(); Waves = null; } GameObjectFactory.Cleanup(); LevelDesc = null; }
/// <summary> /// Write a given scene to xml. The filename is the same as the scene. /// </summary> /// <param name="scene">the scene to write</param> /// <param name="outputPath">the folder to write the file</param> public static void WriteLevel(Scene scene, string outputPath) { //get scene objects List <GameObject> rootObjects = new List <GameObject>(); scene.GetRootGameObjects(rootObjects); //create stream writer at directory StreamWriter writer = new StreamWriter(outputPath + "/" + scene.name + ".xml"); LevelDescription ld = new LevelDescription(); uint count = 0; EditorObjectBase.ResetGlobalID(); //assign IDs foreach (GameObject ob in rootObjects) { var subs = ob.GetComponentsInChildren <EditorObjectBase>(); foreach (var sub in subs) { sub.AssignId(); } } // iterate root objects foreach (GameObject ob in rootObjects) { //only process EditorObjects EditorObjectBase editorObject = ob.GetComponent <EditorObjectBase>(); if (editorObject != null) { ++count; ld.Add(editorObject.GetReadySerialize()); } } XmlSerializer xml = new XmlSerializer(ld.GetType()); xml.Serialize(writer.BaseStream, ld); writer.Close(); Debug.Log("Wrote " + count + " objects to \"" + outputPath + "/" + scene.name + ".xml\""); }
public void Awake() { foreach (Transform childTransform in root) { Destroy(childTransform.gameObject); } foreach (var levelDescription in Levels) { var go = Instantiate(Prefab); go.Level = levelDescription; go.transform.SetParent(root, false); go.Button.OnClickAsObservable().Subscribe ( x => { ChosenLevel = go.Level; Application.LoadLevel("Game"); }); } }
public override void Run(GeneratedLevel level, LevelDescription levelDescription) { foreach (var roomInstance in level.GetRoomInstances()) { var roomTemplateInstance = roomInstance.RoomTemplateInstance; // Find floor tilemap layer var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplateInstance); var floor = tilemaps.Single(x => x.name == "Floor").gameObject; // Add floor collider AddFloorCollider(floor); // Add the room manager component var roomManager = roomTemplateInstance.AddComponent <CurrentRoomDetectionRoomManager>(); roomManager.RoomInstance = roomInstance; // Add current room detection handler floor.AddComponent <CurrentRoomDetectionTriggerHandler>(); } }
public void FallTillZero() { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); var levelDescription = new LevelDescription() { Width = 1, Height = 3, SlotChipDescriptions = new List <SlotChipDescription>() { new SlotChipDescription() { Position = new int2(0, 2), Color = ChipColor.Red, }, } }; levelDescription.DefaultChipDescription = new SlotChipDescription() { ChipType = ChipType.None }; var slotCache = new Dictionary <int2, Entity>(); var sceneConfiguration = CreateTestSceneConfiguration(); var configuration = CreateTestConfiguration(); var createSlots = new CreateSlotsStep(slotCache, sceneConfiguration); createSlots.Apply(levelDescription, entityManager); var createChips = new CreateChipsStep(configuration); createChips.Apply(levelDescription, entityManager); var nextY = FallSystem.GetNextEmptyRow(entityManager, slotCache, new int2(0, 2)); Assert.AreEqual(0, nextY); }
private static LevelDescription InitLevelDescription(LevelType type, int id) { LevelDescription desc = new LevelDescription(); switch (type) { case LevelType.Interior: desc.AuthorizedEnnemy = new EnnemyType[] { EnnemyType.OrganicsA, EnnemyType.RobotB }; desc.Id = id; desc.LevelTimeMax = 60 * 5; desc.Name = "First Escape"; break; case LevelType.Space: desc.AuthorizedEnnemy = new EnnemyType[] { EnnemyType.AncienA, EnnemyType.RobotA }; desc.Id = id; desc.LevelTimeMax = 60 * 5; desc.Name = "First Escape"; break; } return(desc); }
// // Directional // public ProjectileInstance(Projectile projectile, Vector3 sourcePos, Vector3 direction, float distance, float waveTimeFired, LevelDescription desc) { LevelDesc = desc; ProjectileType = projectile; DistanceToTravel = distance; LastUpdateTime = waveTimeFired; FireTime = waveTimeFired; #if LEVEL_EDITOR Position = new Vector3(sourcePos.X, PROJECTILE_HEIGHT, sourcePos.X); Vector3 normalized = Vector3.Normalize(direction); Direction = new Ray(sourcePos, normalized); #else Position = sourcePos; Direction = new Ray(sourcePos, direction.normalized); #endif IsComplete = false; go = GameObjectFactory.InstantiateObject(ProjectileType.Asset); GameObjectFactory.SetMapPos(go, Position); #if LEVEL_EDITOR == false go.transform.forward = direction; #endif heatSeeking = false; }
public void SaveMapButtonClick(HUD invoker) { if (namingTextbox.textRenderer.text == "") { return; } LevelDescription ld = new LevelDescription(); ld.PlayerStartPoint = playerStartPointMaker.transformation.Position; List <GameObject> enemySpawnPoints = FindObjectsByTag("EnemySpawnPoint"); foreach (GameObject enemySpawnPoint in enemySpawnPoints) { ld.SpawnPoints.Add(enemySpawnPoint.transformation.Position); } ld.MapCellSize = 10; ld.MapDeltaHeight = 200; ld.TerrainName = terrainName; ld.SaveToXML(Game.Content.RootDirectory + @"\Level\" + namingTextbox.textRenderer.text + ".xml"); gameManager.isPaused = false; gameManager.LoadTitleScreen(); }
private void PopulateTreeWithWaves(LevelDescription desc) { WavesModel.Clear(); WaveSolution currentSolution = GenerateWaveSolution(); Dictionary <int, WaveSolution> waveSolves = new Dictionary <int, WaveSolution>(); for (int i = 0; i < Solution.WaveSolutions.Count; i++) { waveSolves.Add(Solution.WaveSolutions[i].WaveIndex, Solution.WaveSolutions[i]); } for (int i = 0; i < desc.Waves.Count; i++) { string saveString = "Save"; string loadString = "n/a"; WaveSolution solution = null; if (waveSolves.TryGetValue(i, out solution)) { if (solution.Same(currentSolution)) { saveString = "n/a"; loadString = "n/a"; } else { saveString = "Save"; loadString = "Load"; } } string simDamageKills = WaveStatList[i].FullSimulation.DamagePerEnemy.ToString() + "/" + WaveStatList[i].FullSimulation.EnemiesKilled; string coinString = WaveStatList[i].CoinNeeded.ToString() + "/" + WaveStatList[i].CoinAvail.ToString(); string issues = EnumerateSolutionIssues(i, currentSolution); object[] values = { i, desc.Waves[i].Enemy, desc.Waves[i].Count, desc.Waves[i].DifficultyMultiplier, WaveStatList[i].MaxDmgDealtSingleEnemy, WaveStatList[i].MaxHPPSProducted, WaveStatList[i].MaxDPSOverall, simDamageKills, coinString, saveString, loadString, issues }; WavesModel.AppendValues(values); } }
public void Apply(LevelDescription levelDescription, EntityManager entityManager) { var entities = entityManager.GetAllEntities(); for (int i = 0; i < entities.Length; i++) { if (entityManager.HasComponent <Slot>(entities[i])) { var slotPosition = entityManager.GetComponentData <SlotPosition>(entities[i]); var x = slotPosition.Value.x; var y = slotPosition.Value.y; var position = entityManager.GetComponentData <Position>(entities[i]).Value; var slot = entities[i]; entityManager.AddComponentData(slot, new PossibleNeighbours() { Value = FieldUtils.GetNeighbour(x, y, levelDescription.Width, levelDescription.Height) }); var chipDescription = levelDescription.GetChipDescription(slotPosition.Value); if (chipDescription.ChipType == ChipType.None) { continue; } var colorsCount = Mathf.Min(_chipsPrefabs.Length, levelDescription.ColorCount); var color = (chipDescription.Color == ChipColor.Random) ? (ChipColor)Random.Range(0, colorsCount) : chipDescription.Color; var chip = CreateChip(entityManager, slot, position, color); entityManager.AddComponentData(slot, new ChipReference() { Value = chip }); } } entities.Dispose(); }
public Result Run(LevelDescription levelDescription) { var graph = levelDescription.GetGraph(); var vertices = graph.VerticesCount; var result = new Result(); result.NumberOfRooms = vertices; if (vertices > 20) { result.IsPotentialProblem = true; var sb = new StringBuilder(); sb.AppendLine($"The level graph has quite a lot of rooms ({vertices})."); sb.AppendLine($"The higher the number of rooms, the harder it is for the generator to produce a level."); sb.AppendLine($"If you want to have a lot of rooms in the level, it is best to limit the number of cycles."); result.Summary = sb.ToString(); } else { result.IsPotentialProblem = false; } return(result); }
public void CreateChips() { var entityManager = World.Active.GetOrCreateManager <EntityManager>(); var levelDescription = new LevelDescription() { Width = 5, Height = 5 }; var sceneConfiguration = CreateTestSceneConfiguration(); var configuration = CreateTestConfiguration(); var createSlots = new CreateSlotsStep(new Dictionary <int2, Entity>(), sceneConfiguration); createSlots.Apply(levelDescription, entityManager); var createChips = new CreateChipsStep(configuration); createChips.Apply(levelDescription, entityManager); //check var entities = entityManager.GetAllEntities(); var countChips = 0; for (int i = 0; i < entities.Length; i++) { if (entityManager.HasComponent <Chip>(entities[i])) { countChips++; } } entities.Dispose(); Assert.AreEqual(25, countChips); }
public override void Run(GeneratedLevel level, LevelDescription levelDescription) { List <RoomInstance> roomInstances = new List <RoomInstance>(); tiles = new TileBase[256 * 256]; foreach (RoomInstance room in level.GetRoomInstances()) { roomInstances.Add(room); AddLevelMap(room, tiles, wallTile, backgroundTile); if (!room.RoomTemplateInstance.transform.FindChildWithLayer("Player")) { AddDoor(room, door); } } Tilemap tilemap = level.GetSharedTilemaps()[2]; tilemap.CompressBounds(); tilemap.RefreshAllTiles(); GameManager manager = FindObjectOfType <GameManager>(); manager.InitTilemap(roomInstances, tilemap, ruleTile); }
public void Apply(LevelDescription levelDescription, EntityManager entityManager) { entityManager.CreateEntity(typeof(Score)); }
public static GeneratedLevel TransformLayout(IMapLayout <Room> layout, LevelDescription levelDescription, GameObject rootGameObject) { return(null); }
public override void OnInspectorGUI() { LevelDescription description = this.target as LevelDescription; description.LevelEnvironment = EditorGUILayout.ObjectField("Level Type", description.LevelEnvironment, typeof(LevelEnvironmentEnum), false) as LevelEnvironmentEnum; GUILayout.Space(4); if (CustomEditorUtils.GetButton("Add Description", Color.green)) { description.EncounterModels.Add(new EncounterModel()); } GUILayout.Space(4); this._scrollPos = EditorGUILayout.BeginScrollView(this._scrollPos); int indexToDelete = -1; for (int i = 0; i < description.EncounterModels.Count; i++) { if (description.EncounterModels[i] != null) { GUILayout.BeginVertical(GUI.skin.box); description.EncounterModels[i].Encounter = EditorGUILayout.ObjectField("Encounter", description.EncounterModels[i].Encounter, typeof(EncounterAsset), false) as EncounterAsset; description.EncounterModels[i].MinCount = EditorGUILayout.IntField("MinCount", description.EncounterModels[i] .MinCount); description.EncounterModels[i].MaxCount = EditorGUILayout.IntField("MaxCount", description.EncounterModels[i] .MaxCount); if (CustomEditorUtils.GetButton("Delete Description", Color.red)) { indexToDelete = i; } EditorGUILayout.EndVertical(); } GUILayout.Space(4); } if (indexToDelete > -1) { bool result = EditorUtility.DisplayDialog("Delete component", "Delete component: {0}".F( description.EncounterModels[ indexToDelete ].GetType ()), "OK", "Cancel"); if (result) { description.EncounterModels.Remove(description.EncounterModels[indexToDelete]); } } EditorGUILayout.EndScrollView(); EditorUtility.SetDirty(this.target); }
public override void Run(GeneratedLevel level, LevelDescription levelDescription) { HandleEnemies(level); }
public abstract void Run(GeneratedLevel level, LevelDescription levelDescription);