private void ShowEnemyLevels(Button butt, int index, Vector3 position) { HideEnemyLevels(); int count = Definitions.Enemy((Definitions.Enemies)_selectedWaveEvent.subType).levels.Count; Add(_enemyLevels = new Layout("EnemyLevelLayout", 3, count, 0.25f, 0.1f, count, container)); _enemyLevels.SetPosition(position + (Vector3.right * _enemyLevels.width * 0.5f) + (Vector3.back * _enemyLevels.height * 0.5f)); _enemyLevels.Add(new List <Button>( Button.GetButtons(count, (int capturedIndex) => new Button("Level " + capturedIndex.ToString(), 3, 1, container, "EnemyLevel", fontSize: 20, Enter: (Button button) => button.SetColor(Color.green), Stay: (Button button) => { if (Input.GetMouseButtonDown(0)) { _selectedWaveEvent.level = capturedIndex; ShowWaveEventButtons(); ShowWaveEventEditor(butt, index); HideEnemyLevels(); } }, Exit: (Button button) => button.SetColor(Color.white), Close: (Button button) => { if (Input.GetMouseButtonDown(0)) { HideEnemyLevels(); } }))), true); }
public IEnumerator SessionHandler(Session session, CampaignDefinition selectedCampaign, int selectedCampaignIndex) { if (!Definitions.initialized) { Definitions.Initialize(Assets.Get(Assets.ObjectDataSets.Default)); } session.Hide(); while (!session.player.progress.HasCampaignProgress(selectedCampaignIndex)) { session.player.progress.AddCampaignProgress(); } MissionDefinition missionDefinition = session.player.progress.IsNewGame(selectedCampaignIndex) ? selectedCampaign.GetMissionDefinition(selectedCampaign.firstMissionIndex) : null; int missionIndex = selectedCampaign.firstMissionIndex; if (missionDefinition == null) { Vector3 offset = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.transform.position.y)) + (Vector3.left * selectedCampaign.width * 0.5f) + (Vector3.forward * selectedCampaign.height * 0.5f); CampaignMap campaignMap = new CampaignMap(selectedCampaign.width, selectedCampaign.height, selectedCampaign.columns, selectedCampaign.rows, offset); Layout campaignLayout = new Layout("Campaign", gameObject); for (int i = 0; campaignMap.tileMap.count > i; i++) { int iIndex = i; if (selectedCampaign.Has(i) && session.player.progress.HasCompleted(selectedCampaignIndex, i)) { Button button = new Button(selectedCampaign.GetMissionDefinition(i).name, campaignMap.tileMap.tileWidth - 1, campaignMap.tileMap.tileHeight * 0.5f, gameObject, "CampaignMap" + i, fontSize: 20, Enter: (Button b) => b.SetColor(Color.green), Stay: (Button b) => { if (Input.GetMouseButtonDown(0)) { missionIndex = iIndex; missionDefinition = selectedCampaign.GetMissionDefinition(iIndex); } }, Exit: (Button b) => b.SetColor(Color.cyan)); campaignLayout.Add(button); button.SetColor(Color.cyan); button.SetPosition(campaignMap.tileMap.PositionOf(i)); for (int j = 0; selectedCampaign.connections.Count > j; j++) { int jIndex = j; if (selectedCampaign.connections[j].fromIndex == i) { if (!session.player.progress.HasCompleted(selectedCampaignIndex, selectedCampaign.connections[j].toIndex)) { Button butt = new Button(selectedCampaign.GetMissionDefinition(selectedCampaign.connections[j].toIndex).name, campaignMap.tileMap.tileWidth - 1, campaignMap.tileMap.tileHeight * 0.5f, gameObject, "CampaignMap" + selectedCampaign.connections[j].toIndex, fontSize: 20, Enter: (Button b) => b.SetColor(Color.green), Stay: (Button b) => { if (Input.GetMouseButtonDown(0)) { missionIndex = selectedCampaign.connections[jIndex].toIndex; missionDefinition = selectedCampaign.GetMissionDefinition(selectedCampaign.connections[jIndex].toIndex); } }, Exit: (Button b) => b.SetColor(Color.white)); campaignLayout.Add(butt); butt.SetPosition(campaignMap.tileMap.PositionOf(selectedCampaign.connections[jIndex].toIndex)); } } } } } while (missionDefinition == null) { campaignLayout.Update(); yield return(null); } campaignLayout.Hide(); campaignLayout.Destroy(); } GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); quad.transform.rotation = Quaternion.Euler(90, 0, 0); quad.transform.position = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.transform.position.y)); quad.transform.localScale = new Vector3(12, 4, 1); TextMesh textMesh = new GameObject("StartText").AddComponent <TextMesh>(); textMesh.transform.localRotation = quad.transform.rotation; textMesh.transform.SetPositionAndRotation(quad.transform.position + Vector3.up, quad.transform.rotation); textMesh.fontSize = 200; textMesh.color = Color.black; textMesh.characterSize = 0.15f; textMesh.anchor = TextAnchor.MiddleCenter; textMesh.alignment = TextAlignment.Center; textMesh.text = "START"; float wait = Time.time + 3; while (wait > Time.time) { yield return(null); } quad.SetActive(false); textMesh.gameObject.SetActive(false); StageDefinition stageDefinition = missionDefinition.stageDefinition; session.SetConveyor(new Conveyor( speed: 7, width: 4, height: 15 + (1 * (stageDefinition.laneCount - 1)), itemInterval: 1, itemLimit: 8, itemWidthPadding: 1, itemSpacing: 0.1f)); session.SetStage(new Stage(stageDefinition, session.player, session.conveyor)); Level level = new Level(missionDefinition.duration); for (int i = 0; missionDefinition.waveDefinitions.Count > i; i++) { Wave wave = new Wave(missionDefinition.waveTimes[i] * missionDefinition.duration, session.stage); level.Add(wave); for (int j = 0; missionDefinition.waveDefinitions[i].waveEvents.Count > j; j++) { switch ((WaveEvent.Type)missionDefinition.waveDefinitions[i].waveEvents[j].type) { case WaveEvent.Type.SpawnEnemy: wave.Add(new SpawnEnemyEvent(Definitions.Enemy(Definitions.Enemies.Mini), missionDefinition.waveDefinitions[i].waveEvents[j])); break; } } } session.SetLevel(level); session.Show(); int heroCount = session.player.inventory.heroes.Count; int start = heroCount == 1 ? 2 : heroCount == 2 ? 1 : 0; int stride = start == 2 ? 0 : 2; for (int i = 0; session.player.inventory.heroes.Count > i; i++) { session.stage.AddHero(session.stage.LaneBy(start + (stride * i)), Definitions.Hero(Definitions.Heroes.Default)); } while (1 > session.level.progress || session.stage.enemies > 0 || session.stage.items > 0) { session.Update(1 > session.level.progress || session.stage.enemies > 0); yield return(null); } quad.SetActive(true); textMesh.gameObject.SetActive(true); session.stage.DestroyLanes(); session.level.HideProgress(); session.coinCounter.Hide(); if (session.heldItem != null) { session.heldItem.conveyorItem.Destroy(); session.heldItem.Destroy(); } session.Destroy(); textMesh.text = "STOP"; wait = Time.time + 3; while (wait > Time.time) { yield return(null); } quad.SetActive(false); textMesh.gameObject.SetActive(false); Destroy(textMesh.gameObject); Destroy(quad); //boss warning? //boss battle? //end of level fanfare if (!session.player.progress.HasCompleted(selectedCampaignIndex, missionIndex)) { session.player.progress.AddCompleted(selectedCampaignIndex, missionIndex); } Shop shop = new Shop(); shop.Show(session.player); while (!Input.GetMouseButtonDown(1)) { shop.Update(); yield return(null); } shop.Hide(); PlayerPrefs.SetString(session.player.name, JsonUtility.ToJson(session.player)); PlayerPrefs.Save(); StartSession(session.player, selectedCampaign, selectedCampaignIndex); }
public void ShowWaveEventButtons() { HideWaveEventButtons(); List <List <Button> > waveEventButtons = new List <List <Button> >(); for (int i = 0; _editor.stage.lanes > i; i++) { waveEventButtons.Add(new List <Button>()); Layout layout = new Layout("WaveEvent" + i.ToString() + "Layout", waveEventButtons[i].Count, 1, 0.25f, 0.1f, 1, container, false); layout.SetLocalPosition(_editor.stage.LaneBy(i).start + (Vector3.left * layout.width * 0.5f)); waveEventLayouts.Add(layout); Add(layout); } for (int i = 0; selectedWaveDefinition.waveEvents.Count > i; i++) { int index = i; int laneIndex = selectedWaveDefinition.waveEvents[index].lane; WaveEventDefinition waveEvent = selectedWaveDefinition.waveEvents[index]; Lane lane = _editor.stage.LaneBy(laneIndex); if (waveEventButtons.Count > laneIndex) { float width = 1; float height = 1; Color color = Color.white; string name = index.ToString(); switch ((WaveEvent.Type)waveEvent.type) { case WaveEvent.Type.SpawnEnemy: EnemyDefinition enemyDefinition = Definitions.Enemy((Definitions.Enemies)waveEvent.subType); EnemyLevel enemyLevel = enemyDefinition.levels[waveEvent.level]; width = enemyDefinition.width; height = lane.height - enemyDefinition.laneHeightPadding; name = enemyDefinition.name; color = enemyLevel.color; break; case WaveEvent.Type.SpawnItem: break; } Button button = new Button(name, width, height, container, "WaveEvent" + index.ToString(), fontSize: 20, Enter: (Button butt) => butt.SetColor(Color.green), Stay: (Button butt) => { if (Input.GetMouseButtonUp(0)) { for (int j = 0; waveEventButtons[laneIndex].Count > j; j++) { waveEventButtons[laneIndex][j].Hide(); } butt.Select(); _selectedWaveEvent = waveEvent; ShowWaveEventEditor(butt, index); } if (Input.GetMouseButtonDown(1)) { selectedWaveDefinition.Remove(waveEvent); ShowWaveEventButtons(); } }, Exit: (Button butt) => { if (_editor.timelineEditor.heldWave == null && heldWaveEvent == null && Input.GetMouseButton(0)) { heldWaveEvent = new HeldEvent(butt.rect.position, width, height, color, waveEvent, laneIndex); heldWaveEvent.SetText(name); } butt.SetColor(color); }, Close: (Button butt) => { if (Input.GetMouseButtonDown(0) && butt.selected && _waveTypes == null && _enemyLevels == null && _enemyTypes == null && _itemTypes == null && (waveEventEditor == null || !waveEventEditor.containsMouse)) { HideWaveEventEditor(); butt.Deselect(); for (int j = 0; waveEventButtons[selectedWaveDefinition.waveEvents[index].lane].Count > j; j++) { waveEventButtons[selectedWaveDefinition.waveEvents[index].lane][j].Show(); } } }); button.SetColor(color); waveEventButtons[laneIndex].Add(button); waveEventLayouts[laneIndex].Add(button); button.SetLocalPosition(new Vector3(waveEvent.entryPoint * lane.width, 1, 0)); } } }
public Editor(Player player, GameObject parent) : base("Editor", parent) { session = new Session(new Player()); session.Hide(); waveData = Assets.Get(Assets.WaveDataSets.Default); stageData = Assets.Get(Assets.StageDataSets.Default); objectData = Assets.Get(Assets.ObjectDataSets.Default); campaignData = Assets.Get(Assets.CampaignDataSets.Default); if (waveData == null) { waveData = Assets.Create <WaveData>(Assets.waveDataPath); } if (stageData == null) { stageData = Assets.Create <StageData>(Assets.stageDataPath); } if (campaignData == null) { campaignData = Assets.Create <CampaignData>(Assets.campaignDataPath); } if (objectData == null) { objectData = Assets.Create <ObjectData>(Assets.objectDataPath); } if (objectData.enemySets.Count == 0) { ScriptableObjects.Add(ScriptableObject.CreateInstance <EnemySet>(), objectData); } if (objectData.itemSets.Count == 0) { ScriptableObjects.Add(ScriptableObject.CreateInstance <ItemSet>(), objectData); } if (objectData.heroSets.Count == 0) { ScriptableObjects.Add(ScriptableObject.CreateInstance <HeroSet>(), objectData); } for (int i = objectData.enemySets[(int)Assets.ObjectDataSets.Default].enemyDefinitions.Count; (int)Definitions.Enemies.Count > i; i++) { ScriptableObjects.Add(ScriptableObject.CreateInstance <EnemyDefinition>().Initialize(((Definitions.Enemies)i).ToString(), 2, 1, (Definitions.Enemies)i), objectData.enemySets[(int)Assets.ObjectDataSets.Default]); } for (int i = objectData.heroSets[(int)Assets.ObjectDataSets.Default].heroDefinitions.Count; (int)Definitions.Heroes.Count > i; i++) { ScriptableObjects.Add(ScriptableObject.CreateInstance <HeroDefinition>().Initialize(((Definitions.Heroes)i).ToString(), 2, 1, (Definitions.Heroes)i), objectData.heroSets[(int)Assets.ObjectDataSets.Default]); } for (int i = objectData.itemSets[(int)Assets.ObjectDataSets.Default].itemDefinitions.Count; (int)Definitions.Items.Count > i; i++) { ScriptableObjects.Add(ScriptableObject.CreateInstance <ItemDefinition>().Initialize(((Definitions.Items)i).ToString(), 2, 1, (Definitions.Items)i), objectData.itemSets[(int)Assets.ObjectDataSets.Default]); } Definitions.Initialize(objectData); Add(testButton = new Button("Test", 1.5f, 0.5f, container, "Test", fontSize: 20, Enter: (Button button) => button.SetColor(stage != null && missionEditor.selectedMission != null ? Color.green : button.color), Stay: (Button button) => { if (stage != null && missionEditor.selectedMission != null && Input.GetMouseButtonDown(0)) { if (level == null) { stage.conveyor.Show(); session.SetLevel(new Level(missionEditor.selectedMission.duration, showProgress: false)); for (int i = 0; missionEditor.selectedMission.waveDefinitions.Count > i; i++) { Wave wave = new Wave(missionEditor.selectedMission.waveTimes[i] * missionEditor.selectedMission.duration, stage); level.Add(wave); for (int j = 0; missionEditor.selectedMission.waveDefinitions[i].waveEvents.Count > j; j++) { switch ((WaveEvent.Type)missionEditor.selectedMission.waveDefinitions[i].waveEvents[j].type) { case WaveEvent.Type.SpawnEnemy: wave.Add(new SpawnEnemyEvent(Definitions.Enemy((Definitions.Enemies)missionEditor.selectedMission.waveDefinitions[i].waveEvents[j].subType), missionEditor.selectedMission.waveDefinitions[i].waveEvents[j])); break; } } } button.SetLabel("Stop"); button.SetPosition(saveButton.position); saveButton.Hide(); saveButton.Disable(); objectsButton.Hide(); campaignButton.Hide(); stageEditor.HideStageSets(); stageEditor.HideStageEditor(); stageEditor.HideStageDefinitions(); missionEditor.HideMissionEditor(); waveEditor.HideWaveEventButtons(); session.Start(); } else { session.Stop(); stage.ClearLanes(); conveyor.Hide(); conveyor.Clear(); button.SetLabel("Test"); level.DestroyProgress(); session.SetLevel(null); _heldItem = null; _itemTime = 0; saveButton.Show(); saveButton.Enable(); objectsButton.Show(); campaignButton.Show(); stageEditor.ShowStageSets(); stageEditor.ShowStageEditor(); missionEditor.ShowMissionEditor(); testButton.SetPosition(saveButton.position + Vector3.right * (saveButton.width)); if (waveEditor.selectedWaveDefinition != null) { waveEditor.ShowWaveEventButtons(); } } } }, Exit: (Button button) => button.SetColor(Color.white))); Add(saveButton = new Button("Save", 1.5f, 0.5f, container, "Save", fontSize: 20, Enter: (Button button) => button.SetColor(Color.green), Stay: (Button button) => { if (Input.GetMouseButtonDown(0)) { EditorUtility.SetDirty(campaignData); EditorUtility.SetDirty(objectData); EditorUtility.SetDirty(stageData); EditorUtility.SetDirty(waveData); ScriptableObjects.Save(); } }, Exit: (Button button) => button.SetColor(Color.white))); saveButton.SetViewportPosition(new Vector2(0, 1)); saveButton.SetPosition(saveButton.position + Vector3.up); testButton.SetPosition(saveButton.position + Vector3.right * (saveButton.width)); testButton.Disable(); testButton.Hide(); Add(campaignButton = new Button("Campaigns", 2, 0.5f, container, "CampaignsButton", fontSize: 20, Enter: (Button button) => button.SetColor(button.selected ? button.color : Color.green), Stay: (Button button) => { if (!button.selected && Input.GetMouseButtonDown(0)) { ShowCampaignEditor(); } }, Exit: (Button button) => button.SetColor(button.selected ? button.color : Color.white))); campaignButton.SetViewportPosition(new Vector2(1, 1)); campaignButton.SetPosition(campaignButton.position + (Vector3.left * campaignButton.width) + Vector3.up); Add(objectsButton = new Button("Objects", 2, 0.5f, container, "ObjectsButton", fontSize: 20, Enter: (Button button) => button.SetColor(button.selected ? button.color : Color.green), Stay: (Button button) => { if (!button.selected && Input.GetMouseButtonDown(0)) { ShowObjectEditors(); } }, Exit: (Button button) => button.SetColor(button.selected ? button.color : Color.white))); objectsButton.SetPosition(campaignButton.position + Vector3.left * (objectsButton.width)); Add(campaignMapEditor = new CampaignMapEditor(this, container)); Add(campaignEditor = new CampaignEditor(this, Vector3.zero, container)); Add(timelineEditor = new TimelineEditor(this, container)); Add(missionEditor = new MissionEditor(this, container)); Add(stageEditor = new StageEditor(this, container)); Add(enemyEditor = new EnemyEditor(this, container)); Add(waveEditor = new WaveEditor(this, container)); Add(itemEditor = new ItemEditor(this, container)); Add(heroEditor = new HeroEditor(this, container)); ShowCampaignEditor(); }