//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, December 26, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //剧情对话面板 namespace Snxxz.UI { public class DialogueDuidanceWin : Window { [SerializeField] Button m_MarkRay; [SerializeField] Button m_SKIPButton; [SerializeField] GameObject m_BaseboardImageNPC; [SerializeField] RawImage m_NPCIcon; [SerializeField] Text m_NPCNameText; [SerializeField] Text m_ContentText_Npc; [SerializeField] GameObject m_BaseboardImagePlayer; [SerializeField] RawImage m_playerIcon; [SerializeField] Text m_PlayerNameText; [SerializeField] Text m_ContentText; [SerializeField] Text m_NextText; [SerializeField] List MysteriousTaskID = new List();//新添神秘任务 Dictionary PlayerIcon = new Dictionary(); private int storyMissionsID = 0;//剧情任务ID private int taskCount = 0;//获取对话总条数 private int[] sPeaker;//对话对应半身像(0为主角/1为NPC) private int nowTaskNum = 0;//获取当前的任务 private int typesPeaker = -1; private float timeType = 0f; TaskModel m_TaskModel; TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel()); } } TreasureModel m_treasureModel; TreasureModel treasureModel { get { return m_treasureModel ?? (m_treasureModel = ModelCenter.Instance.GetModel()); } } PlayerMainDate m_MainModel; PlayerMainDate mainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel()); } } private int IsMultistage = 0;//是否有多段对话0,没有1,有 private int FabaoId; private int AwaitSecond; #region Built-in private enum TaskType { OK = 0, FB = 1, Double = 2, } protected override void BindController() { var config = FuncConfigConfig.Get("TaskContinue"); FabaoId = int.Parse(config.Numerical1); AwaitSecond = int.Parse(config.Numerical2); PlayerHead(); } protected override void AddListeners() { m_MarkRay.AddListener(OnClickMarkRay); m_SKIPButton.AddListener(OnClickSKIPButton); } protected override void OnPreOpen() { MainInterfaceWin.IsOpenMaininterface += IsOpenMaininterface; timeType = 0; m_NextText.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecond); IsCloseWindow(); typesPeaker = -1; storyMissionsID = taskmodel._TaskNow; var config = StoryMissionsConfig.Get(storyMissionsID); if (config.TaskMusic != 0) { SoundPlayer.Instance.PlayNpcAudio(config.TaskMusic); } if (config == null) { return; } if (config.NpcID[0] == taskmodel.NPCid) { taskCount = config.TalkNum[0]; sPeaker = config.Speaker1; IsMultistage = 0; } else { taskCount = config.TalkNum[0]; sPeaker = config.Speaker2; IsMultistage = 1; } //taskCount = config.TalkNum; //sPeaker = config.Speaker; nowTaskNum = 0; ShowDialogSelect(sPeaker[0], nowTaskNum); } private void IsCloseWindow() { if (WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Close(); } if (WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Close(); } } protected override void OnAfterOpen() { } protected override void OnPreClose() { MainInterfaceWin.IsOpenMaininterface -= IsOpenMaininterface; UI3DModelExhibition.Instance.StopShow(); } private void IsOpenMaininterface() { Close(); } protected override void OnAfterClose() { if (MysteriousTaskID.Contains(storyMissionsID)) { mainModel.MysteriousTaskID = storyMissionsID; CoroutineMgr.Instance.OnMysteriousTask(); } bool _bool = IsDungeon(); if (_bool) { WindowCenter.Instance.Open(); } if (!WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Open(); } } protected override void LateUpdate() { timeType += Time.deltaTime; if (timeType >= AwaitSecond) { m_NextText.text = string.Format(Language.Get("TaskContinueCount"), 0); OnClickSKIPButton(); mainModel.IsSelfMotionTask = true; } else { m_NextText.text= string.Format(Language.Get("TaskContinueCount"), AwaitSecond - (int)timeType); } if (this is BossShowDialogueWin) { return; } if (!WindowCenter.Instance.IsOpen()) { return; } 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)) { WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); _hero.LockTarget = null; } } private void OnClickMarkRay() { timeType = 0; var config = StoryMissionsConfig.Get(storyMissionsID); if (config == null) { return; } nowTaskNum += 1; if (taskCount - 1 >= nowTaskNum)//下一条 { ShowDialogSelect(sPeaker[nowTaskNum], nowTaskNum); } if (taskCount - 1 < nowTaskNum)//最后一条 { SessionEnd(TaskType.OK); Close(); WindowCenter.Instance.Open(); bool _bool = IsDungeon(); if (_bool) { WindowCenter.Instance.Open(); } } } private void OnClickSKIPButton() { var config = StoryMissionsConfig.Get(storyMissionsID); if (config != null) { SessionEnd(TaskType.OK); } mainModel.IsSelfMotionTask = false; Close(); HeroAIRecorder.ClearRecord(); WindowCenter.Instance.Open(); } #endregion private void ShowDialogSelect(int type, int stepNum) { if (type == 0) { if (typesPeaker != type) { m_BaseboardImageNPC.SetActive(false); m_BaseboardImagePlayer.SetActive(true); } int playerJob = PlayerDatas.Instance.baseData.Job; UI3DModelExhibition.Instance.ShowPlayer(m_playerIcon, playerJob, true); m_PlayerNameText.text = PlayerDatas.Instance.baseData.PlayerName; string platercContentKey = StoryMissionsConfig.Get(storyMissionsID).content[IsMultistage]; var config = TASKINFOConfig.Get(string.Format(platercContentKey, stepNum)); if (config != null) { m_ContentText.text = config.show_writing; } else { DebugEx.LogError("TaskInFo中没有这个Key。。" + string.Format(platercContentKey, stepNum)); } } if (type == 1) { if (typesPeaker != type) { m_BaseboardImageNPC.SetActive(true); m_BaseboardImagePlayer.SetActive(false); } var configStoryMissions = StoryMissionsConfig.Get(storyMissionsID); if (configStoryMissions == null) { return; } int npcId = configStoryMissions.NpcID[IsMultistage]; var npcConfig = NPCConfig.Get(npcId); m_NPCNameText.text = npcConfig.charName; string npcContentKey = configStoryMissions.content[IsMultistage]; var taskInfo = TASKINFOConfig.Get(string.Format(npcContentKey, stepNum)); if (taskInfo == null) { DebugEx.LogError("TASKINFOConfig中没有找到对应的Key"); } else { m_ContentText_Npc.text = taskInfo.show_writing; } string npcIcon = configStoryMissions.NpcIcon[IsMultistage]; var data = new UI3DNPCExhibitionData() { npcId = npcId, isDialogue = true, }; UI3DModelExhibition.Instance.ShowNPC(m_NPCIcon,data); } typesPeaker = type; } private void SessionEnd(TaskType taskType) { switch (taskType) { case TaskType.OK: case TaskType.FB: taskmodel.RequestGetTaskAward("OK"); break; case TaskType.Double: taskmodel.RequestGetTaskAward("Double"); break; default: break; } } private void PlayerHead() { string[] headStr1 = FuncConfigConfig.Get("StoryTaskIcon").Numerical1.Split('|'); string[] headStr2 = FuncConfigConfig.Get("StoryTaskIcon").Numerical2.Split('|'); for (int i = 0; i < headStr1.Length; i++) { if (!PlayerIcon.ContainsKey(int.Parse(headStr1[i]))) { PlayerIcon.Add(int.Parse(headStr1[i]), headStr2[i]); } } } private bool IsDungeon() { var mapId = PlayerDatas.Instance.baseData.MapID; var mapConfig = MapConfig.Get(mapId); return mapConfig != null && mapConfig.MapFBType != 0; } } }