public void ClearAllDialogues()
    {
        GameObject boxObject    = null;
        TextBoxUI  boxComponent = null;

        if (boxObjects != null)
        {
            for (int i = 0; i < boxObjects.Length; i++)
            {
                /*halmeida - relying on the coherence of all box related arrays.*/
                boxComponent = boxComponents[i];
                if (boxComponent != null)
                {
                    boxComponent.Clear();
                    boxComponents[i] = null;
                }
                boxObject = boxObjects[i];
                if (boxObject != null)
                {
                    GameObject.Destroy(boxObject);
                    boxObjects[i] = null;
                }
                boxMasterEvents[i] = null;
                boxMasterItems[i]  = null;
            }
            boxOptionIndexes = null;
            boxQuestionRoles = null;
            boxMasterItems   = null;
            boxMasterEvents  = null;
            boxComponents    = null;
            boxObjects       = null;
        }
        RemoveQuestionPreparation();
        itemOnDisplay = false;
    }
    private void RemoveDialogue(int dialogueIndex, bool affectOptions)
    {
        TextBoxUI        boxComponent          = null;
        GameObject       boxObject             = null;
        EventDialogue    boxMasterEvent        = null;
        QuestionRole     boxQuestionRole       = QuestionRole.None;
        IOptionsListener savedQuestionDelegate = null;
        int  savedOptionIndex  = -1;
        bool lastOptionToClose = false;

        if (boxObjects != null)
        {
            if ((dialogueIndex > -1) && (dialogueIndex < boxObjects.Length))
            {
                /*halmeida - relying on the coherence of all box related arrays.*/
                boxComponent = boxComponents[dialogueIndex];
                if (boxComponent != null)
                {
                    boxComponent.Clear();
                    boxComponents[dialogueIndex] = null;
                }
                boxObject = boxObjects[dialogueIndex];
                if (boxObject != null)
                {
                    GameObject.Destroy(boxObject);
                    boxObjects[dialogueIndex] = null;
                }
                boxMasterEvent = boxMasterEvents[dialogueIndex];
                if (boxMasterEvent != null)
                {
                    boxMasterEvent.ReactToDialogueEnd();
                    boxMasterEvents[dialogueIndex] = null;
                }
                boxMasterItems[dialogueIndex] = null;
                boxQuestionRole = boxQuestionRoles[dialogueIndex];
                UsefulFunctions.DecreaseArray <int>(ref boxOptionIndexes, dialogueIndex);
                UsefulFunctions.DecreaseArray <QuestionRole>(ref boxQuestionRoles, dialogueIndex);
                UsefulFunctions.DecreaseArray <EventDialogue>(ref boxMasterEvents, dialogueIndex);
                UsefulFunctions.DecreaseArray <ItemData>(ref boxMasterItems, dialogueIndex);
                UsefulFunctions.DecreaseArray <TextBoxUI>(ref boxComponents, dialogueIndex);
                UsefulFunctions.DecreaseArray <GameObject>(ref boxObjects, dialogueIndex);
                /*halmeida - if there are no more items associated with dialogues, we update the related variable.*/
                itemOnDisplay = (boxMasterItems == null) ? false : itemOnDisplay;
                if (itemOnDisplay)
                {
                    itemOnDisplay = false;
                    for (int i = 0; i < boxMasterItems.Length; i++)
                    {
                        if (boxMasterItems[i] != null)
                        {
                            itemOnDisplay = true;
                            break;
                        }
                    }
                }

                /*halmeida - the chosen option closes before the others, as a visual feedback to the player as to
                 * which option did he choose. If there was more than one available choice, we start closing them when
                 * the closure of the chosen one ends. We only send the chosen index to the delegate by the time all
                 * options have finished closing.*/
                if ((boxQuestionRole == QuestionRole.Option) && (questionDelegate != null))
                {
                    /*halmeida - since we don't really require an enunciate, I can't use the end of the closure of the
                     * enunciate as the trigger to send the chosen option and prepare for another question. I will use the
                     * end of the closure of the last option as this trigger.*/
                    lastOptionToClose = (boxQuestionRoles == null);
                    if (!lastOptionToClose)
                    {
                        lastOptionToClose = true;
                        for (int i = 0; i < boxQuestionRoles.Length; i++)
                        {
                            if (boxQuestionRoles[i] == QuestionRole.Option)
                            {
                                lastOptionToClose = false;
                            }
                        }
                    }
                    if (lastOptionToClose)
                    {
                        /*halmeida - send choice to questionDelegate, reset variables to allow preparation for other questions.*/

                        /*halmeida - when we send the choice, the questionDelegate may immediately start a new question, assigning
                         * itself or another questionDelegate to this TextBoxManager in the process. If we remove the question prep
                         * after sending the choice, we may be losing this new question's preparation. That's why we need to send
                         * the chosen choice only after the removal of the preparation of the current question, not before. To do
                         * that we need to save the values first.*/
                        savedQuestionDelegate = questionDelegate;
                        savedOptionIndex      = optionChosenIndex;
                        RemoveQuestionPreparation();
                        if (savedQuestionDelegate != null)
                        {
                            savedQuestionDelegate.ChooseOption(savedOptionIndex);
                        }
                    }
                    else
                    {
                        if (affectOptions)
                        {
                            CloseQuestion();
                        }
                    }
                }
            }
        }
    }