using FSM; using System; using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; using Unity.VisualScripting.Dependencies.NCalc; using UnityEngine; using UnityEngine.SocialPlatforms.Impl; using ZXKFramework; namespace DongWuYiXue.DaoNiaoShu { public class FSMManager : FsmBase { [HideInInspector] public bool nextState; public GameModel gameModel; public Main.GameModel main_gameModel; bool tip; //string gudieTxt_kaoHe; //bool tip; 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.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.uiManager.GetUI().Locate(gameModel.parentBtnName, gameModel.childBtnName); if (main_gameModel.modeType == ModeType.ShiXun) { GameManager.Instance.kaoheManager.AddData(gameModel.bData.parentName, gameModel.bData.name, gameModel.bData.type, gameModel.bData.score_sx); } if (main_gameModel.modeType == ModeType.KaoHe) { GameManager.Instance.kaoheManager.AddData(gameModel.bData.parentName, gameModel.bData.name, gameModel.bData.type, gameModel.bData.score_kh); } } } //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, bool isKaohe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) 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); } //添加Down交互 public void InteractionUp(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IUp up); up?.Up(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 isKaohe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) return;//考核模式不高亮 Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = true }); } /// /// 打开高亮 打开交互 /// public void Light_EnableInteraction(string value, bool isKaohe = false) { Light(value, isKaohe); 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 PlayClip(string value, Action callBack, float progress) { float t = GetClipLength(value); if (t > 0.1f) GameManager.Instance.uiManager.CloseUI(); //GameManager.Instance.timelineManager.PlayNormalClip(value); for (int i = 0; i < GameManager.Instance.timelineManager.clips.Length; i++) { if (GameManager.Instance.timelineManager.clips[i].name == value) { // 确保进度在0-1之间 progress = Mathf.Clamp01(progress); // 计算对应的时间点 float time = progress * (float)GameManager.Instance.timelineManager.clips[i].playClip.duration; //GameManager.Instance.timelineManager.clips[i].PlayNormal(); time = Mathf.Clamp(time, 0f, (float)GameManager.Instance.timelineManager.clips[i].playClip.duration); // 设置Timeline的当前时间 GameManager.Instance.timelineManager.clips[i].playClip.time = time; GameManager.Instance.timelineManager.clips[i].playClip.Play(); } } if (Game.Instance) { if (coroutine != null) Game.Instance.IEnumeratorManager.Stop(coroutine); coroutine = Game.Instance.IEnumeratorManager.Run(WaitExecute(t, () => { //GameManager.Instance.uiManager.GetUI().InteractableTrue(t); if (main_gameModel.modeType == ModeType.ShiXun) GameManager.Instance.uiManager.ShowUI(); callBack?.Invoke(); })); } } 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 Show_Light_EnableInteraction(string value, bool isKaoHe = false) { Show(value); Light(value, isKaoHe); GameManager.Instance.interactionManager.EnableInteraction(value); } /// /// 隐藏物体 关闭高亮 /// public void Hide_Unlight(string value) { Hide(value); Unlight(value); } public void Hide_Unlight_DisableInteraction(string value) { Hide(value); Unlight(value); GameManager.Instance.interactionManager.DisableInteraction(value); } //public void ShowTxtQuestion(int id, int score, int scoreId, Action nextFun) //{ // TxtSelectQuestionPanel txtSelectQuestionPanel = GameManager.Instance.uiManager.GetUI(); // txtSelectQuestionPanel.ShowImgQuestion(id); // txtSelectQuestionPanel.nextAction = nextFun; // txtSelectQuestionPanel.subAction = isTrue => // { // if (main_gameModel.modeType == ModeType.KaoHe) // { // if (isTrue) // { // AddScore(score, scoreId); // } // else // { // AddScore(0, scoreId); // } // } // else // { // Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = isTrue }); // } // }; //} public void ShowTxtQuestion(string stepName, int id, int scoreId, int score, Action nextFun) { TxtSelectQuestionPanel txtSelectQuestionPanel = GameManager.Instance.uiManager.GetUI(); txtSelectQuestionPanel.ShowImgQuestion(id, stepName); txtSelectQuestionPanel.nextAction = nextFun; txtSelectQuestionPanel.subAction = isTure => { if (isTure) { GameManager.Instance.kaoheManager.AddScore(score, scoreId, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } else { GameManager.Instance.kaoheManager.AddScore(0, scoreId, null); } }; } public void ShowImgQuestion(int id, int score, int scoreId, Action nextFun) { ImgSelectQuestionPanel imgSelectQuestionPanel = GameManager.Instance.uiManager.GetUI(); imgSelectQuestionPanel.ShowImgQuestion(id); imgSelectQuestionPanel.nextAction = nextFun; imgSelectQuestionPanel.subAction = isTrue => { //if (main_gameModel.modeType == ModeType.KaoHe) //{ if (isTrue) { AddScore(score, scoreId); } else { AddScore(0, scoreId); } //} //else //{ // Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = isTrue }); //} }; } //public void ShowDragQuestion(int id, int score, int scoreId, Action nextFun) //{ // DragQuestionPanel dragQuestionPanel = GameManager.Instance.uiManager.GetUI(); // dragQuestionPanel.ShowDragQuestion(id); // dragQuestionPanel.nextAction = nextFun; // dragQuestionPanel.subAction = (a, b) => // { // if (a) // { // AddScore(score, scoreId); // } // else // { // AddScore(0, scoreId); // } // }; //} 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(score, scoreId, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } else { GameManager.Instance.kaoheManager.AddScore(0, scoreId, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } }; } public void ShowLineQuestion(int id, int score, int scoreId, Action nextFun) { LineQuestionPanel lineQuestionPanel = GameManager.Instance.uiManager.GetUI(); lineQuestionPanel.ShowLineQuestion(id); lineQuestionPanel.nextAction = nextFun; lineQuestionPanel.subAction = isTure => { if (isTure) { AddScore(score, scoreId); } else { AddScore(0, scoreId); } }; } public void AddScore(int score, int id) { 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(score, id, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } GameManager.Instance.uiManager.GetUI().tip = false; } public void AddScore(int score, int id, bool isYiJianShuRu) { if (score.Equals(0) && isYiJianShuRu) { if (GameManager.Instance.uiManager.GetUI().tip == false) { GameManager.Instance.kaoheManager.AddScore(score, id, (s, t) => { GameManager.Instance.uiManager.GetUI().SetScore(s.ToString(), t.ToString()); }); } } } public void ShowArrow(string txt, Vector2 v, int arrowType = 0, int showtime = 2, int hidetime = 5, bool isKaoHe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaoHe) return; GameManager.Instance.uiManager.GetUI().ShowArrow(txt, v, arrowType, showtime, hidetime); } public void ShowArrow(Vector2 v, int arrowType = 0, int showtime = 2, int hidetime = 5, bool isKaoHe = false) { if (main_gameModel.modeType == ModeType.KaoHe && !isKaoHe) return; GameManager.Instance.uiManager.GetUI().ShowArrow(v, arrowType, showtime, hidetime); } public void ShowArrow(string txt, string objName, int arrowType = 0, 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, arrowType, showtime, hidetime); } public void HideArrow() { GameManager.Instance.uiManager.CloseUI(); } 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 ShowSlider(Vector2 v, float maxValue, float minValue, float initValue, Action updateaction, Action okaction) { GameManager.Instance.uiManager.GetUI().ShowPanel(v, maxValue, minValue, initValue, updateaction, okaction); } public void HideSlider() { GameManager.Instance.uiManager.CloseUI(); } //public void ShowSpeakPanel(Vector3 TransformWorldPlacement, string speakTxt, string keyword, int showtime, int hidetime, Action action) //{ // GameManager.Instance.uiManager.GetUI().SetTransformWorldPlacement(TransformWorldPlacement); // if (main_gameModel.modeType == ModeType.ShiXun) // { // GameManager.Instance.uiManager.GetUI().ShowSpeakPanel(speakTxt, keyword, true, true, showtime, hidetime, action); // } // else // { // GameManager.Instance.uiManager.GetUI().ShowSpeakPanel(speakTxt, keyword, false, true, showtime, hidetime, action); // } //} 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 ShowNextPanel(Action action) { GameManager.Instance.uiManager.GetUI().ShowPanel(action); } public void ShowVideoPanel(string path, Action action) { GameManager.Instance.uiManager.GetUI().ShowVideo(path, action); } public void HideVideoPanel() { GameManager.Instance.uiManager.CloseUI(); } } }