예제 #1
0
    }         //End getNextSet

    private List <Line> getNextLines(Set set)
    {
        List <Line> lines = new List <Line>();

        //If the set is a player choice set, return all lines
        if (set.speaker.Equals("PLAYER"))
        {
            for (int i = 0; i < set.setLines.Length; i++)
            {
                lines.Add(JSONHolder.getLineFromSet(i, set));
            } //End for
        }     //End if
        //If the set is a random choice set, return one line at random
        else if (set.speaker.Equals("NPC") && set.setLines.Length > 1)
        {
            currentIndex = Random.Range(0, set.setLines.Length);
            lines.Add(JSONHolder.getLineFromSet(currentIndex, set));
        }//End if
        //If the set is a sequential choice set, return the one line available
        else
        {
            currentIndex = 0;
            lines.Add(JSONHolder.getLineFromSet(0, set));
        }//End else
        foreach (Line line in lines)
        {
            GameState.updateGameState(line.lineID, "line");
        } //End foreach
        return(lines);
    }     //End getNextLine
예제 #2
0
    }     //End parseScriptFromLine

    private Set getNextSet(Conversation conversation, Set set)
    {
        //If it's the start of the conversation, get the first set
        if (set == null)
        {
            return(JSONHolder.getSetFromConversation(0, conversation));
        }//End if
        //Get specific next set pointed to by the current set
        if (set.setLines[currentIndex].nextSet != null && set.setLines[currentIndex].nextSet.Length > 0)
        {
            return(JSONHolder.getSetFromConversation(set.setLines[currentIndex].nextSet, conversation));
        }//End if
        //Move on to the next set in the array
        else
        {
            int index = System.Array.IndexOf(conversation.setIDs, set.setLines[currentIndex].nextSet);
            if (index == -1)
            {
                conversationIsOver = true;
                return(null);
            }//End else
            else
            {
                return(JSONHolder.getSetFromConversation(index, conversation));
            } //End if
        }     //End else
    }         //End getNextSet
예제 #3
0
 public void setDialogueOption(SetLine setLine)
 {
     gameObject.GetComponent <Button>().interactable = false;
     this.setLine = setLine;
     text         = gameObject.GetComponentInChildren <TextMeshProUGUI>();
     text.text    = JSONHolder.getLine(setLine.lineID).text;
 }//End Dialogue Option Setter
예제 #4
0
    }//End Player Speaking Display Getter

    #endregion

    private void Start()
    {
        //Create blank currentDialogue
        currentDialogue = null;
        //Get the player speaker data
        playerData = JSONHolder.getSpeaker("Player");
        //Get the portrait, name, and line objects from the UI
        for (int i = 0; i < convoHUDObject.transform.childCount; i++)
        {
            var child = convoHUDObject.transform.GetChild(i);
            switch (child.name)
            {
            case "NPC Dialogue Box":
                npcSpeakingDisplay = child.gameObject;
                for (int j = 0; j < npcSpeakingDisplay.transform.childCount; j++)
                {
                    var npcChild = npcSpeakingDisplay.transform.GetChild(j);
                    switch (npcChild.name)
                    {
                    case "Portrait": portraitNPCDisplay = npcChild.gameObject.GetComponent <Image>(); break;

                    case "Name": speakerNameNPCDisplay = npcChild.gameObject.GetComponent <TextMeshProUGUI>(); break;

                    case "Line": lineInBoxNPCDisplay = npcChild.gameObject.GetComponent <TextMeshProUGUI>(); break;
                    } //End switch
                }     //End for
                break;

            case "Player Choices":
                playerSpeakingDisplay = child.gameObject;
                var playerDialogueBox = playerSpeakingDisplay.transform.GetChild(0);
                for (int j = 0; j < playerDialogueBox.transform.childCount; j++)
                {
                    var playerChild = playerDialogueBox.transform.GetChild(j);
                    switch (playerChild.name)
                    {
                    case "Portrait":
                        portraitPlayerDisplay = playerChild.gameObject.GetComponent <Image>();
                        setPlayerPortrait(playerData.portrait);
                        break;

                    case "Name":
                        speakerNamePlayerDisplay = playerChild.gameObject.GetComponent <TextMeshProUGUI>();
                        setPlayerName(playerData.speakerName);
                        break;

                    case "Line":
                        lineInBoxPlayerDisplay = playerChild.gameObject.GetComponent <TextMeshProUGUI>();
                        setPlayerLineInBox("");
                        break;
                    } //End switch
                }     //End for
                break;
            }//End switch
        }//End for
        playerSpeakingDisplay.SetActive(false);
        npcSpeakingDisplay.SetActive(false);
    }//End Start
