public override void Run_Node() { sceneName = String.Empty; activityNumber = StatsManager.Get_Numbered_Stat("intActivity"); activityName = StatsManager.Get_String_Stat("strActivity"); //EX: conversation_to_start = GameObject.Find("ArtActivityManager").GetComponent<ConversationManager>(); switch (activityName) { case "study": sceneName += "s_"; break; case "workout": sceneName += "w_"; activityNumber += 600; break; case "art": sceneName += "a_"; activityNumber += 1200; break; case "talk": sceneName += "t_"; activityNumber += 1800; break; case "play": sceneName += "p_"; activityNumber += 2400; break; } IsNewScene(); seenScenes.Add(activityNumber); //sceneName += activityNumber; sceneName += 1; conversation_to_start = GameObject.Find(sceneName).GetComponent <ConversationManager>(); StartCoroutine(Check_If_Actors_Have_Exited()); Finish_Node(); }
// Starts the designated conversation, and stops the current conversation public void Change_Conversation(ConversationManager conversation_to_start) { VNSceneManager.current_conversation.Finish_Conversation(); conversation_to_start.Start_Conversation(); }
public void Start_Conversation(ConversationManager conversation) { conversation.Start_Conversation(); }
private static void ImportTxtScriptFile() { string path = EditorUtility.OpenFilePanel("Select a script file to import", "", "txt"); if (string.IsNullOrEmpty(path)) { return; } Debug.Log("Reading in .txt script file: " + path); // Read the file string line; System.IO.StreamReader file = new System.IO.StreamReader(path); // Create a child object to hold all elements created from this file Transform import_parent = (new GameObject(Path.GetFileNameWithoutExtension(path))).transform; ConversationManager cur_conversation = null; // Read it line by line while ((line = file.ReadLine()) != null) { // Continue if it's an empty line if (String.IsNullOrEmpty(line)) { continue; } string[] split_line = line.Split(new char[] { ':' }, 2); // Create a new conversation if (line.StartsWith("Conversation", true, System.Globalization.CultureInfo.InvariantCulture)) { GameObject go = new GameObject(split_line[1] + " Conversation"); go.transform.parent = import_parent; ConversationManager new_conv = go.AddComponent <ConversationManager>(); if (cur_conversation != null) { cur_conversation.start_conversation_when_done = new_conv; } cur_conversation = new_conv; } else if (line.StartsWith("EnterActor", true, System.Globalization.CultureInfo.InvariantCulture)) { GameObject go = new GameObject("Enter " + split_line[1]); go.transform.parent = cur_conversation.transform; EnterActorNode node = go.AddComponent <EnterActorNode>(); node.actor_name = split_line[1]; } else if (line.StartsWith("ExitActor", true, System.Globalization.CultureInfo.InvariantCulture)) { GameObject go = new GameObject("Exit " + split_line[1]); go.transform.parent = cur_conversation.transform; ExitActorNode node = go.AddComponent <ExitActorNode>(); node.actor_name = split_line[1]; } else if (line.StartsWith("SetBackground", true, System.Globalization.CultureInfo.InvariantCulture)) { GameObject go = new GameObject("Set Background " + split_line[1]); go.transform.parent = cur_conversation.transform; SetBackground node = go.AddComponent <SetBackground>(); try { node.sprite = Resources.Load <Sprite>(split_line[1]); } catch (Exception e) { Debug.Log("Error loading audio clip " + split_line[1] + ". Make sure your named clip matches the resource. Ex: some_folder/cool_music"); } } else if (line.StartsWith("SetMusic", true, System.Globalization.CultureInfo.InvariantCulture)) { GameObject go = new GameObject("Set Music " + split_line[1]); go.transform.parent = cur_conversation.transform; SetMusicNode node = go.AddComponent <SetMusicNode>(); // If possible, load the necessary resource try { node.new_music = Resources.Load <AudioClip>(split_line[1]); } catch (Exception e) { Debug.Log("Error loading audio clip " + split_line[1] + ". Make sure your named clip matches the resource. Ex: some_folder/cool_music"); } } // ADD MORE HERE IF YOU WISH TO EXTEND THE IMPORTING FUNCTIONALITY // // // // // // Must be a line of dialogue else if (split_line.Length == 2) { GameObject go = new GameObject(split_line[0]); go.transform.parent = cur_conversation.transform; DialogueNode node = go.AddComponent <DialogueNode>(); node.actor = split_line[0]; node.textbox_title = split_line[0]; node.text = split_line[1]; } } file.Close(); Debug.Log("Done importing script: " + path); }
// Loads a scene and sets the settings of this save file to the game // Must be called with a monobehaviour with StartCoroutine(Load()) // Modify this method to add in your own custom loading code public IEnumerator Load() { Debug.Log("Loading..." + current_conv_node); StatsManager.Clear_All_Stats(); string active_scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; // UI is unresponsive if there are 2 event systems if (UnityEngine.EventSystems.EventSystem.current.gameObject) { GameObject.Destroy(UnityEngine.EventSystems.EventSystem.current.gameObject); } // Load items StatsManager.items = saved_items; VNSceneManager.scene_manager = null; // Load the scene that was saved UnityEngine.SceneManagement.SceneManager.LoadScene(current_scene, UnityEngine.SceneManagement.LoadSceneMode.Additive); // Must wait 1 frame before initializing the new scene yield return(null); // Unpause in case the game was paused before loading Pause.pause.ResumeGame(); // Stop the default things from happening VNSceneManager.scene_manager.starting_conversation = null; ConversationManager cur_conv = GameObject.Find(current_conv).GetComponent <ConversationManager>(); // Set log VNSceneManager.scene_manager.Add_To_Log("", log_text); // Set play time VNSceneManager.scene_manager.play_time += time_played; ActorManager.actors_on_scene = new List <Actor>(); ActorManager.exiting_actors = new List <Actor>(); ActorManager.left_actors = new List <Actor>(); ActorManager.right_actors = new List <Actor>(); ActorManager.center_actors = new List <Actor>(); /* * // Load the actors on the scene * foreach (string a in left_actors) * { * ActorManager.Instantiate_Actor(a, Actor_Positions.LEFT); * } * foreach (string a in right_actors) * { * ActorManager.Instantiate_Actor(a, Actor_Positions.RIGHT); * } * foreach (string a in center_actors) * { * ActorManager.Instantiate_Actor(a, Actor_Positions.CENTER); * } */ // Execute any Nodes that need to executed to create the scene (StaticImageNodes, SetBackground, SetMusicNode, ChangeActorImage, etc) foreach (string node_path in Nodes_to_Execute_on_Load) { // Figure out what type of Node we're dealing with string[] node_parts = node_path.Split(new string[] { feature_save_separation_character }, StringSplitOptions.None); // We can figure out which node is executed by the Node component embedded in the string if (node_parts.Length == 2) { GameObject go = GameObject.Find(node_parts[1]); if (go == null) { Debug.LogError("Load: Could not find node to execute; " + node_path); continue; } Node n = (Node)go.GetComponent(node_parts[0]); if (n != null) { n.executed_from_load = true; n.Run_Node(); } else { Debug.LogError("Load: Gameobject did not have attached node to execute; " + node_path); } } // Can't figure out which node type this is, simply execute the first node on the found gameobject else if (node_parts.Length == 1) { GameObject go = GameObject.Find(node_path); if (go == null) { Debug.LogError("Load: Could not find node to execute; " + node_path); continue; } Node n = go.GetComponent <Node>(); if (n != null) { n.executed_from_load = true; n.Run_Node(); } else { Debug.LogError("Load: Gameobject did not have attached node to execute; " + node_path); } } } // Delete conversations not present in our saved conversations ConversationManager[] convs = (ConversationManager[])UnityEngine.Object.FindObjectsOfType(typeof(ConversationManager)) as ConversationManager[]; foreach (ConversationManager c in convs) { // Find all conversations in our freshly loaded scene, check if we should keep or delete these conversations string name = (c.name); // Record the full name of the object (including its parents) Transform parent = c.transform.parent; while (parent != null) { name = name.Insert(0, parent.name + "/"); parent = parent.parent; } bool delete_conv = true; // Check against saved conversations foreach (string s in remaining_conversations) { if (name == s) { delete_conv = false; break; } } if (delete_conv) { GameObject.Destroy(c.gameObject); } } // Load stats StatsManager.boolean_stats = saved_boolean_stats; StatsManager.numbered_stats = saved_numbered_stats; StatsManager.string_stats = saved_string_stats; StatsManager.items = saved_items; StatsManager.Print_All_Stats(); // Load log text VNSceneManager.text_logs = log_categories; VNSceneManager.scene_manager.Conversation_log = log_text; //<< MODIFY THIS SECTION TO LOAD THINGS SPECIFIC TO YOUR GAME >>// //<< MODIFY THE ABOVE SECTION TO LOAD THINGS SPECIFIC TO YOUR GAME >>// // Start the conversation cur_conv.Start_Conversation_Partway_Through(current_conv_node); yield return(0); // Flip any actors that are meant to be flipped foreach (string a in flipped_actors) { Actor actor = ActorManager.Get_Actor(a); if (a != null) { actor.transform.localScale = new Vector3(-actor.transform.localScale.x, actor.transform.localScale.y, actor.transform.localScale.z); } } UnityEngine.SceneManagement.SceneManager.SetActiveScene(UnityEngine.SceneManagement.SceneManager.GetSceneByName(current_scene)); UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(active_scene); AudioListener.pause = false; yield return(0); }
public IEnumerator Running() { // Wait a frame so we can evaluate if objects we check for requirements have been destroyed yield return(0); bool conditions_met = true; for (int x = 0; x < Number_Of_Conditions; x++) { bool cur_condition = false; // Evaluate each condition sequentially switch (Conditions[x]) { case Condition.Bool_Stat_Requirement: cur_condition = StatsManager.Compare_Bool_Stat_To(Stat_Name[x], Bool_Compare_Value[x]); break; case Condition.Float_Stat_Requirement: cur_condition = StatsManager.Compare_Float_Stat(Stat_Name[x], Float_Stat_Is[x], Float_Compare_Value[x]); break; case Condition.String_Stat_Requirement: bool the_same = true; switch (String_Is[x]) { case Result.Is: the_same = true; break; case Result.Is_Not: the_same = false; break; } cur_condition = StatsManager.Compare_String_Stat_To(Stat_Name[x], String_Compare_Value[x], the_same); break; case Condition.Object_Is_Null: // Check if object exists // If the object doesn't exist, and the box is checked // OR the object exists and the box is not checked cur_condition = Check_Null_Object[x] && !Bool_Compare_Value[x]; break; case Condition.Object_Is_Active: // Check if the gameobject is enabled cur_condition = Check_Active_Object[x].activeSelf && Bool_Compare_Value[x]; break; } // Check if need to keep going with AND's or OR's if (x == 0) { // First condition, nothing to AND or OR with conditions_met = cur_condition; } else if (x < Number_Of_Conditions) { // Must AND or OR the previous condition switch (Logic[x - 1]) { case Boolean_Logic.And: conditions_met = conditions_met && cur_condition; break; case Boolean_Logic.Or: conditions_met = conditions_met || cur_condition; break; } } } if ((Is_Condition_Met == Condition_Is.Met && conditions_met) || (Is_Condition_Met == Condition_Is.Not_Met && !conditions_met)) { switch (Action) { case Requirement_Met_Action.Change_Conversation: if (Conversation_To_Switch_To != null) { Conversation_To_Switch_To.Start_Conversation(); } else { Debug.LogError("No conversation to switch to", this.gameObject); } break; case Requirement_Met_Action.Jump_to_Middle_of_Conversation: if (!Node_To_Switch_To) { Debug.LogError("Node to switch to not set in IfNode", gameObject); break; } ConversationManager cm = Node_To_Switch_To.GetComponentInParent <ConversationManager>(); if (cm) { cm.Start_At_Node(Node_To_Switch_To); } else { Debug.LogError("Couldn't find Conversation associated with Node: " + Node_To_Switch_To.name, gameObject); } break; case Requirement_Met_Action.Custom_Events: Custom_Actions.Invoke(); if (Continue_Conversation) { Finish_Node(); } break; } } else { // Just continue conversation Finish_Node(); } }