using FSM; using System; using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; using UnityEngine; using ZXKFramework; namespace YiLiao.XinFeiTingZhen { public class FSMManager : FsmBase { [HideInInspector] public bool nextState; public GameModel gameModel; public Main.GameModel main_gameModel; public void Init() { gameModel = MVC.GetModel(); main_gameModel = MVC.GetModel(); StartCoroutine(InitData(ChangeStateEvent)); } private void ChangeStateEvent(string stateName) { gameModel.ChangeState(stateName); if (gameModel.bData != null) { InteractionDisableAll(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.uiManager.CloseUI(); GameManager.Instance.highLightManager.HideAllHighLight(); GameManager.Instance.sceneDataHandler.SaveSceneDataToJson(main_gameModel.mainData.folder + "/SaveData/" + stateName + ".json"); GameManager.Instance.uiManager.GetUI().AddTip(gameModel.bData.txt); //GameManager.Instance.kaoheManager.AddData(gameModel.bData.parentName, gameModel.bData.name, gameModel.bData.type, gameModel.bData.score_kh); if (main_gameModel.modeType == ModeType.KaoHe) { GameManager.Instance.kaoheManager.AddData(gameModel.bData.name1, gameModel.bData.name2, gameModel.bData.name3, gameModel.bData.name4, gameModel.bData.type, gameModel.bData.score_kh); } if (main_gameModel.modeType == ModeType.ShiXun) { GameManager.Instance.kaoheManager.AddData(gameModel.bData.name1, gameModel.bData.name2, gameModel.bData.name3, gameModel.bData.name4, gameModel.bData.type, gameModel.bData.score_sx); } GameManager.Instance.uiManager.GetUI().Expand(gameModel.bData.state); } } public void ShowPopText(string str) { GameManager.Instance.uiManager.ShowUI(null, new string[] { str }); } public void ClosePopText() { GameManager.Instance.uiManager.CloseUI(); } public void ShowTip(int i, bool isKaohe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) return;//考核模式不显示 GameManager.Instance.uiManager.GetUI().ShowTip(i); GameManager.Instance.uiManager.ShowUI(); } public void HideTip() { GameManager.Instance.uiManager.CloseUI(); } public void ShowCamera(string value) { GameManager.Instance.virtualCameraManager.ShowCamera(value); } //播放语音 public void PlayBgm(int id) { if (main_gameModel.modeType == ModeType.KaoHe) return;//考核模式不显示 if (gameModel.bData.sound.Split('|').Length <= id) return; Game.Instance.eventManager.Raise(new PlaySoundEvent() { path = gameModel.bData.sound.Split('|')[id], }); } public GameObject Get(string value) { return GameManager.Instance.interactionManager._allInteraction[value]; } //显示交互 public void Show(string value) { GameManager.Instance.interactionManager._allInteraction[value].SetActive(true); } //隐藏交互 public void Hide(string value) { GameManager.Instance.interactionManager._allInteraction[value].SetActive(false); } //添加Down交互 public void InteractionDown(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IDown down); down?.Down(callBack); } //添加Stay交互 public void InteractionStay(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IStay stay); stay?.Stay(callBack); } //添加Trigger交互 public void InteractionTrigger(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ITrigger trigger); trigger?.Trigger(callBack); } //显示高亮 public void Light(string value, bool isKaoHeLight = false) { if (!isKaoHeLight) { if (main_gameModel.modeType == ModeType.ShiXun) { Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = true }); } } else { Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = true }); } } public void Light(string value) { if (main_gameModel.modeType == ModeType.KaoHe) return;//考核模式不高亮 Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = true }); } /// /// 打开高亮 打开交互 /// public void Light_EnableInteraction(string value) { Light(value); GameManager.Instance.interactionManager.EnableInteraction(value); } //隐藏高亮 public void Unlight(string value) { Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = false }); } /// /// 关闭高亮 关闭交互 /// public void Unlight_DisableInteraction(string value) { Unlight(value); GameManager.Instance.interactionManager.DisableInteraction(value); } public void InteractionDisableAll() { foreach (var item in GameManager.Instance.interactionManager._allInteraction) { item.Value.TryGetComponent(out ITrigger trigger); trigger?.Trigger(null); item.Value.TryGetComponent(out IStay stay); stay?.Stay(null); item.Value.TryGetComponent(out IDown down); down?.Down(null); } } //播放Timeline Coroutine coroutine; public void PlayClip(string value, Action callBack = null) { float t = GetClipLength(value); if (t > 0.1f) GameManager.Instance.uiManager.GetUI().LockAllBtn(); GameManager.Instance.timelineManager.PlayNormalClip(value); if (Game.Instance) { if (coroutine != null) Game.Instance.IEnumeratorManager.Stop(coroutine); coroutine = Game.Instance.IEnumeratorManager.Run(WaitExecute(t, () => { GameManager.Instance.uiManager.GetUI().UnLockAllBtn(); callBack?.Invoke(); })); } } public void StopClip(string value) { if (Game.Instance) { Game.Instance.IEnumeratorManager.Stop(coroutine); GameManager.Instance.timelineManager.StopNormalCilp(value); } } IEnumerator WaitExecute(float length, Action callBack) { yield return new WaitForSeconds(length); callBack?.Invoke(); } //时长Timeline public float GetClipLength(string value) { return GameManager.Instance.timelineManager.GetNormalTime(value); } /// /// 显示物体 打开高亮 /// public void Show_Light(string value) { Show(value); Light(value); } /// /// 隐藏物体 关闭高亮 /// public void Hide_Unlight(string value) { Hide(value); Unlight(value); } public void ShowTxtQuestion(int id, int scoreId, int score, Action nextFun) { TxtSelectQuestionPanel txtSelectQuestionPanel = GameManager.Instance.uiManager.GetUI(); txtSelectQuestionPanel.ShowImgQuestion(id); txtSelectQuestionPanel.nextAction = nextFun; txtSelectQuestionPanel.subAction = isTrue => { if (isTrue) { AddScore(scoreId, score); } else { AddScore(scoreId, 0); } }; } public void ShowImgQuestion(int id, int scoreId, int score, Action nextFun) { ImgSelectQuestionPanel imgSelectQuestionPanel = GameManager.Instance.uiManager.GetUI(); imgSelectQuestionPanel.ShowImgQuestion(id); imgSelectQuestionPanel.nextAction = nextFun; imgSelectQuestionPanel.subAction = isTrue => { if (isTrue) { GameManager.Instance.kaoheManager.AddScore(scoreId, score, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } else { GameManager.Instance.kaoheManager.AddScore(scoreId, 0, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } }; } public void ShowDragQuestion(string stepName, int id, int scoreId, int score, Action nextFun) { DragQuestionPanel dragQuestionPanel = GameManager.Instance.uiManager.GetUI(); dragQuestionPanel.ShowDragQuestion(id, stepName); dragQuestionPanel.nextAction = nextFun; dragQuestionPanel.subAction = isTrue => { if (isTrue) { GameManager.Instance.kaoheManager.AddScore(scoreId, score, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } else { GameManager.Instance.kaoheManager.AddScore(scoreId, 0, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } }; } public void ShowLineQuestion(int id, int scoreId, int score, Action nextFun) { LineQuestionPanel lineQuestionPanel = GameManager.Instance.uiManager.GetUI(); lineQuestionPanel.ShowLineQuestion(id); lineQuestionPanel.nextAction = nextFun; lineQuestionPanel.subAction = isTrue => { if (isTrue) { GameManager.Instance.kaoheManager.AddScore(scoreId, score, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } else { GameManager.Instance.kaoheManager.AddScore(scoreId, 0, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } }; } public void AddScore(int id, float score) { if (score > 0) { Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = true }); } else { Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = false }); } if (GameManager.Instance.uiManager.GetUI().tip == false) { GameManager.Instance.kaoheManager.AddScore(id, score, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } GameManager.Instance.uiManager.GetUI().tip = false; } public void ShowArrow(string txt, Vector2 v, int showtime = 2, int hidetime = 5, bool isKaoHe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaoHe) return; GameManager.Instance.uiManager.GetUI().ShowArrow(txt, v, 0, showtime, hidetime); } public void ShowArrow(Vector2 v, int showtime = 2, int hidetime = 5, bool isKaoHe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaoHe) return; GameManager.Instance.uiManager.GetUI().ShowArrow(v, 0, showtime, hidetime); } public void ShowArrow(string txt, string objName, int showtime = 2, int hidetime = 5, bool isKaoHe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaoHe) return; GameManager.Instance.uiManager.GetUI().ShowArrow(GameManager.Instance.interactionManager._allInteraction[objName].transform, txt, 0, showtime, hidetime); } public void HideArrow() { GameManager.Instance.uiManager.GetUI().HideArrow(); } public void ShowTipBtn(Action action, int showt = 2) { if (main_gameModel.modeType == ModeType.ShiXun) return; GameManager.Instance.uiManager.GetUI().ShowTipBtn(action, showt); } public void HideTipBtn() { GameManager.Instance.uiManager.CloseUI(); } public void ShowSpeakPanel(string stepName, string tipTxt, Vector2 v, int delayShowTime, int id, int score, Action action) { GameManager.Instance.uiManager.GetUI().ShowSpeakPanel(stepName, tipTxt, v, delayShowTime, id, score, action); } public void HideSpeakPanel() { GameManager.Instance.uiManager.CloseUI(); } } }