コード例 #1
0
 /// <summary>
 /// Starts the dialogue between the player and an open world character by setting various references
 /// specific to the context.
 /// </summary>
 /// <param name="speakerPos">Speaker position.</param>
 /// <param name="dialogueChain">Dialogue chain.</param>
 /// <param name="offset">Offset.</param>
 /// <param name="currSpeaker">Curr speaker.</param>
 public void StartDialogue(Transform speakerPos, DialogueChain dialogueChain, Vector2 offset, CharacterDialogMgr currSpeaker)
 {
     //Get a reference to the current speaker
     this.speaker = currSpeaker;
     //Get reference to cuurent dialogue chain - string of text and objects for decision making
     currDialogueChain = dialogueChain;
     //Create UI elements
     currTextBox = CreateSpeechBubble(speakerPos, dialogueChain, offset, ref currText);
 }
コード例 #2
0
    /// <summary>
    /// Creates the speech bubble.
    /// </summary>
    /// <returns>The speech bubble.</returns>
    /// <param name="speakerPos">Speaker position.</param>
    /// <param name="dialogue">Dialogue.</param>
    /// <param name="offset">Offset.</param>
    /// <param name="displayText">Display text.</param>
    public GameObject CreateSpeechBubble(Transform speakerPos, DialogueChain dialogue, Vector2 offset, ref GameObject displayText)
    {
        Debug.Log("CreateSpeechBubble called.");
        //Canvas canvas;
        GameObject tBox = (GameObject)GameObject.Instantiate(charTextBox);

        tBox.transform.SetParent(_uiContainer.transform, false);
        //Get reference to response box and its script then disable it for now
        rBox = tBox.transform.Find("ResponseBox").gameObject;
        currResponseScript = tBox.GetComponentInChildren <ResponseBoxScript>();
        rBox.SetActive(false);

        //Rect transform for UI element
        RectTransform uiBoxRect = tBox.GetComponent <RectTransform>();

        //Get RectTransform for canvas
        RectTransform CanvasRect = CanvasObject.GetComponent <RectTransform>();

        //Calculate position for the UI Element - 0,0 for the canvas is at the cneter of the screen, whereas World to viewPortPoint
        //treats the lower left as 0,0.  Because of this, you need to subrat the height/width of the canvas * 0.5 to get the correct pos

        Vector2 viewportPosition = Camera.main.WorldToViewportPoint(speakerPos.position);
        Vector2 speakerScreenPos = new Vector2(
            ((viewportPosition.x * CanvasRect.sizeDelta.x) - (CanvasRect.sizeDelta.x * 0.5f)),
            ((viewportPosition.y * CanvasRect.sizeDelta.y) - (CanvasRect.sizeDelta.y * 0.5f)));

        /*position over desired character. Y offset needs to be double as sprite's origin pos is at its center*/
        Vector2 uiObjPos = new Vector2(speakerScreenPos.x, speakerScreenPos.y + (offset.y * 2f));

        uiBoxRect.anchoredPosition = uiObjPos;

        /*Create Text*/
        displayText = (GameObject)GameObject.Instantiate(uiText);
        displayText.transform.SetParent(_uiContainer.transform, false);
        /*Set text position*/
        RectTransform textRect = displayText.GetComponent <RectTransform>();

        /*Zero it within parent*/
        textRect.anchoredPosition = uiObjPos;

        /*Set flag to display string arguments*/
        DialogueActive = true;
        StartCoroutine(PopulateText(dialogue));

        /*Return ui text box*/
        return(tBox);
    }
コード例 #3
0
 public override void Action(DialogueChain chain)
 {
     if (Initialize(chain))
     {
         _index = 0;
         chain.data[_index].pre_execution_event.Invoke();
         StartCoroutine(First.Type(_GUITextFirst));
         if (Second != null)
         {
             StartCoroutine(Second.Type(_GUITextSecond));
         }
         if (Third != null)
         {
             StartCoroutine(Third.Type(_GUITextThird));
         }
     }
 }
