using UnityEngine; using UnityEngine.UI; using System; using DataTools; using WebTools.Customizes.Behaviours; [Serializable] public class ConversationAudioData { public string audioId; public AudioClip voice; } public class ConversationManager : GameplayBase { public static ConversationManager instance; public event Action onChangeDialog; [Header("DATA")] [SerializeField] protected DataUser dataUser; [Header("ANIMATIONS")] [SerializeField] private Animator dialogAnimation; [Header("GAME OBJECTS")] [SerializeField] private GameObject Dialog; [SerializeField] private GameObject Notification; [SerializeField] private GameObject nextButton; [SerializeField] private GameObject answersContainer; [SerializeField] private GameObject textGlobeConversation; [SerializeField] private GameObject textGlobePhone; [Header("TEXT")] [SerializeField] private Text currenConversationText; [SerializeField] private Text currentSpeakerText; [Header("TEXT MESSAGE")] [SerializeField] private PhoneUIMessages texMessage; [SerializeField] private PhoneUIMessages mailMessage; [Header("BUTTONS")] [SerializeField] private ButtonAnswer[] buttonsAnswer; [Header("SOUNDS")] [SerializeField] private ConversationAudioData[] conversationAudioData; [SerializeField] private AudioSource audioSource; [Header("CHARACTER")] [SerializeField] private CustomizeCharacterBehaviour currentCharacter; [Header("StyleCheck")] [SerializeField] private FillBar stylebar; [SerializeField] private Image styleImage; [SerializeField] private Sprite styleCasual; [SerializeField] private Sprite styleCouture; [SerializeField] private Sprite styleActivewear; [SerializeField] private Sprite styleSwimwear; [Header("Next dialog marks")] [SerializeField] private Image nextMark; [SerializeField] private Sprite basicMark; [SerializeField] private Sprite phoneMark; [Header("Sound for answers VFX")] [SerializeField] private AudioClip cameraSound; public AudioClip CameraSound { get { return cameraSound; } } private Characters characters; private int nextDialogIndex = 0; private string newLocationId = ""; private float conversationDelay = 0; private bool dialogIsEnabled = true; private bool needToRestartConversation = false; private void Awake() { instance = this; } protected override void Start() { WebTools.UserInput.OnNameInput += ResetConversation; WebTools.UserInput.OnGenderInput += NextDialogue; DisableDialogItmes(); characters = FindObjectOfType(); base.Start(); } private void OnDestroy() { WebTools.UserInput.OnNameInput -= ResetConversation; WebTools.UserInput.OnGenderInput -= NextDialogue; } public void ClearText() { currenConversationText.text = ""; currentSpeakerText.text = ""; } private void SetNextMark() { if(currentConversation != null) { switch(currentConversation.ConvType) { case DataTools.ConversationType.PhoneCall: { nextMark.sprite = phoneMark; break; } default: { nextMark.sprite = basicMark; break; } } } } private bool LocationMatch { get { bool locationFlag = currentConversation.Location.ToUpper() == newLocationId.ToUpper(); bool exteriorFlag = (currentConversation.Location.ToUpper() == "EXTERIOR") && GameGlobal.Instance.GetIsExterior(); bool anyFlag = (currentConversation.Location.ToUpper() == "ANY"); return (locationFlag || exteriorFlag || anyFlag); } } public void StartDialogue() { UnblockGame(); if (!LocationMatch) { return; } ClearText(); PanelQuestBehaviour.Instance.HideMainQuest(); Notification.SetActive(false); Dialog.SetActive(true); SetupInitialDiaogue(); EnableNextDialogue(0f, currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex]); } public void FinishTask(bool resetDialog = true) { ContacsBehaviour.Instance.ShowContac(); if (resetDialog) { dataUser.UserData.ProgressData.CurrentConversationIndex = 0; } UnblockGame(); OnFinishConversation(); } private void OnFinishConversation(bool mainStoryConvo = true) { currentConversation = null; if (mainStoryConvo) { GameplayManager.instance.NextChapterAction(); } } private void DisableDialogItmes() { ClearText(); Debug.Log("Disable dialog items"); Dialog.SetActive(false); Notification.SetActive(false); } private void EnableNextDialogue(float animDelay, DataTools.Dialog dialog) { if(onChangeDialog != null) { onChangeDialog(dialog); } string prevNpcId = GameGlobal.Instance.CurrentNpc; GameGlobal.Instance.CurrentNpc = dialog.NpcId; if (prevNpcId != GameGlobal.Instance.CurrentNpc) { ClearText(); dialogAnimation.StopPlayback(); Dialog.SetActive(false); Invoke("PlayDialogue", 0.2f); } else { Invoke("PlayDialogue", animDelay); } } private bool isNoProblemWithNextDialog { get { return ((currentConversation != null) && (currentConversation.Dialog != null) && (currentConversation.Dialog.Count != 0)); } } private void NextDialogue() { SetActiveButtons(false); if (nextDialogIndex == -1) { int nextIndex = isNoProblemWithNextDialog ? currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex].NextDialogIndex : -1; if (nextIndex != -1) { dataUser.UserData.ProgressData.CurrentConversationIndex = nextIndex; } else { dataUser.UserData.ProgressData.CurrentConversationIndex = currentConversation.Dialog.Count; } } else { if (nextDialogIndex == dataUser.UserData.ProgressData.CurrentConversationIndex || nextDialogIndex == 0) { int nextIndex = isNoProblemWithNextDialog ? currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex].NextDialogIndex : -1; if (nextIndex != -1) { dataUser.UserData.ProgressData.CurrentConversationIndex = nextIndex; } else { dataUser.UserData.ProgressData.CurrentConversationIndex = currentConversation.Dialog.Count; } } else { dataUser.UserData.ProgressData.CurrentConversationIndex = nextDialogIndex; } } if (currentConversation != null) { if (GameGlobal.Instance.GetCurrentQuest != null /*&& currentConversation.ConvType!=DataTools.ConversationType.Optional*/) { GameGlobal.Instance.SetCurrentDialogIndex(dataUser.UserData.ProgressData.CurrentConversationIndex); GameGlobal.Instance.SetActionID(GameGlobal.Instance.GetCurrentQuest.Tasks[GameGlobal.Instance.GetQuestIndex()].Action.PropertyId, currentConversation.Id); } if (dataUser.UserData.ProgressData.CurrentConversationIndex < currentConversation.Dialog.Count) { EnableNextDialogue(0.5f, currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex]); } else { dialogIsEnabled = false; if (currentConversation.ConvType == DataTools.ConversationType.PhoneCall) { WebTools.Phone.PanelPhoneBehaviour.Instance.EndCall(); } FinishTask(); } } dataUser.UpdateUserProgress(); } private void PlayAudio() { conversationDelay = 0; if (currentConversation != null) { if (currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex].SoundId != "") { foreach (ConversationAudioData audioData in conversationAudioData) { if (audioData.audioId == currentConversation.Dialog[dataUser.UserData.ProgressData.CurrentConversationIndex].SoundId) { audioSource.clip = audioData.voice; audioSource.Play(); conversationDelay = audioSource.clip.length; } } } } } public void SetNextDialogue(int _nextDialogIndex) { if (currentConversation != null) { if (currentConversation.ConvType == DataTools.ConversationType.Auto || currentConversation.ConvType == DataTools.ConversationType.Basic || currentConversation.ConvType == DataTools.ConversationType.PhoneCall || currentConversation.ConvType == DataTools.ConversationType.Optional) { if (needToRestartConversation) { needToRestartConversation = false; ResetConversation(); return; } nextDialogIndex = _nextDialogIndex; PlayAudio(); dialogAnimation.Play("EndDialogue"); Invoke("NextDialogue", conversationDelay); } } } public void GoToNextDialog() { int dialog = dataUser.UserData.ProgressData.CurrentConversationIndex; int next = currentConversation.Dialog[dialog].NextDialogIndex; SetNextDialogue(next); } public void ResetConversation() { if (GameplayManager.instance.QuestIsActive) { GameGlobal.Instance.DecreaseQuestIndex(); } else { GameGlobal.Instance.DecreaseChapElementIndex(); } FinishTask(false); } private void UnblockGame() { GameGlobal.Instance.PannigLocked = false; if (currentConversation.ConvType != DataTools.ConversationType.TextMessage) { if (currentConversation.ConvType != DataTools.ConversationType.Email) { Navigation.Instance.FinishCam(); } } BlockerManager.Instance.UnblockAllButtons(GameplayManager.instance.isFirstGigPassed); } public void CancelConversation() { UnblockGame(); DisableDialogItmes(); SetConversation(currentConversation); } private void SetActiveButtons(bool setActive) { Button[] buttons = this.gameObject.GetComponentsInChildren