Ejemplo n.º 1
0
 // display the texts in the dialogueObj on the screen
 // if there's none, delete the dialogue
 public void NextDialogue()
 {
     try
     {
         DialogueStruct dialogueObj = dialogues[curScriptIndex++];
         speechTxt.text  = dialogueObj.speech;
         speakerTxt.text = dialogueObj.speaker;
         if (dialogueObj.speaker == "Help")
         {
             profilePic.sprite = Resources.Load <Sprite>($"Profiles/question_marks");
         }
         else
         {
             profilePic.sprite = Resources.Load <Sprite>($"Profiles/{dialogueObj.speaker.ToLower()}");
         }
     }
     catch (IndexOutOfRangeException)
     {
         dialogues = null;
         Destroy(gameObject);
         OnDialogueEnds();
     }
     catch (NullReferenceException)
     {
         Destroy(gameObject);
         OnDialogueEnds();
     }
 }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        DialogueStruct diaStruct = (DialogueStruct)target;

        SerializedProperty diaStruScripts = serializedObject.FindProperty("scriptsToRun");

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(diaStruScripts, true);

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }

        //diaStruct.scriptToRun = (DialogueScript)EditorGUILayout.ObjectField("Script To Run", diaStruct.scriptToRun, typeof(DialogueScript), true);

        EditorGUILayout.HelpBox("To be able to attach scripts, the scripts MUST extend the DialogueScript class.", MessageType.Info);

        diaStruct.secondsPerCharacter = EditorGUILayout.FloatField("Seconds Per Character", diaStruct.secondsPerCharacter);

        diaStruct.responseType = (DialogueResponseType)EditorGUILayout.Popup("Response Type", (int)diaStruct.responseType, Enum.GetNames(typeof(DialogueResponseType)));

        if (diaStruct.responseType == DialogueResponseType.YES_NO)
        {
            EditorGUILayout.LabelField("Response Trees", EditorStyles.boldLabel);
            diaStruct.yesResponseTree = (DialogueTrigger)EditorGUILayout.ObjectField("Yes Response Trigger", diaStruct.yesResponseTree, typeof(DialogueTrigger), true);
            diaStruct.noResponseTree  = (DialogueTrigger)EditorGUILayout.ObjectField("No Response Trigger", diaStruct.noResponseTree, typeof(DialogueTrigger), true);
        }

        EditorGUILayout.LabelField("Sentence", EditorStyles.boldLabel);

        diaStruct.sentence = EditorGUILayout.TextArea(diaStruct.sentence);
    }