コード例 #4
0
    public override bool Initialize(DialogueChain data)
    {
        if (data)
        {
            CharacterController2D.block_input = true;

            chain        = data;
            _GUIText     = GetComponent <Text>();
            _initialized = true;
            return(true);
        }
        else
        {
            print("CHAIN DATA IS NULL" +
                  ": ");
            return(false);
        }
    }
コード例 #5
0
    public override bool Initialize(DialogueChain data)
    {
        if (data.data.Count < 1)
        {
            return(false);
        }
        First = data.data[0];

        if (data.data.Count > 1)
        {
            Second = data.data[1];
        }
        if (data.data.Count > 2)
        {
            Third = data.data[2];
        }

        DialogueRef = GameObject.Find("SelectionTexts");
        DialogueRef.SetActive(true);
        try
        {
            _GUITextFirst       = (Text)DialogueRef.GetComponent <RefHandler>().handler[0];
            _GUITextSecond      = (Text)DialogueRef.GetComponent <RefHandler>().handler[1];
            _GUITextThird       = (Text)DialogueRef.GetComponent <RefHandler>().handler[2];
            _GUITextFirst.text  = "";
            _GUITextSecond.text = "";
            _GUITextThird.text  = "";
            _actionPressed      = 0;
            CharacterController2D.block_input = true;

            _initialized = true;
            return(true);
        }
        catch (Exception e)
        {
            print("DIALOGUE SELECTION COMPONENT NOT FOUND: " + e.ToString());
            return(false);
        }
    }
コード例 #6
0
 public void SetDialogueChain(DialogueChain c)
 {
     handler[0] = c;
 }
コード例 #7
0
    private void PopulateDialogue()
    {
        //parse all dialogue  and create a list of dialogue chains(a dialogue chain is a group of related dialogue sets)
        List <DialogueChain> dSets = new List <DialogueChain>();
        string dialogue            = System.IO.File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "Dialogue.json"));

        DialogueSet[] allDialogue = JsonHelper.getJsonArray <DialogueSet>(dialogue);
        foreach (DialogueSet d in allDialogue)
        {
            bool found = false;
            foreach (DialogueChain dc in dSets)
            {
                if (dc.chainID == d.id / 10)
                {
                    dc.members.Add(d.id);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                DialogueChain nDChain = new DialogueChain();
                nDChain.chainID = d.id / 10;
                nDChain.members = new List <int>();
                nDChain.members.Add(d.id);
                dSets.Add(nDChain);
            }
        }
        dSets.RemoveAt(0);//removes intro scene from list of dialogues


        //now we generate a list of narrativecore nodes
        List <GameObject> NCNodes = new List <GameObject>();

        foreach (GameObject Node in gameObject.GetComponent <MapProperties>().Nodes)
        {
            if (Node.GetComponent <NodeProperties>().NodeEvent == NodeProperties.EventType.NARRATIVECORE)
            {
                NCNodes.Add(Node);
            }
        }

        //with the list of narrative core nodes, assign each NCNode a dialogue chain until we run out of nodes or dialogue
        foreach (GameObject Node in NCNodes)
        {
            if (dSets.Count == 0)
            {
                return;//if we no longer have any unassigned dialogue left, we are done
            }
            Node.GetComponent <NodeProperties>().chainID = dSets[0].chainID;
            Node.GetComponent <NodeProperties>().dialogueSet.AddRange(dSets[0].members);
            Node.GetComponent <NodeProperties>().SetColor();
            dSets.RemoveAt(0);
        }

        //now we generate a list of side narrative nodes
        List <GameObject> SNNodes = new List <GameObject>();

        foreach (GameObject Node in gameObject.GetComponent <MapProperties>().Nodes)
        {
            if (Node.GetComponent <NodeProperties>().NodeEvent == NodeProperties.EventType.NARRATIVE)
            {
                SNNodes.Add(Node);
            }
        }

        //with the list of side narrative, assign each NCNode a dialogue chain until we run out of nodes or dialogue
        foreach (GameObject Node in SNNodes)
        {
            if (dSets.Count == 0)
            {
                return;//if we no longer have any unassigned dialogue left, we are done
            }
            Node.GetComponent <NodeProperties>().chainID = dSets[0].chainID;
            Node.GetComponent <NodeProperties>().dialogueSet.AddRange(dSets[0].members);
            Node.GetComponent <NodeProperties>().SetColor();
            dSets.RemoveAt(0);
        }
    }
