public void Start(ref List <Dialogue.DialogueData.DialoguePoint> interactions, DialogueAdvanceDelegate callback) { _onDialogueAdvance = null; if (null != callback) { _onDialogueAdvance += callback; } else if (null != _dialogueData && _dialogueData.isDuringGameplay) { _onDialogueAdvance += AdvanceChatBubbles; } _dialoguePoints = interactions; _currentInteraction = InteractionNotStarted; AdvanceInteraction(); }
public void Start(DialogueAdvanceDelegate callback) { Start(ref _dialogueData.dialoguePoints, callback); }
public void DisplayCharacterDialogue(string dialogue, string characterName = null, DialogueAdvanceDelegate dialogueAdvanceDelegate = null) { Debug.Log(characterName + " says: " + dialogue); // Place dialogue Vector2 dialoguePoint = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f); if (characterName != null) { float height = 0; Vector3 offsetPosition = Vector3.zero; GameObject speaker = GameObject.Find(characterName); if (speaker != null) { BoxCollider2D collider = speaker.GetComponent <BoxCollider2D>(); if (collider != null) { height = collider.size.y; } offsetPosition = new Vector3(speaker.transform.position.x, speaker.transform.position.y + height + kDialogueVerticalOffset, speaker.transform.position.z); } Camera cam = FindObjectsOfType <Camera>().First(); if (cam != null) { Vector3 screenPosition = cam.WorldToViewportPoint(offsetPosition); Debug.Log(screenPosition); dialoguePoint = new Vector2(screenPosition.x * canvas.GetComponent <RectTransform>().sizeDelta.x, screenPosition.y * canvas.GetComponent <RectTransform>().sizeDelta.y); } } GameObject dialogueObject; if (autoCreateSpokenText || dialogueBoxPrefab == null) { dialogueObject = new GameObject("Current Dialogue"); Text dialogueText = dialogueObject.AddComponent <Text>(); ContentSizeFitter sizeFitter = dialogueObject.AddComponent <ContentSizeFitter>(); sizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; dialogueText.text = dialogue; // TODO(laurenfrazier): Will each character have their own font/size/color? dialogueText.font = menuFont; dialogueText.fontSize = 44; } else { dialogueObject = Instantiate(dialogueBoxPrefab); dialogueObject.SetActive(true); DialogueMenu dialogueMenu = dialogueObject.GetComponentInChildren <DialogueMenu>(); if (dialogueMenu != null) { if (characterName != null) { dialogueMenu.AddTitle(characterName); } dialogueMenu.AddDescription(dialogue); } } dialogueObject.transform.SetParent(canvas.transform, true); dialogueObject.transform.position = dialoguePoint; currentlyDisplayedDialogueBox = dialogueObject; // When user dismisses by touching the screen, call callback this.dialogueAdvanceDelegate = dialogueAdvanceDelegate; if (screenTouchPanel != null) { screenTouchPanel.SetActive(true); } awaitingDialogueAdvance = true; }