/// <summary> /// When triggered, either by button press or simply entering the zone, starts the dialogue /// </summary> public virtual void StartDialogue() { if (_buttonA != null) { Destroy(_buttonA); } if (_collider == null) { return; } if (_activated && !ActivableMoreThanOnce) { return; } if (!_activable) { return; } if (!CanMoveWhileTalking) { LevelManager.Instance.FreezeCharacters(); if (ShouldUpdateState) { _characterButtonActivation.GetComponent <Character>().MovementState.ChangeState(CharacterStates.MovementStates.Idle); } } if (!_playing) { GameObject dialogueObject = (GameObject)Instantiate(Resources.Load("GUI/DialogueBox")); _dialogueBox = dialogueObject.GetComponent <DialogueBox>(); _dialogueBox.transform.position = new Vector2(_collider.bounds.center.x, _collider.bounds.max.y + DistanceFromTop); _dialogueBox.ChangeColor(TextBackgroundColor, TextColor); _dialogueBox.ButtonActive(ButtonHandled); if (TextFont != null) { _dialogueBox.DialogueText.font = TextFont; } if (TextSize != 0) { _dialogueBox.DialogueText.fontSize = TextSize; } _dialogueBox.DialogueText.alignment = Alignment; if (!ArrowVisible) { _dialogueBox.HideArrow(); } _playing = true; } StartCoroutine(PlayNextDialogue()); }
/// <summary> /// When triggered, either by button press or simply entering the zone, starts the dialogue /// </summary> public virtual void StartDialogue() { // if the button A prompt is displayed, we hide it if (_buttonA != null) { Destroy(_buttonA); } // if the dialogue zone has no box collider, we do nothing and exit if (_collider == null) { return; } // if the zone has already been activated and can't be activated more than once. if (_activated && !ActivableMoreThanOnce) { return; } // if the zone is not activable, we do nothing and exit if (!_activable) { return; } // if the player can't move while talking, we notify the game manager if (!CanMoveWhileTalking) { LevelManager.Instance.FreezeCharacters(); if (ShouldUpdateState) { _characterButtonActivation.GetComponent <Character>().MovementState.ChangeState(CharacterStates.MovementStates.Idle); } } // if it's not already playing, we'll initialize the dialogue box if (!_playing) { // we instantiate the dialogue box GameObject dialogueObject = (GameObject)Instantiate(Resources.Load("GUI/DialogueBox")); _dialogueBox = dialogueObject.GetComponent <DialogueBox>(); // we set its position _dialogueBox.transform.position = new Vector2(_collider.bounds.center.x, _collider.bounds.max.y + DistanceFromTop); // we set the color's and background's colors _dialogueBox.ChangeColor(TextBackgroundColor, TextColor); // if it's a button handled dialogue, we turn the A prompt on _dialogueBox.ButtonActive(ButtonHandled); // if font settings have been specified, we set them if (BoxesFollowZone) { _dialogueBox.transform.SetParent(this.gameObject.transform); } if (TextFont != null) { _dialogueBox.DialogueText.font = TextFont; } if (TextSize != 0) { _dialogueBox.DialogueText.fontSize = TextSize; } _dialogueBox.DialogueText.alignment = Alignment; // if we don't want to show the arrow, we tell that to the dialogue box if (!ArrowVisible) { _dialogueBox.HideArrow(); } // the dialogue is now playing _playing = true; } // we start the next dialogue StartCoroutine(PlayNextDialogue()); }