Exemplo n.º 1
0
    void Update()
    {
        //check if we have the mouse over the character
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        //make sure we left click and is on a NPC
        if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
        {
            //only return NPC
            if (hit.transform == this.transform)
            {
                //check the bubble on the character and make it appear!
                if (vBubble.Count > 0 && vConversation != null && !vConversation.GetComponent <Conversation>().isAuto)
                {
                    ShowBubble(hit.transform.GetComponent <DialogBubble> ());
                }
            }
        }

        //can't have a current character
        if (!IsTalking)
        {
            vActiveBubble = null;
        }
    }
Exemplo n.º 2
0
    private string ModifyTextFromComponentByAddindNewLineAfterWords(PixelBubble pixelBubble)
    {
        //cut the message into 24 characters
        string trueMessage = "";
        string line        = "";
        int    limit       = 20;

        if (pixelBubble.messageForm == BubbleType.Round)
        {
            limit = 15;
        }

        //cut each word in a text in 24 characters.
        foreach (string word in pixelBubble.message.Split(' '))
        {
            if (line.Length + word.Length > limit)
            {
                trueMessage += line + System.Environment.NewLine;

                line = "";           //add a line break after   //then reset the current line
            }
            line += word + " ";      //add the current word with a space
        }
        trueMessage += line;         //add the last line

        return(trueMessage);
    }
Exemplo n.º 3
0
    private GameObject InstantiateBubble(PixelBubble bubblesList, DialogBubble dialogBubble)
    {
        GameObject newBubbleDialogObject = null;

        //create a rectangle or round bubble
        if (bubblesList.messageForm == BubbleType.Rectangle)
        {
            newBubbleDialogObject = (GameObject)Instantiate(prefab, dialogBubble.transform.position + new Vector3(4f, 4.25f, 0f)
                                                            , Quaternion.identity);
        }
        else
        {
            newBubbleDialogObject = (GameObject)Instantiate(prefab2, dialogBubble.transform.position + new Vector3(0.25f, 4.5f, 0f)
                                                            , Quaternion.identity);
        }

        return(newBubbleDialogObject);
    }
Exemplo n.º 4
0
    private void RenderBodyOfBubble(GameObject pixelBubbleObject, PixelBubble pixelBubble, string trueMessage)
    {
        Color newBodyColor   = new Color(pixelBubble.bodyColor.r, pixelBubble.bodyColor.g, pixelBubble.bodyColor.b, 255f);
        Color newBorderColor = new Color(pixelBubble.borderColor.r, pixelBubble.borderColor.g, pixelBubble.borderColor.b, 255f);
        Color newFontColor   = new Color(pixelBubble.fontColor.r, pixelBubble.fontColor.g, pixelBubble.fontColor.b, 255f);

        //get all image below the main Object
        foreach (Transform child in pixelBubbleObject.transform)
        {
            SpriteRenderer spriteRenderer = child.GetComponent <SpriteRenderer> ();
            TextMesh       textMesh       = child.GetComponent <TextMesh> ();

            if (spriteRenderer != null && child.name.Contains("Body"))
            {
                spriteRenderer.color = newBodyColor;                 //change the body color
            }
            else if (spriteRenderer != null && child.name.Contains("Border"))
            {
                spriteRenderer.color = newBorderColor;                  //change the border color
            }
            else if (textMesh != null && child.name.Contains("Message"))
            {
                //change the message and show it in front of everything
                textMesh.color = newFontColor;
                textMesh.text  = trueMessage;

                Transform mouseIcon = child.FindChild("MouseIcon");
                if (mouseIcon != null && !pixelBubble.clickToCloseBubble)
                {
                    mouseIcon.gameObject.SetActive(false);
                }
            }

            //disable the mouse icon because it will close by itself
            if (child.name == "MouseIcon" && !pixelBubble.clickToCloseBubble)
            {
                child.gameObject.SetActive(false);
            }
            else
            {
                activeBubble = pixelBubble;                 //keep the active bubble and wait for the Left Click
            }
        }
    }
