//Loads the selected level public void LoadLevel(int index) { //Make sure if the selected level exists, //if not, go to main menu if (index < 0 || index >= allLevels.Length) { egc.ExitGame(); return; } //Find current level and destroy it GameLevel current = FindObjectOfType <GameLevel>(); if (current != null) { Destroy(current.gameObject); } //Instantiate the new level GameObject newLevelObject = (GameObject)Instantiate(allLevels[index].gameObject); GameLevel newLevelScript = newLevelObject.GetComponent <GameLevel>(); //Set the parent and the position of the level newLevelObject.transform.parent = transform; newLevelObject.transform.position = Vector2.zero; //Change current level index currentLevel = index; //Change background to the new level bgManager.ChangeBackground(newLevelScript.backgroundIndex); //Inform about new level load SendMessage("NewLevelLoaded"); }
public void Initialize() { List <IManager> managers = new List <IManager>(); managers.Add(scene1Text = CreateInstance(typeof(Scene1Text)) as Scene1Text); managers.Add(bgManager = GameObject.FindObjectOfType <BackgroundManager>()); managers.Add(textManager = GameObject.FindObjectOfType <TextManager>()); wardrobeManager = CreateInstance(typeof(WardrobeManager)) as WardrobeManager; loadManager = FindObjectOfType <LoadManager>(); foreach (var i in managers) { i.Initialize(); } reputationManager = GameObject.FindObjectOfType <ReputationManager>(); BackgroundManager.curBackground = BackgroundManager.backgroundsList[0]; bgManager.ChangeBackground(); SceneManager.sceneLoaded += OnLevelLoaded; relationsData = new RelationsData(); RelationsData.LoadData(); int ready = 0; while (ready < managers.Count) { foreach (var i in managers) { if (i.status == ManagerStatus.Online) { ready++; } } } status = ManagerStatus.Online; }
//Next command public void Next() { for (;;) { if (programCounter >= commands.Count) { Debug.LogWarning("programCounter >= commands.Count"); Debug.LogWarning(programCounter); return; } Debug.Log(programCounter); if (commands[programCounter].GetType() == typeof(DialogueAndNarration)) { DialogueAndNarration dialogueAndNarrationCommand = (DialogueAndNarration)commands[programCounter]; //Debug.Log(dialogueAndNarrationCommand); dialogueManager.SetText(((dialogueAndNarrationCommand.Character != null) ? dialogueAndNarrationCommand.Character.Name : "") + "\n\n" + dialogueAndNarrationCommand.Text); programCounter++; return; } else if (commands[programCounter].GetType() == typeof(string[])) { string[] arrayCommand = (string[])commands[programCounter]; Debug.Log(string.Join(", ", arrayCommand)); switch (arrayCommand[0]) { case "hide": if (arrayCommand.Length == 2) { characterManager.RemoveCharacter(arrayCommand[1]); } else if (arrayCommand.Length == 3) { if (arrayCommand[2].ToUpper().Equals("FADEOUT")) { characterManager.GetCharacter(arrayCommand[1]).GetComponent <CharacterModel>().FadeOutInit(1f); } } else { if (arrayCommand[2].ToUpper().Equals("FADEOUT")) { characterManager.GetCharacter(arrayCommand[1]).GetComponent <CharacterModel>().FadeOutInit(int.Parse(arrayCommand[3])); } } programCounter++; continue; case "jump": if (labels.ContainsKey(arrayCommand[1])) { programCounter = labels[arrayCommand[1]]; continue; } else { Debug.LogWarning(string.Format("Unknown label `{0}`", arrayCommand[1])); programCounter++; return; } case "play": if (arrayCommand[1].ToUpper().Equals("MUSIC")) { audioManager.ChangeMusic(arrayCommand[2], true); } else if (arrayCommand[1].ToUpper().Equals("SOUND")) { audioManager.PlaySound(arrayCommand[2]); } programCounter++; continue; case "scene": if (arrayCommand[2] == null) { backgroundManager.ChangeBackground(arrayCommand[1]); } else { string[] trans = arrayCommand[2].Split(' '); if (trans.Length == 1) { backgroundManager.ChangeBackground(arrayCommand[1], transitions[trans[0]]); } else if (trans.Length == 2) { backgroundManager.ChangeBackground(arrayCommand[1], transitions[trans[0]], int.Parse(trans[1])); } else { Debug.Log(string.Format("Excessive Transition modifiers at line '{0}'.")); } } programCounter++; continue; case "lighting": float[] newLight; lightingColors.TryGetValue(arrayCommand[1], out newLight); if (newLight != null) { backgroundManager.AmbientLight.GetComponent <Light>().color = new Color(newLight[0], newLight[1], newLight[2]); backgroundManager.AmbientLight.GetComponent <Light>().intensity = newLight[3]; } else { Debug.Log(string.Format("Unknown lighting parameter '{0}'.", arrayCommand[1])); } programCounter++; continue; case "show": string[] anims = arrayCommand[1].Split(' '); if (!characterManager.GetCharacter(anims[0])) { characterManager.AddCharacter(anims[0]); } if (anims.Length > 1) { for (int i = 1; i < anims.Length; i++) { characterManager.StartAnimation(anims[i], anims[0]); } } else { characterManager.StartAnimation(anims[1], anims[0]); } programCounter++; continue; case "choices": if (!dialogueManager.choiceState && !dialogueManager.choiceBuffer) { int numChoices = int.Parse(arrayCommand[1]); string[] choiceTexts = new string[numChoices]; string choiceName = arrayCommand[2]; //Debug.LogError(choiceName); for (int l = 1; l <= numChoices; l++) { //Debug.LogError(2 + l * 3); choiceTexts[l - 1] = arrayCommand[2 + l * 3]; } dialogueManager.ChoiceInit(choiceTexts, choiceName); return; } else if (dialogueManager.choiceBuffer) { if (dialogueManager.GetSelectedChoice() < 1 || dialogueManager.GetSelectedChoice() > 5) { Debug.LogError("Invalid choice index returned: " + dialogueManager.GetSelectedChoice() + " Choice aborted"); programCounter++; dialogueManager.ResetChoice(); return; } else { int choiceIndex = dialogueManager.GetSelectedChoice() * 3; //choiceData.Add("" + choiceIndex/3); if (labels.ContainsKey(arrayCommand[choiceIndex + 1])) { programCounter = labels[arrayCommand[choiceIndex + 1]]; dialogueManager.ResetChoice(); continue; } else { Debug.LogWarning(string.Format("Unknown label assigned to choice `{0}`", arrayCommand[choiceIndex])); programCounter++; dialogueManager.ResetChoice(); return; } } } else { return; } case "return": //UnityEditor.EditorApplication.isPlaying = false; programCounter++; return; default: Debug.LogWarning(string.Format("Unknown command `{0}`", arrayCommand[0])); programCounter++; continue; } } else { Debug.LogWarning(string.Format("Unknown command `{0}`", commands[programCounter])); programCounter++; continue; } } }