示例#1
0
        public IEnumerator Running()
        {
            // Wait a frame so we can evaluate if objects we check for requirements have been destroyed
            yield return(0);

            // Display the choices on the UI
            UIManager.ui_manager.choice_panel.SetActive(true);

            if (Localize_Choice_Text)
            {
                UIManager.ui_manager.choice_text_banner.text = VNSceneManager.scene_manager.Get_Localized_Dialogue_Entry(Name_Of_Choice);  // Localize the name of the choice;
            }
            else
            {
                UIManager.ui_manager.choice_text_banner.text = Name_Of_Choice;
            }

            if (Hide_Dialogue_UI)
            {
                VNSceneManager.scene_manager.Show_UI(!Hide_Dialogue_UI);
            }

            // Loop through each button
            // Make buttons that have events visible, set their text,
            // add call to Finish_Node() on the OnClick() listener and hook up the choices buttons to the events on this node
            for (int x = 0; x < Number_Of_Choices; x++)
            {
                if (Button_Events[x].GetPersistentEventCount() > 0)
                {
                    // Set a button image for this button if we have one
                    if (x < choice_button_images.Length && choice_button_images[x] != null)
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().sprite = choice_button_images[x];

                        if (use_image_native_size_for_buttons)
                        {
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().preserveAspect = true;
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().type           = Image.Type.Simple;
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().SetNativeSize();
                            UIManager.ui_manager.choice_buttons[x].GetComponent <LayoutElement>().preferredHeight = -1;
                        }
                    }
                    // No image to set, use reset it to the default one
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().sprite = default_button_sprite;
                        UIManager.ui_manager.choice_buttons[x].GetComponent <LayoutElement>().preferredHeight = default_button_flexible_height;
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().preserveAspect          = false;
                        //UIManager.ui_manager.choice_buttons[x].GetComponent<Image>().SetNativeSize();
                    }

                    UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(true);    // Make visible
                    UIManager.ui_manager.choice_buttons[x].interactable = true;
                    bool requirement_met = true;

                    if (Localize_Choice_Text)
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = VNSceneManager.scene_manager.Get_Localized_Dialogue_Entry(Button_Text[x]);   // Set button text, get localized version
                    }
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = Button_Text[x];   // Set button text
                    }
                    //(Choice_Been_Clicked_Before[x] ||
                    if (Show_Choice_Was_Selected_Before[x] && StatsManager.Compare_Bool_Stat_To(Name_Of_Choice + ": " + Button_Text[x], true))
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentsInChildren <Image>(true)[1].enabled = true;
                    }
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentsInChildren <Image>(true)[1].enabled = false;
                    }


                    if (Has_Requirements[x] != Choice_Stat_Requirement.No_Requirement)
                    {
                        // Loop through each requirement
                        for (int req = 0; req < max_number_of_buttons; req++)
                        {
                            bool this_requirement_met = true;

                            // No more requirements
                            if (req > 0 && Logic[x * max_number_of_buttons + (req - 1)] == Choice_Boolean_Logic.Done)
                            {
                                break;
                            }

                            // Check stat requirements
                            switch (Requirement_Type[x * max_number_of_buttons + req])
                            {
                            case Choice_Condition.Float_Stat_Requirement:
                                this_requirement_met = StatsManager.Compare_Float_Stat(Stat_Name[x * max_number_of_buttons + req], Float_Stat_Is[x * max_number_of_buttons + req], Float_Compare_Value[x * max_number_of_buttons + req]);
                                break;


                            case Choice_Condition.Bool_Stat_Requirement:
                                this_requirement_met = StatsManager.Compare_Bool_Stat_To(Stat_Name[x * max_number_of_buttons + req], Bool_Compare_Value[x * max_number_of_buttons + req]);
                                break;


                            case Choice_Condition.String_Stat_Requirement:
                                bool the_same = true;
                                switch (String_Is[x * max_number_of_buttons + req])
                                {
                                case Result.Is:
                                    the_same = true;
                                    break;

                                case Result.Is_Not:
                                    the_same = false;
                                    break;
                                }
                                this_requirement_met = StatsManager.Compare_String_Stat_To(Stat_Name[x * max_number_of_buttons + req], String_Compare_Value[x * max_number_of_buttons + req], the_same);
                                break;


                            case Choice_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
                                this_requirement_met = Check_Null_Object[x * max_number_of_buttons + req] && !Bool_Compare_Value[x * max_number_of_buttons + req];
                                break;
                            }

                            // Compare this requirement with previous requirement
                            if (req > 0)
                            {
                                switch (Logic[x * max_number_of_buttons + (req - 1)])
                                {
                                case Choice_Boolean_Logic.And:
                                    requirement_met = requirement_met && this_requirement_met;
                                    break;

                                case Choice_Boolean_Logic.Or:
                                    requirement_met = requirement_met || this_requirement_met;
                                    break;
                                }
                            }
                            else
                            {
                                requirement_met = this_requirement_met; // First requirement uses this requirement
                            }
                        }
                    }

                    // Stat requirements have been met. Display the choice
                    if (requirement_met)
                    {
                        AddListeners(x);
                    }
                    else
                    {
                        switch (Requirement_Not_Met_Actions[x])
                        {
                        case Requirement_Not_Met_Action.Disable_Button:
                            UIManager.ui_manager.choice_buttons[x].interactable = false;
                            UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = Disabled_Text[x];      // Set button text
                            break;

                        case Requirement_Not_Met_Action.Hide_Choice:
                            UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);        // Make inivisible
                            break;
                        }
                    }
                }
                else
                {
                    UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);
                }
            }

            // Disable all other buttons
            for (int x = Number_Of_Choices; x < max_number_of_buttons; x++)
            {
                UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);
            }

            if (randomize_choices_order)
            {
                RandomizeButtonOrder();
            }
        }
