public override void Run_Node() { if (ActorManager.Is_Actor_On_Scene(actor_name)) { if (!slide_out && !fade_out) { ActorManager.Remove_Actor(actor_name); Finish_Node(); } else { Actor actor = ActorManager.Get_Actor(actor_name); if (fade_out) { // Fade out actor.Fade_Out(fade_out_time); } else { // Slide out actor.Slide_Out(1f); } StartCoroutine(Wait(actor)); } } else { Debug.Log(actor_name + " is not on the scene. Remember to correctly name your actor and use 'EnterActorNode'"); Finish_Node(); } }
IEnumerator Fade_Out_Coroutine(float over_time) { if (!ActorManager.exiting_actors.Contains(this)) { ActorManager.exiting_actors.Add(this); } Image img = this.GetComponent <Image>(); Color tmp_color = img.color; tmp_color.a = 1; float value = 0; while (value < over_time) { value += Time.deltaTime; tmp_color.a = Mathf.Lerp(1, 0, value / over_time); img.color = tmp_color; yield return(0); } // Remove this actor after we're done Debug.Log("Removing actor " + actor_name); ActorManager.Remove_Actor(this.actor_name); yield break; }
// Instantly places the actor at the designated position public void Place_At_Position(Actor_Positions destination) { position = destination; ActorManager.Add_Actor_To(this, destination); this.rect = this.GetComponent <RectTransform>(); this.rect.localPosition = this.desired_position; }
// Instantiates an actor from the Resources/Actors folder with the name actor_name. // It then sets the object as a child of the Actors object in the canvas public static Actor Instantiate_Actor(string actor_name, Actor_Positions destination, Transform custom_position = null) { // Check to see if the actor is already on the scene Actor a = ActorManager.Get_Actor(actor_name); if (a != null) { Debug.Log("Actor " + actor_name + " already on scene"); return(a); } if (UIManager.ui_manager.actor_parent == null) { Debug.LogError("Unable to instantiate Actor " + actor_name + " because UIManager's actor_parent field is empty. Please set actor_parent field to an object."); } // Check if there is a disabled actor available to use if (use_inactive_actors) { Actor[] disabled_actors = UIManager.ui_manager.actor_parent.gameObject.GetComponentsInChildren <Actor>(true); foreach (Actor acto in disabled_actors) { if (acto.actor_name == actor_name) { // Found a correct actor, set it up correctly a = acto; a.Reset(); a.gameObject.SetActive(true); } } } if (a == null) { // Proceed with creating a gameobject GameObject actor = Instantiate(Resources.Load("Actors/" + actor_name, typeof(GameObject)), UIManager.ui_manager.actor_parent) as GameObject; a = actor.GetComponent <Actor>(); } actors_on_scene.Add(a); // Add to list of actors // Place actor at custom position if (destination == Actor_Positions.CUSTOM && custom_position != null) { //a.rect.localPosition = custom_position.position; a.desired_position = new Vector3(custom_position.GetComponent <RectTransform>().localPosition.x, custom_position.GetComponent <RectTransform>().localPosition.y *a.transform.localScale.y); a.custom_position = custom_position; } // Use standard automatic position calculations else { ActorManager.Add_Actor_To(a, destination); } return(a); }
void Awake() { actor_manager = this; actors_on_scene = new List <Actor>(); exiting_actors = new List <Actor>(); left_actors = new List <Actor>(); right_actors = new List <Actor>(); }
// Calls a coroutine to slide in this actor over a number of seconds specified by over_time public void Slide_In(Actor_Positions destination, float over_time) { rect = GetComponent <RectTransform>(); ActorManager.Add_Actor_To(this, destination); // Set our starting point so we slide into our desired position ActorManager.actor_manager.Slide_Start_Position(this, position); }
public override void Run_Node() { Actor actor = ActorManager.Get_Actor(actor_name); // Can only change the animation of an actor if they're already on the scene if (actor != null) { actor.Play_Animation(animation_name); } Finish_Node(); }
public override void Run_Node() { if (ActorManager.Is_Actor_On_Scene(actor_name)) { Actor actor = ActorManager.Get_Actor(actor_name); SaveManager.SetSaveFeature(this, actor.gameObject); Debug.Log("Actor on scene " + actor.actor_name); if (fade_in_new_image) { Sprite old_sprite = actor.cur_image.overrideSprite; if (lighten_actor) { actor.Lighten(); } if (bring_actor_to_front) { ActorManager.Bring_Actor_To_Front(actor); } // Fade out old image actor.fading_child_image.gameObject.SetActive(true); actor.fading_child_image.overrideSprite = old_sprite; // Set colour of old image to match current image actor.fading_child_image.color = actor.cur_image.color; actor.fading_child_image.GetComponent <RectTransform>().sizeDelta = actor.rect.sizeDelta; StartCoroutine(Fade_Out_Coroutine(fade_out_time, actor.fading_child_image)); // Fade in new image actor.cur_image.overrideSprite = new_image; StartCoroutine(Fade_In_Coroutine(fade_out_time, actor.cur_image)); // Wait before we allow it to finish StartCoroutine(Wait(actor, fade_out_time * 1.1f)); } else { Debug.Log("Actor on scene " + actor.actor_name); actor.cur_image.overrideSprite = new_image; Finish_Node(); } } else { Finish_Node(); Debug.Log(actor_name + " is not on the scene. Remember to correctly name your actor and use 'EnterActorNode'"); } }
public override void Run_Node() { Actor actor = ActorManager.Get_Actor(actor_name); Vector3 scale = actor.transform.localScale; scale.x = -scale.x; actor.transform.localScale = scale; SaveManager.SetSaveFeature(this, actor.gameObject); Finish_Node(); }
public override void Run_Node() { Actor actor_script; // Check if the actor is already present if (ActorManager.Is_Actor_On_Scene(actor_name)) { // Actor is already on the scene Debug.Log("Actor " + actor_name + " already on scene"); actor_script = ActorManager.Get_Actor(actor_name).GetComponent <Actor>(); Finish_Node(); return; } else { // Actor is not in the scene. Instantiate it if (VNSceneManager.verbose_debug_logs) { Debug.Log("Creating new actor " + actor_name); } if (destination == Actor_Positions.CUSTOM && custom_position != null) { actor_script = ActorManager.Instantiate_Actor(actor_name, destination, custom_position); } else { actor_script = ActorManager.Instantiate_Actor(actor_name, destination); } } SaveManager.SetSaveFeature(this, actor_script.gameObject); switch (entrance_type) { case Entrance_Type.Slide_In: actor_script.Slide_In(destination, 2.0f); Finish_Node(); break; case Entrance_Type.Fade_In: actor_script.Place_At_Position(destination); actor_script.Fade_In(fade_in_time); StartCoroutine(Wait(fade_in_time + 0.2f)); break; case Entrance_Type.None: Finish_Node(); break; } }
public override void Run_Node() { VNSceneManager.scene_manager.Show_UI(true); // Ensure dialogue panel is visible running = true; UIManager.ui_manager.text_panel.text = ""; // Get localized text and sub in Stats values GetLocalizedText(false); StartCoroutine(Animate_Text(text)); // If the actor field is filled in and the actor is present on the scene Actor speaker = ActorManager.Get_Actor(actor); if (actor != "" && speaker != null) { // Slightly darken all other actors if (darken_all_other_characters) { ActorManager.Darken_All_Actors_But(speaker); } // Lighten this actor to show this one is talking speaker.Lighten(); // Bring this actor to the front if (bring_speaker_to_front) { ActorManager.Bring_Actor_To_Front(speaker); } } if (voice_clip != null && voice_clip.clip != null) { // Play audio if there is any voice_clip.volume = AudioManager.audio_manager.voice_volume; voice_clip.Play(); } else { done_voice_clip = true; no_voice_playing = true; } }
// Slides the actor out, and remove the actor after it has gone public void Slide_Out(float over_time) { rect = GetComponent <RectTransform>(); if (!remove_when_out_of_sight) { if (this.position == Actor_Positions.LEFT) { ActorManager.left_actors.Remove(this); desired_position = ActorManager.actor_manager.offscreen_left.localPosition; if (!ActorManager.exiting_actors.Contains(this)) { ActorManager.exiting_actors.Add(this); } } else if (this.position == Actor_Positions.RIGHT) { ActorManager.right_actors.Remove(this); desired_position = ActorManager.actor_manager.offscreen_right.localPosition; if (!ActorManager.exiting_actors.Contains(this)) { ActorManager.exiting_actors.Add(this); } } else if (this.position == Actor_Positions.CENTER) { ActorManager.center_actors.Remove(this); desired_position = ActorManager.actor_manager.offscreen_right.localPosition; if (!ActorManager.exiting_actors.Contains(this)) { ActorManager.exiting_actors.Add(this); } } else if (this.position == Actor_Positions.CUSTOM) { desired_position = ActorManager.Closest_Side_To_Exit(this); if (!ActorManager.exiting_actors.Contains(this)) { ActorManager.exiting_actors.Add(this); } } desired_position.y = 0;// ActorManager.Get_Actor_Y_Position(this); remove_when_out_of_sight = true; } }
IEnumerator Wait_Until_Actor_Is_Stopped() { yield return(0); Actor actor = ActorManager.Get_Actor(actor_name); if (actor == null) { Debug.Log("Could not find actor"); Finish_Node(); } while (actor.is_moving) { yield return(0); } Finish_Node(); }
public override void Run_Node() { // Check if the Actor is on the scene if (!ActorManager.Is_Actor_On_Scene(actor_name)) { Debug.LogError(actor_name + " actor is not on the scene. Please use an Enter Actor Node for " + actor_name); Finish_Node(); return; } ActorManager.Move_Actor_Outwards(ActorManager.Get_Actor(actor_name)); if (wait_until_actor_has_stopped) { StartCoroutine(Wait_Until_Actor_Is_Stopped()); } else { Finish_Node(); } }
public void Update() { is_moving = false; // Move towards desired position if we are not at our desired position if (this.rect.localPosition != desired_position) { this.rect.localPosition = Vector3.Lerp(this.rect.localPosition, desired_position, 3f * Time.deltaTime); //this.transform.position = Vector3.Lerp(this.transform.position, desired_position, 3f * Time.deltaTime); if (Vector2.Distance(this.rect.localPosition, desired_position) > 1f) { is_moving = true; } } // If sliding out, check if we're visible. If we're not visible, remove the actor if (remove_when_out_of_sight && Mathf.Abs(this.rect.localPosition.x - desired_position.x) <= 30) { ActorManager.Remove_Actor(this.actor_name); } }
public override void Run_Node() { if (!slide_out && !fade_out) { for (int x = ActorManager.actors_on_scene.Count - 1; x >= 0; x--) { Debug.Log("Exit all immediately: " + ActorManager.actors_on_scene[x].actor_name); ActorManager.Remove_Actor(ActorManager.actors_on_scene[x]); } } else { for (int x = ActorManager.actors_on_scene.Count - 1; x >= 0; x--) { Debug.Log("Exit all: " + ActorManager.actors_on_scene[x].actor_name); Actor actor = ActorManager.actors_on_scene[x]; if (fade_out) { // Fade out actor.Fade_Out(1f); } else { // Slide out actor.Slide_Out(1f); } } } if (wait_for_actors_to_exit) { StartCoroutine(Wait()); } else { Finish_Node(); } }
public override void Run_Node() { if (string.IsNullOrEmpty(actor)) { Debug.LogError("Actor " + actor + " name is null or empty", this.gameObject); } // Check if the actor is already present else if (ActorManager.Is_Actor_On_Scene(actor)) { // Actor is already on the scene Actor actor_script = ActorManager.Get_Actor(actor); actor_script.position = destination; ActorManager.Remove_Actor_From_Positions_Lists(actor_script); ActorManager.Add_Actor_To(actor_script, destination); } else { Debug.LogError("Actor " + actor + " is not on the scene. Use EnterActorNode to place them on the scene", this.gameObject); } Finish_Node(); }
// 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 override void Run_Node() { ActorManager.Darken_All_Actors(); Finish_Node(); }
public string actor_name; // Actor to darken public override void Run_Node() { ActorManager.Get_Actor(actor_name).Darken(); Finish_Node(); }
public string actor_name; // Actor to bring backwards public override void Run_Node() { ActorManager.Bring_Actor_To_Back(ActorManager.Get_Actor(actor_name)); Finish_Node(); }