const float k_MarginBetweenCards = 20f; //Margin between each card private void Awake() { main = (DialogueBlock)target; reorderableList = new ReorderableList(main.dialogueList, typeof(Dialogue), true, true, true, true); reorderableList.drawHeaderCallback += OnDrawHeader; reorderableList.drawElementCallback += OnDrawElement; reorderableList.elementHeightCallback += GetElementHeight; reorderableList.onReorderCallbackWithDetails += ReorderCallbackDelegateWithDetails; }
///<summary>Main method to call when adding a new Dialogue Block to the Dialogue Manager. Also starts up the dialogue box.</summary> ///<param name="dialogueListScript">The Dialogue Block to add the the Dialogue Manager's list.</param> public void AddDialogueBlock(DialogueBlock dialogueListScript) { //Add the incoming data to the master list dialogueBlocks.Add(dialogueListScript); //Startup for the first time if (isDialoguePlaying == false) { isDialoguePlaying = true; animator.SetBool("IsOpen", true); UpdateDialogue(); } }
///<summary>Updates the dialogue box.</summary> private void UpdateDialogue() { DialogueBlock currentBlock = dialogueBlocks[indexBlock]; //The current Dialogue Block we are on Dialogue currentDialogue = currentBlock.dialogueList[indexSentence]; //The current Dialogue Sentence we are on //Reset all button components SetAllButtons_Active(false); SetAllButtons_TextIconsActive(false); SetAllButtons_ButtonIconsActive(false); SetAllButtons_SelectArrowActive(false); SetAllButtons_ButtonLinkType(ButtonType.None); //Set the areaField as the default selected button clickAreaField.gameObject.SetActive(true); clickAreaField.Select(); #region BUTTON_CHECK //Check if we are at the end of the current block if (indexSentence >= currentBlock.dialogueList.Count - 1) { //Check if the current block has any buttons if (currentBlock.hasButtons) { //Turn off the areaField clickAreaField.gameObject.SetActive(false); //Select the last button as the default selected button choiceButtons[currentBlock.buttonCount - 1].Select(); choiceButtons[currentBlock.buttonCount - 1].OnSelect(null); //Loop through and update each individual button for (int i = 0; i < currentBlock.buttonCount; i++) { choiceButtons[i].SetActive(true); //Turn the button on choiceButtons[i].SetText(currentBlock.choiceBtnDataList[i].text); //Set the Text if (currentBlock.choiceBtnDataList[i].hasTextIcon) { choiceButtons[i].SetTextIcon(currentBlock.choiceBtnDataList[i].textIcon); //Set the TextIcon } choiceButtons[i].SetButtonType(currentBlock.choiceBtnDataList[i].buttonType); //Set the ButtonIcon int delegateIndex = i; //Note: Dont use i in a delegate, use delegateIndex instead choiceButtons[i].onSubmit.RemoveAllListeners(); choiceButtons[i].onSubmit.AddListener(delegate { if (isDialoguePlaying) { OnButtonSubmit(delegateIndex); DialogueBlock nextDialogueBlock = currentBlock.choiceBtnDataList[delegateIndex].DialogueBlock; //Checks if their is a dialogue block to trigger if (nextDialogueBlock != null) { nextDialogueBlock.TriggerDialogue(); } DisplayNextSentence(); } }); } } } #endregion //Play the typing audio audioTyping.Stop(); audioTyping.Play(); //Set the name and sentance textName.text = currentDialogue.name; string sentence = currentDialogue.sentence; //Start typing out sentance if (coroutineTypeSentence != null) { StopCoroutine(coroutineTypeSentence); } coroutineTypeSentence = StartCoroutine(TypeSentence(sentence)); }