示例#2
0
 void Start()
 {
     StatsManager.Clear_All_Stats();
 }
示例#3
0
        // 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);
        }
示例#4
0
        // force_change means the language was changed, immediately stop animating the text and just set the text to done
        public void GetLocalizedText(bool force_change)
        {
            // Localize and/or insert stats into the title of the text box if needed
            if (!string.IsNullOrEmpty(textbox_title))
            {
                string speaker_title = "";

                if (speaker_name_from == Dialogue_Source.Text_From_Editor)
                {
                    speaker_title = textbox_title;
                }
                else if (speaker_name_from == Dialogue_Source.Localized_Text_From_CSV)
                {
                    // Get the key associated with the speaker's name
                    speaker_title = UIManager.ui_manager.Get_Localized_UI_Entry(textbox_title);
                }
                else if (speaker_name_from == Dialogue_Source.Text_From_String_Stat)
                {
                    // Is there a string stat of this name?
                    string stat_val = StatsManager.Get_String_Stat(textbox_title);

                    // Check if it's valid
                    if (string.IsNullOrEmpty(stat_val))
                    {
                        Debug.LogError("String stat " + textbox_title + " does not exist, please set the Stat before using it in a DialogueNode", this.gameObject);
                        UIManager.ui_manager.speaker_panel.text = textbox_title;
                    }
                    else
                    {
                        if (fetch_localized_stat_value)
                        {
                            stat_val = UIManager.ui_manager.Get_Localized_UI_Entry(textbox_title);
                        }
                        speaker_title = stat_val;
                    }
                }

                UIManager.ui_manager.speaker_panel.text = speaker_title;
            }



            // If using text from a CSV, grab it now
            if (dialogue_from == Dialogue_Source.Localized_Text_From_CSV)
            {
                if (string.IsNullOrEmpty(localized_key))
                {
                    Debug.LogError("Localized key is null. Please enter a key", this.gameObject);
                    return;
                }

                text = VNSceneManager.scene_manager.Get_Localized_Dialogue_Entry(this.localized_key);
                if (string.IsNullOrEmpty(text))
                {
                    Debug.LogError("Retrieved localized dialogue is null or empty. Please ensure you have entered a row with the key matching: " + this.localized_key, this.gameObject);
                }

                // If done printing, just change the text
                if (!force_change && done_printing)
                {
                    UIManager.ui_manager.text_panel.text = text;
                }

                if (force_change && !done_printing)
                {
                    Button_Pressed();
                }

                // Go through text, checking to see if we need to insert Stats values
                text = Insert_Stats_into_Text(text);

                UIManager.ui_manager.text_panel.text = text;
            }
            else
            {
                // Go through text, checking to see if we need to insert Stats values
                text = Insert_Stats_into_Text(text);
            }
        }
示例#5
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();
            }
        }