예제 #5
0
 //Get the values that will always need to be carried by the dialogue manager
 private void Start()
 {
     nextPressed        = false;
     currentIndex       = -1;
     finishedLine       = false;
     conversationIsOver = true;
     playerData         = JSONHolder.getSpeaker("Player");
     uiManager          = GameObject.FindGameObjectWithTag("HUD").GetComponent <UIManager>();
     audioSource        = GameObject.FindGameObjectWithTag("Audio Source").GetComponent <AudioSource>();
 }//End Start
예제 #6
0
    }//End startDialogue

    public void runDialogue(SetLine setLineFromDialogueChoice)
    {
        //Reset script run status
        storedLineSeenResult = false;
        finishedLine         = false;
        doneBeforeLine       = false;
        doneAfterLine        = false;
        destroyOldDialogueObjects();
        currentDialogue = gameObject.AddComponent <CurrentDialogue>();
        //Try to get the next set in the conversation
        if (setLineFromDialogueChoice == null)
        {
            set = getNextSet(conversation, set);
        }//End if
        else
        {
            set = JSONHolder.getSetFromConversation(setLineFromDialogueChoice.nextSet, conversation);
        }//End else
        //If there is no next set in the conversation, the conversation is over
        if (!conversationIsOver && set != null)
        {
            lines = getNextLines(set);
            if (set.speaker.Equals("PLAYER"))
            {
                List <SetLine> dialogueOptions = setUpDialogueOptions();
                currentDialogue.speakerIsPlayer(playerData);
                currentDialogue.setDialogueOptions(dialogueOptions);
                currentDialogue.displayDialogueOptions();
            }//End if
             //Display individual NPC line
            else if (set.speaker.Equals("NPC"))
            {
                if (lines[0].doBeforeLine != null)
                {
                    //Run a script before the line itself has run
                    runDialogueLineScript(lines[0]);
                }//End if
                //Set NPC dialogue data up
                setNPCDialogueData();
                currentDialogue.speakLine();
                StartCoroutine(WaitForLineToFinish());
            }//End else if
            else
            {
                Debug.LogError("ERROR IN SET JSON: PLAYER or NPC speaker marker in " + set.setID + " mistyped as " + set.speaker + ".");
            } //End else
        }     //End if
        else
        {
            currentDialogue.setBlipSource(null);
            PlayerInteraction playerInteraction = GameObject.FindGameObjectWithTag("Player").gameObject.GetComponentInChildren <PlayerInteraction>();
            playerInteraction.setIsInteracting(false);
        } //End else
    }     //End runDialogue
예제 #7
0
    }         //End thisOptionWasChosen

    private IEnumerator TypeLine()
    {
        displayLine = "";
        float typingSpeed;

        //For every letter in the line of text
        foreach (char letter in JSONHolder.getLine(setLine.lineID).text)
        {
            //Add a character from it to the displayed text
            displayLine += letter;
            typingSpeed  = setTypingSpeedByChar(letter);
            text.text    = displayLine;
            //Wait before adding the next one
            yield return(new WaitForSeconds(typingSpeed / 2));
        } //End foreach
        finishedTyping = true;
    }     //End Type enumerator
예제 #8
0
    }                 //End Update

    //Start a new conversation with an NPC
    public void startDialogue(GameObject npcGameObject)
    {
        currentIndex = 0;
        //Set the conversation being over variable to false
        conversationIsOver = false;
        //Get NPC speaker data
        NPCData = JSONHolder.getSpeaker(npcGameObject.GetComponent <Interactive>().getID());
        //Attach an audio source to the NPC if they don't have one already
        if (!npcGameObject.GetComponent <AudioSource>())
        {
            npcGameObject.AddComponent <AudioSource>();
        }//End if
        //Horrendous workaround
        currentDialogue = gameObject.AddComponent <CurrentDialogue>();
        currentDialogue.setBlipSource(npcGameObject.GetComponent <AudioSource>());
        DestroyImmediate(currentDialogue);
        //Find the relevant conversation
        conversation = JSONHolder.findConversation(NPCData);
        set          = null;
        lines        = new List <Line>();
        runDialogue(null);
    }//End startDialogue
예제 #9
0
    }//End Is Interacting Setter

    #endregion

    //Initialise variables on player start
    private void Start()
    {
        //Set the player to whatever is currently set as the player
        player = GameObject.FindGameObjectWithTag("Player");
        //Find camera
        playerCam = FindObjectOfType <Camera>();
        //Set the interaction range to a test value of ten
        interactRange = 1.5f;
        //Set the interaction layer to... the interaction layer
        interactLayer = LayerMask.GetMask("Interactible");
        //Set the HUD Handler to the correct object
        HUDHandler = GameObject.FindGameObjectWithTag("HUD").GetComponent <ExplorationHUD>();
        //Set player voice
        GameObject.FindGameObjectWithTag("MainCamera").GetComponentInChildren <AudioSource>().clip = JSONHolder.getSpeaker("Player").voice;
    }//End Start