Exemple #1
0
 public void ChangePopupText(TextPromptSO textObject)
 {
     if (!showingText)
     {
         string[] editedText = new string[textObject.dialogueText.Length];
         for (int i = 0; i < textObject.dialogueText.Length; i++)
         {
             editedText[i] = textObject.dialogueText[i].Replace("*", "\n");
         }
         textObject.dialogueText = editedText;
         StartCoroutine(UITextPopup(textObject));
     }
 }
Exemple #2
0
    IEnumerator UITextPopup(TextPromptSO textObject)
    {
        //Tell other classes that a text prompt is actively being handled


        //Make sure response box is hidden
        responseBox.GetComponent <SpriteRenderer>().enabled = false;
        foreach (GameObject responseObject in responseText)
        {
            responseObject.GetComponent <TextMesh>().text         = "";
            responseObject.GetComponent <BoxCollider2D>().enabled = false;
        }

        //Loop through each line of the popup text
        for (int i = 0; i < textObject.dialogueText.Length; i++)
        {
            textDisplay.text = textObject.dialogueText[i];
            if (i < textObject.dialogueText.Length - 1)
            {
                continueArrow.GetComponent <SpriteRenderer>().enabled = true;
                yield return(new WaitForEndOfFrame());

                showingText  = true;
                textContinue = false;
                while (!textContinue)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }
        }
        continueArrow.GetComponent <SpriteRenderer>().enabled = false;

        //If there is a response to this text show the options and wait for a response
        if (textObject.hasResponse)
        {
            responseBox.GetComponent <SpriteRenderer>().enabled = true;
            for (int i = 0; i < textObject.responseObjects.Length; i++)
            {
                responseText[i].GetComponent <TextMesh>().text         = "- " + textObject.responseObjects[i].responseLabel;
                responseText[i].GetComponent <ShowText>().textPromptSO = textObject.responseObjects[i];
                responseText[i].GetComponent <BoxCollider2D>().enabled = true;
            }
            awaitingResponse = true;
        }

        //Finish off the coroutine
        showingText = false;
    }
Exemple #3
0
    //Public function to allow inventory object to be cleared
    public void ClearInventoryObject()
    {
        //Clear variables
        inventorySprite            = null;
        inventorySpriteHighlighted = null;
        inventoryObjectName        = null;
        inventoryTextPrompt        = null;

        //Update sprite renderer
        sr.sprite = null;

        //Set highlight sprite script variables
        highlightSprite.normalSprite      = null;
        highlightSprite.highlightedSprite = null;

        //Set show text script variables
        showText.textPromptSO = null;
    }
Exemple #4
0
    //Override for SetInventoryObject that allows InventoryObject to be used as input rather than individual components, mostly used by InventoryManager when shifting objects around
    public void SetInventoryObject(InventoryObject inventoryObject)
    {
        //Set variables
        inventorySprite            = inventoryObject.inventorySprite;
        inventorySpriteHighlighted = inventoryObject.inventorySpriteHighlighted;
        inventoryObjectName        = inventoryObject.inventoryObjectName;
        inventoryTextPrompt        = inventoryObject.inventoryTextPrompt;

        //Update sprite renderer
        sr.sprite = inventorySprite;

        //Set highlight sprite script variables
        highlightSprite.normalSprite      = inventorySprite;
        highlightSprite.highlightedSprite = inventorySpriteHighlighted;

        //Set show text script variables
        showText.textPromptSO = inventoryTextPrompt;
    }
Exemple #5
0
    //Public function used to set the variables for this InventoryObject and update the relevant components
    public void SetInventoryObject(Sprite inventorySprite, Sprite inventorySpriteHighlighted, string inventoryObjectName, TextPromptSO inventoryTextPrompt)
    {
        //Set variables
        this.inventorySprite            = inventorySprite;
        this.inventorySpriteHighlighted = inventorySpriteHighlighted;
        this.inventoryObjectName        = inventoryObjectName;
        this.inventoryTextPrompt        = inventoryTextPrompt;

        //Update sprite renderer
        sr.sprite = inventorySprite;

        //Set highlight sprite script variables
        highlightSprite.normalSprite      = inventorySprite;
        highlightSprite.highlightedSprite = inventorySpriteHighlighted;

        //Set show text script variables
        showText.textPromptSO = inventoryTextPrompt;
    }
    void ShowPopupText(TextPromptSO textPromptSO)
    {
        Manager <UIManager> .Instance.ChangePopupText(textPromptSO);

        //Check if this text option sets a Game Data Key
        if (textPromptSO.gameDataUpdate)
        {
            SetGameDataValue(textPromptSO.updateGameDataKey, textPromptSO.updateGameDataValue);
        }

        //Check if this text prompt adds item to inventory
        if (textPromptSO.addToInventory)
        {
            Manager <InventoryManager> .Instance.AddNewInventoryObject(textPromptSO.inventorySprite, textPromptSO.inventorySpriteHighlighted, textPromptSO.inventoryObjectAddName, textPromptSO.inventoryTextPrompt);
        }

        //Check if this text prompt removes item from inventory
        if (textPromptSO.removeFromInventory)
        {
            Manager <InventoryManager> .Instance.RemoveInventoryObjectByName(textPromptSO.inventoryObjectRemoveName);
        }

        //Check if text prompt triggers object to be swapped out
        if (textPromptSO.changeObject)
        {
            GameObject objectToDelete  = GameObject.Find(textPromptSO.oldObjectName);
            Transform  oldObjectParent = objectToDelete.transform.parent;
            Instantiate(textPromptSO.newObject, oldObjectParent);
            Destroy(objectToDelete);
        }

        //Check if this text prompt enables a popup window
        if (textPromptSO.openPopup)
        {
            GameObject popupObjectHolder = GameObject.Find(textPromptSO.popupObjectName + " Holder");
            GameObject popupObject       = popupObjectHolder.transform.GetChild(0).gameObject;
            popupObject.SetActive(true);
        }

        //Check if this text prompt spwans an object
        if (textPromptSO.spawnObject)
        {
            Instantiate(textPromptSO.spawnedObject, textPromptSO.spawnTransform);
        }

        //Check if this text prompt increases lawyer level
        if (textPromptSO.increaseLawyerLevel)
        {
            IncrementLawyerLevel();
        }

        //Check if this text prompt triggers an animation
        if (textPromptSO.triggerAnimation)
        {
            Animator animatorObject = GameObject.Find(textPromptSO.triggerAnimatorName).GetComponent <Animator>();
            if (animatorObject != null)
            {
                animatorObject.SetTrigger(textPromptSO.triggerString);
            }
            else
            {
                Debug.LogFormat("{0} is not a valid animator name!", textPromptSO.triggerAnimatorName);
            }
        }

        //Check if this text prompt triggers a sound effect
        if (textPromptSO.playSound)
        {
            Manager <SoundManager> .Instance.PlaySoundEffect(textPromptSO.soundEffect);
        }

        //Check if this text prompt triggers scene change
        if (textPromptSO.sceneTransition)
        {
            Debug.LogFormat("Transition to scene {0}", textPromptSO.sceneIndex);
            //No extra scenes because just the tutorial scene made so trigger animation for "To Be Continued"
            toBeContinuedAnim.SetTrigger("EndTutorial");
        }

        //Any other checks should be done before the delete check is done in case the object to be deleted is the one holding the text prompt

        //Check if item should be deleted
        if (textPromptSO.deleteObject)
        {
            GameObject objectToDelete = GameObject.Find(textPromptSO.objectToDelete);
            Destroy(objectToDelete);
        }
    }