コード例 #8
0
ファイル: DialogueBase.cs プロジェクト: llorensri/Marmelade
 public virtual void Action(DialogueChain chain)
 {
 }
コード例 #9
0
ファイル: DialogueBase.cs プロジェクト: llorensri/Marmelade
 public virtual bool Initialize(DialogueChain chain)
 {
     print("I should not be executing!"); return(false);
 }
コード例 #10
0
//    public void PopulateText()
//    {
//        DialogueChain dialogue = currDialogueChain;
//        /*Create object to pass to text coroutine*/
//        SpeechText sText = new SpeechText(dialogue.SpeechText[CurrDialogueIndex].Text, currText);
//
//        int count = 0;
//        //TODO: Add text population word by word with overflow detect
//        foreach (string s in sText.Text)
//        {
//            count++;
//
//            for (int i = 0; i < s.Length; i++)
//            {
//                if (CheckTextOverflowHeight(sText.UIText.GetComponent<RectTransform>()))
//                {
//                    Debug.Log("Text overflowed height!");
//                    yield return null;
//                }
//                else
//                {
//                    sText.UIText.GetComponent<Text>().text += s.Substring(i, 1);
//                    yield return(new WaitForSeconds(_textDelayTime));
//                }
//
//            }
//
//
//
//            if (count < sText.Text.Length)
//            {
//                Debug.Log("Waiting for player input");
//
//                //Check for if this requires responses
//                if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ReqResponse && !rBox.activeInHierarchy)
//                {
//                    Debug.Log("Response required detected!!");
//                    Debug.Log("Dialogue text at 0 is: "+ currDialogueChain.SpeechText[0].Text[0]);
//                    rBox.SetActive(true);
//
//                    currResponseScript.CreateResponses(currDialogueChain.SpeechText[this.CurrDialogueIndex].Responses);
//                    //Initialize references for UI elements for dialogue responses
//                    currResponseScript.Init();
//                    //Set flag to wait for response
//                    this.DialogueChoice = true;
//                }
//                //flag to wait for player input
//                _waitForPlayer = true;
//
//                //Turn on continue arrow
//                sText.UIText.GetComponent<TextBoxScript>().SwitchArrow();
//                /*String finished populating, now we wait for player's input to continue*/
//                while (_waitForPlayer)
//                {
//                    yield return null;
//                }
//                //turn off continue arrow that is parented to the UI text object
//                sText.UIText.transform.GetComponent<TextBoxScript>().SwitchArrow();
//                //Clear previous string from text box
//                sText.UIText.GetComponent<Text>().text = "";
//            }
//            else
//            {
//                Debug.Log("End of dialog reached. Waiting for player to close.");
//                //do nothing
//                _waitForPlayer = true;
//
//                while (_waitForPlayer)
//                {
//                    yield return null;
//                }
//                //Check to see if there is a new dialog chain to display
//                if (newDialogueChain)
//                {
//                    newDialogueChain = false;
//                }
//                else
//                {
//                    //if no new dialogue chain then End of dialog reached so close text box
//                    CloseTextBox();
//                }
//            }
//        }
//
//
//    }

    IEnumerator PopulateText(DialogueChain dialogue)
    {
        while (DialogueActive)
        {
            Debug.Log("Top of while loop");
            /*Create object to pass to text coroutine*/
            SpeechText sText = new SpeechText(dialogue.SpeechText[CurrDialogueIndex].Text, currText);
            /*set reference variable for debug*/
            currDialogueChain = dialogue;


            //TODO: Add text population word by word with overflow detect
            for (int count = 0; count <= sText.Text.Length; count++)
            {
                if (count < sText.Text.Length)
                {
                    for (int i = 0; i < sText.Text[count].Length; i++)
                    {
                        if (CheckTextOverflowHeight(sText.UIText.GetComponent <RectTransform>()))
                        {
                            Debug.Log("Text overflowed height!");
                            yield return(null);
                        }
                        else
                        {
                            sText.UIText.GetComponent <Text>().text += sText.Text[count].Substring(i, 1);
                            yield return(new WaitForSeconds(_textDelayTime));
                        }
                    }

                    Debug.Log("Waiting for player input");
                    Debug.Log("--Count is:" + count + "---");
                    Debug.Log("SText.Text.Length is:" + sText.Text.Length);
                    //Check if the character gives the player an item
                    if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ItemIndex != -1)
                    {
                        int index = currDialogueChain.SpeechText[this.CurrDialogueIndex].ItemIndex;
                        //Call player state manager to add item
                        PlayerStateManager.Instance.AddToInventory(speaker.dialogueEventItems[index], true);
                        //Create notification
                        GameObject notif = (GameObject)GameObject.Instantiate(notifBox);
                        //Set parent to ui_container because the object is a ui elemetn
                        notif.transform.SetParent(_uiContainer.transform, false);
                        //position notification and set reference elements as part of initialization
                        notif.GetComponent <NotificationScript>().Init(speaker.dialogueEventItems[index].thisItem.PickupText, PlayerStateManager.Instance.LocalPosition);
                        //Trigger fade out
                        notif.GetComponent <NotificationScript>().StartFadeOut();
                    }
                    //Check for if this requires responses
                    if (currDialogueChain.SpeechText[this.CurrDialogueIndex].ReqResponse && !rBox.activeInHierarchy)
                    {
//                        Debug.Log("Response required detected!!");
//                        Debug.Log("Dialogue text at 0 is: " + currDialogueChain.SpeechText[0].Text[0]);
                        rBox.SetActive(true);

                        currResponseScript.CreateResponses(currDialogueChain.SpeechText[this.CurrDialogueIndex].Responses);
                        //Initialize references for UI elements for dialogue responses
                        currResponseScript.Init();
                        //Set flag to wait for response
                        this.DialogueChoice = true;
                    }
                    //flag to wait for player input
                    _waitForPlayer = true;

                    //Turn on continue arrow
                    sText.UIText.GetComponent <TextBoxScript>().SwitchArrow();
                    /*String finished populating, now we wait for player's input to continue*/
                    while (_waitForPlayer)
                    {
                        yield return(null);
                    }
                    //turn off continue arrow that is parented to the UI text object
                    sText.UIText.transform.GetComponent <TextBoxScript>().SwitchArrow();
                    //Clear previous string from text box
                    sText.UIText.GetComponent <Text>().text = "";
                }
                else
                {
//                    Debug.Log("End of dialog reached. Waiting for player to close.");
//                    //do nothing
//                    _waitForPlayer = true;
//
//                    while (_waitForPlayer)
//                    {
//                        yield return null;
//                    }

                    if (newDialogueChain)
                    {
                        Debug.Log("New dialog chain created!");
                        this.CurrDialogueIndex = this.newDialogueIndex;
                    }
                    else
                    {
                        //Update the Dialogue Manager's state
                        this.DialogueActive = false;
                        //End of dialog reached so close text box
                        CloseTextBox();
                    }
                }
            }
        }
    }
コード例 #11
0
 public void SetThird(DialogueChain c)
 {
     Third = c;
 }
コード例 #12
0
 public void SetSecond(DialogueChain b)
 {
     Second = b;
 }
コード例 #13
0
 public void SefFirst(DialogueChain a)
 {
     First = a;
 }
コード例 #14
0
 public void setData(DialogueChain data, DialogueChain data1, DialogueChain data2)
 {
     First  = data;
     Second = data1;
     Third  = data2;
 }