Exemplo n.º 5
0
    //show the right bubble on the current character
    public void ShowBubble(DialogBubble vcharacter)
    {
        bool gotonextbubble = false;

        //if vcurrentbubble is still there, just close it
        if (vActiveBubble != null)
        {
            if (vActiveBubble.vClickToCloseBubble)
            {
                //get the function to close bubble
                Appear vAppear = vcharacter.vCurrentBubble.GetComponent <Appear> ();
                vAppear.valpha  = 0f;
                vAppear.vTimer  = 0f;                //instantly
                vAppear.vchoice = false;             //close bubble

                //check if last bubble
                if (vActiveBubble == vcharacter.vBubble.Last())
                {
                    vcharacter.IsTalking = false;
                }
            }
        }

        foreach (PixelBubble vBubble in vcharacter.vBubble)
        {
            //make sure the bubble isn't already opened
            if (vcharacter.vCurrentBubble == null)
            {
                //make the character in talking status
                vcharacter.IsTalking = true;

                //cut the message into 24 characters
                string vTrueMessage = "";
                string cLine        = "";
                int    vLimit       = 35;
                if (vBubble.vMessageForm == BubbleType.Round)
                {
                    vLimit = 30;
                }

                //cut each word in a text in 24 characters.
                foreach (string vWord in vBubble.vMessage.Split(' '))
                {
                    if (cLine.Length + vWord.Length > vLimit)
                    {
                        vTrueMessage += cLine + System.Environment.NewLine;

                        //add a line break after
                        cLine = "";                         //then reset the current line
                    }

                    //add the current word with a space
                    cLine += vWord + " ";
                }

                //add the last word
                vTrueMessage += cLine;
                GameObject vBubbleObject = null;

                Vector3 shift = new Vector3(0, 0, 0);

                //create a rectangle or round bubble
                if (vBubble.vMessageForm == BubbleType.Rectangle)
                {
                    //create bubble
                    vBubbleObject = Instantiate(Resources.Load <GameObject> ("Customs/BubbleRectangle"));
                    shift         = new Vector3(1f, 3.1f, 0f);
                }
                else
                {
                    //create bubble
                    vBubbleObject = Instantiate(Resources.Load <GameObject> ("Customs/BubbleRound"));
                    shift         = new Vector3(1f, 2.9f, 0f);
                }

                if (vCustomBubblePosition == true)
                {
                    shift = vBubblePosition;
                }

                vBubbleObject.transform.position   = vcharacter.transform.position + shift;               //move a little bit the teleport particle effect
                vBubbleObject.transform.localScale = new Vector3(1f, 1f, 1f);

                //show the mouse and wait for the user to left click OR NOT (if not, after 10 sec, it disappear)
                vBubbleObject.GetComponent <Appear>().needtoclick = vBubble.vClickToCloseBubble;

                Color vNewBodyColor   = new Color(vBubble.vBodyColor.r, vBubble.vBodyColor.g, vBubble.vBodyColor.b, 0f);
                Color vNewBorderColor = new Color(vBubble.vBorderColor.r, vBubble.vBorderColor.g, vBubble.vBorderColor.b, 0f);
                Color vNewFontColor   = new Color(vBubble.vFontColor.r, vBubble.vFontColor.g, vBubble.vFontColor.b, 255f);

                //get all image below the main Object
                foreach (Transform child in vBubbleObject.transform)
                {
                    SpriteRenderer vRenderer = child.GetComponent <SpriteRenderer> ();
                    TextMesh       vTextMesh = child.GetComponent <TextMesh> ();

                    if (vRenderer != null && child.name.Contains("Body"))
                    {
                        //change the body color
                        vRenderer.color = vNewBodyColor;

                        if (vRenderer.sortingOrder < 10)
                        {
                            vRenderer.sortingOrder = 1500;
                        }
                    }
                    else if (vRenderer != null && child.name.Contains("Border"))
                    {
                        //change the border color
                        vRenderer.color = vNewBorderColor;
                        if (vRenderer.sortingOrder < 10)
                        {
                            vRenderer.sortingOrder = 1501;
                        }
                    }
                    else if (vTextMesh != null && child.name.Contains("Message"))
                    {
                        //change the message and show it in front of everything
                        vTextMesh.color = vNewFontColor;
                        vTextMesh.text  = vTrueMessage;
                        child.GetComponent <MeshRenderer>().sortingOrder = 1550;

                        Transform vMouseIcon = child.FindChild("MouseIcon");
                        if (vMouseIcon != null && !vBubble.vClickToCloseBubble)
                        {
                            vMouseIcon.gameObject.SetActive(false);
                        }
                    }

                    if (vBubbleOnRight == false && (child.name.Equals("BaseBody") || child.name.Equals("BaseBorder")))
                    {
                        child.transform.Rotate(Vector3.up * 180);
                    }

                    //disable the mouse icon because it will close by itself
                    if (child.name == "MouseIcon" && !vBubble.vClickToCloseBubble)
                    {
                        child.gameObject.SetActive(false);
                    }
                    else
                    {
                        vActiveBubble = vBubble;                          //keep the active bubble and wait for the Left Click
                    }
                }

                vcharacter.vCurrentBubble      = vBubbleObject;            //attach it to the player
                vBubbleObject.transform.parent = vcharacter.transform;     //make him his parent
            }
            else if (vActiveBubble == vBubble && vActiveBubble.vClickToCloseBubble)
            {
                gotonextbubble            = true;
                vcharacter.vCurrentBubble = null;
            }
        }
    }