//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, April 23, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class NormalDialogueWin : Window { [SerializeField] Button m_Skip; [SerializeField] Button m_EmptyAccepter; [SerializeField] Transform m_ContainerNpc; [SerializeField] RawImage m_RawNpc; [SerializeField] Text m_NpcName; [SerializeField] Text m_NpcDialogue; [SerializeField] Transform m_ContainerPlayer; [SerializeField] RawImage m_RawPlayer; [SerializeField] Text m_PlayerName; [SerializeField] Text m_PlayerDialogue; [SerializeField] Text m_Time; int dialogueIndex = 0; public static int npcId = 0; public static int[] speakTypes = null; public static string[] dialogues = null; public static int autoSeconds = 0; float timer = 0f; float displayTimer = 0f; public static event Action onDialogueComplete; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_EmptyAccepter.AddListener(OnClickEmpty); m_Skip.AddListener(OnSkip); } protected override void OnPreOpen() { dialogueIndex = 0; timer = 0f; DisplayDialogue(); DisplayTime(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { UI3DModelExhibition.Instance.StopShow(); } protected override void OnAfterClose() { if (!WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Open(); } } protected override void LateUpdate() { timer += Time.deltaTime; if (timer >= autoSeconds) { OnClickEmpty(); } displayTimer += Time.deltaTime; if (displayTimer >= 0.5f) { displayTimer = 0f; DisplayTime(); } GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero == null) { return; } if (_hero.LockTarget == null) { return; } float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _hero.LockTarget.Pos); if (_chkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2)) { _hero.LockTarget = null; Close(); } } #endregion private void DisplayDialogue() { timer = 0f; DisplayTime(); if (speakTypes == null || dialogues == null) { return; } var speakType = speakTypes[dialogueIndex]; m_ContainerNpc.gameObject.SetActive(speakType == 0); m_ContainerPlayer.gameObject.SetActive(speakType == 1); switch (speakType) { case 1: var job = PlayerDatas.Instance.baseData.Job; UI3DModelExhibition.Instance.ShowPlayer(m_RawPlayer, job, true); m_PlayerName.text = PlayerDatas.Instance.baseData.PlayerName; m_PlayerDialogue.text = Language.Get(dialogues[dialogueIndex]); break; case 0: var npcConfig = NPCConfig.Get(npcId); m_NpcName.text = npcConfig.charName; m_NpcDialogue.text = Language.Get(dialogues[dialogueIndex]); var data = new UI3DNPCExhibitionData() { npcId = npcId, isDialogue = true, }; UI3DModelExhibition.Instance.ShowNPC(m_RawNpc, data); break; } } private void OnSkip() { Close(); if (onDialogueComplete != null) { onDialogueComplete(); } } private void DisplayTime() { var seconds = (int)(autoSeconds - timer); m_Time.text = Language.Get("TaskContinueCount", seconds); } private void OnClickEmpty() { if (dialogues != null && dialogueIndex < dialogues.Length - 1) { dialogueIndex += 1; DisplayDialogue(); } else { Close(); if (onDialogueComplete != null) { onDialogueComplete(); } } } } }