Ejemplo n.º 3
0
 private void SetCardGiven()     // set a bool so that character won't give out cards again
 {
     for (int i = 0; i < GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues.Count; i++)
     {
         foreach (int triggerID in GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i].triggerIDs)
         {
             if (triggerID == CardUsageScript.me.cardId)
             {
                 if (myApproach == Approaches.inquire)
                 {
                     DialogueStruct d = GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i];
                     d.inquiringCard_given = true;
                     GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i] = d;
                 }
                 else if (myApproach == Approaches.threaten)
                 {
                     DialogueStruct d = GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i];
                     d.threatenedCard_given = true;
                     GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i] = d;
                 }
                 else if (myApproach == Approaches.trade)
                 {
                     DialogueStruct d = GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i];
                     d.tradingCard_given = true;
                     GameManager.me.interviewee.GetComponent <CharacterScript>().dialogues[i] = d;
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 public void ShowDialogue(GameObject interviewee)     // call in update
 {
     // show default dialogue
     if (myApproach == Approaches.na)
     {
         //foreach (DialogueStruct availableChunk in interviewee.GetComponent<CharacterScript>().dialogues)
         //{
         //	if (availableChunk.triggerIDs.Count == 0 &&
         //		availableChunk.preconditions.Count == 0)
         //	{
         //		chunk = availableChunk;
         //		currentDialogue = chunk.dialogue;
         //		dDisplayer.text = chunk.dialogue[index];
         //	}
         //}
         currentDialogue = interviewee.GetComponent <CharacterScript>().defaultDialogues;
         dDisplayer.text = currentDialogue[index];
     }
     // show inquire/trade/threaten dialogue
     else
     {
         // first get all the dialogues stored in the character
         foreach (DialogueStruct availableChunk in interviewee.GetComponent <CharacterScript>().dialogues)
         {
             // get all the trigger ids in all the dialogues
             foreach (int triggerID in availableChunk.triggerIDs)
             {
                 // if the trigger id matches the card in use
                 if (triggerID == CardUsageScript.me.cardId)
                 {
                     // show different text based on different approaches
                     if (myApproach == Approaches.inquire)
                     {
                         chunk           = availableChunk;
                         dDisplayer.text = chunk.dialogue_inquiring[index];
                         currentDialogue = chunk.dialogue_inquiring;
                         ProcessCard();
                     }
                     else if (myApproach == Approaches.trade)
                     {
                         chunk           = availableChunk;
                         dDisplayer.text = chunk.dialogue_trading[index];
                         currentDialogue = chunk.dialogue_trading;
                         ProcessCard();
                     }
                     else if (myApproach == Approaches.threaten)
                     {
                         chunk           = availableChunk;
                         dDisplayer.text = chunk.dialogue_threatened[index];
                         currentDialogue = chunk.dialogue_threatened;
                         ProcessCard();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
    //=-------------------------------------------------------=


    public static DialogueStruct[] getDialogueFromString(string val)
    {
        string[] lines = WholeLineToSepereateLines(val);

        DialogueStruct[] result = new DialogueStruct[lines.Length];
        for (int i = 0; i < result.Length; i++)
        {
            result[i] = new DialogueStruct(Ober, lines[i], false);
        }
        return(result);
    }
Ejemplo n.º 6
0
 // display the texts in the dialogueObj on the screen
 // if there's none, delete the dialogue
 // returns true if there are
 /// <summary>
 /// Get the next dialogue. If there's no more, destroy
 /// the dialogue UI object.
 /// </summary>
 /// <returns>
 /// true if there is a next dialogue. Else false.
 /// </returns>
 public bool NextDialogue()
 {
     try
     {
         DialogueStruct dialogueObj = dialogues[curScriptIndex++];
         speechTxt.text  = dialogueObj.speech;
         speakerTxt.text = dialogueObj.speaker;
         if (dialogueObj.speaker == "Help")
         {
             profilePic.sprite = Resources.Load <Sprite>($"CharacterPic/question_marks");
         }
         else
         {
             profilePic.sprite = Resources.Load <Sprite>($"CharacterPic/{dialogueObj.speaker.ToLower()}");
         }
     }
     catch (IndexOutOfRangeException)
     {
         Destroy(gameObject);
         DialogueEnded?.Invoke(this, args);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 7
0
    public void DisplayNextSentence()
    {
        if (continueButton != null)
        {
            continueButton.gameObject.SetActive(false);
        }
        else
        {
            Debug.LogError("[DialogueManager] You have not assigned the continue button to the dialogue manager!");
        }

        if (yesButton != null)
        {
            yesButton.gameObject.SetActive(false);
        }
        else
        {
            Debug.LogError("[DialogueManager] You have not assigned the yes button to the dialogue manager!");
        }

        if (noButton != null)
        {
            noButton.gameObject.SetActive(false);
        }
        else
        {
            Debug.LogError("[DialogueManager] You have not assigned the no button to the dialogue manager!");
        }

        if (currentDialogueStruct != null)
        {
            if (currentDialogueStruct.scriptsToRun != null)
            {
                if (!endOfSentence)
                {
                    for (int i = 0; i < currentDialogueStruct.scriptsToRun.Length; i++)
                    {
                        if (currentDialogueStruct.scriptsToRun[i] != null)
                        {
                            currentDialogueStruct.scriptsToRun[i].OnFinish();
                        }
                        else
                        {
                            Debug.LogError("[DialogueManager] [Scripts] Element " + i + " of current dialogue is null!");
                        }
                    }
                }

                for (int i = 0; i < currentDialogueStruct.scriptsToRun.Length; i++)
                {
                    if (currentDialogueStruct.scriptsToRun[i] != null)
                    {
                        currentDialogueStruct.scriptsToRun[i].OnEndOfStruct();
                    }
                    else
                    {
                        Debug.LogError("[DialogueManager] [Scripts] Element " + i + " of current dialogue is null!");
                    }
                }
            }

            if (currentDialogueStruct.typingSoundScript != null)
            {
                if (!endOfSentence)
                {
                    currentDialogueStruct.typingSoundScript.OnFinish();
                }

                currentDialogueStruct.typingSoundScript.OnEndOfStruct();
            }
            else
            {
                Debug.LogError("[DialogueManager] Typing sound script is null for the current dialogue! Text: " + currentDialogueStruct.sentence);
            }
        }

        if (dStructQueue.Count == 0)
        {
            EndDialogue();
            return;
        }

        currentDialogueStruct = dStructQueue.Dequeue();

        if (currentDialogueStruct == null)
        {
            Debug.LogError("[DialogueManager] You have not assigned a dialogue struct!");
            return;
        }

        secondsPerCharacter = currentDialogueStruct.secondsPerCharacter;

        string sentence = currentDialogueStruct.sentence;

        StopAllCoroutines();
        StartCoroutine(TypeSentence(sentence));

        if (currentDialogueStruct.responseType == DialogueResponseType.CONTINUE)
        {
            if (continueButton != null)
            {
                continueButton.gameObject.SetActive(true);
            }
            else
            {
                Debug.LogError("[DialogueManager] You have not assigned the continue button to the dialogue manager!");
            }
        }
        else if (currentDialogueStruct.responseType == DialogueResponseType.YES_NO)
        {
            if (yesButton != null)
            {
                yesButton.gameObject.SetActive(true);
            }
            else
            {
                Debug.LogError("[DialogueManager] You have not assigned the yes button to the dialogue manager!");
            }

            if (noButton != null)
            {
                noButton.gameObject.SetActive(true);
            }
            else
            {
                Debug.LogError("[DialogueManager] You have not assigned the no button to the dialogue manager!");
            }
        }
    }