using BNG; using FSM; using System; using System.Collections; using System.Linq; using UnityEngine; using ZXKFramework; namespace YiLiao.SiBuChuZhen { public class FSMManager : FsmBase { [HideInInspector] public bool nextState; //手部模型 ControllerOffsetHelper[] hands; public BaseData bData; public QuestionData qData; public void Init() { StartCoroutine(InitData(ChangeStateEvent)); hands = GameManager.Instance.playerManager.player.GetComponentsInChildren(); } private void ChangeStateEvent(string stateName) { bData = MVC.GetModel().excelData.GetBaseDatastate(stateName); qData = MVC.GetModel().excelData.GetQuestionDatastate(stateName); if (bData != null && bData.modeType.Split('|').Contains(MVC.GetModel().modeType.ToString())) { if (bData.isBtn == "True") { GameManager.Instance.sceneDataHandler.SaveSceneDataToJson(MVC.GetModel().mainData.folder + "/SaveData/" + stateName + ".json"); } AddText(bData.txt); if (!string.IsNullOrEmpty(bData.vr_hand_materials) && Game.Instance.operatingType == OperatingType.VR) { ChangeHandMaterial(Convert.ToInt32(bData.vr_hand_materials));//改变手的材质 } if (MVC.GetModel().modeType == ModeType.KaoHe) { //AddButtonByID(bData.id); Game.Instance.eventManager.Raise(new KaoHeDataEvent() { name = string.IsNullOrEmpty(bData.childName) ? bData.name : bData.childName, state = bData.state, answer = bData.answerObj, score = bData.score, audio = bData.sound_kaohe, text = bData.txt_kaohe, type = bData.type }); } ScrollToButton(bData.id);//定位Button } } public void AddText(string value, Action callBack = null) { if (callBack != null) { GameManager.Instance.uiManager.GetUI().ShowConfirmGroup(value, callBack); } else { if (MVC.GetModel().modeType == ModeType.ShiXun) { GameManager.Instance.uiManager.GetUI().AddText(value); } } } public void AddButtonByID(int value) { GameManager.Instance.uiManager.GetUI().AddBtnByID(value); } public void HighlightText(int value) { GameManager.Instance.uiManager.GetUI().HighlightText(value); } public void ScrollToButton(int value) { GameManager.Instance.uiManager.GetUI().ScrollTo(value); } public void ShowCamera(string value) { GameManager.Instance.virtualCameraManager.ShowCamera(value); } public void PlayVideo(string path, Action callBack = null) { GameManager.Instance.uiManager.GetUI().ShowVideo(path, callBack); } //播放语音 public void PlayBgm(string path) { if (MVC.GetModel().modeType == ModeType.ShiXun) { Game.Instance.eventManager.Raise(new PlaySoundEvent() { path = path }); } } /// /// 设置物体的父物体为Null /// /// public void SetParentToRoot(string name) { GameManager.Instance.interactionManager._allInteraction[name].transform.SetParent(null); } public GameObject Get(string value) { return GameManager.Instance.interactionManager._allInteraction[value]; } //打开交互 public void EnableInteraction(string value) { GameManager.Instance.interactionManager.EnableInteraction(value); } //关闭交互 public void DisableInteraction(string value) { GameManager.Instance.interactionManager.DisableInteraction(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); } //添加Up交互 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); } //添加Enter交互 public void InteractionEnter(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IEnter enter); enter?.Enter(callBack); } //添加Exit交互 public void InteractionExit(string value, Action callBack) { GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IExit exit); exit?.Exit(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) { if (MVC.GetModel().modeType == ModeType.ShiXun) { Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = true }); } } //隐藏高亮 public void Unlight(string value) { Game.Instance.eventManager.Raise(new HighLightEvent() { name = value, visiable = false }); } //播放Timeline Coroutine coroutine; public void PlayClip(string value, Action callBack = null) { GameManager.Instance.timelineManager.PlayNormalClip(value); if (callBack != null) { coroutine = Game.Instance.IEnumeratorManager.Run(WaitExecute(GetClipLength(value), callBack)); } } public float PlayClip(string value) { GameManager.Instance.timelineManager.PlayNormalClip(value); return GetClipLength(value); } public void StopClip(string value) { 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 void InitClip(string value) { GameManager.Instance.timelineManager.PlayResetClip(value); } //时长Timeline public float GetClipLength(string value) { return GameManager.Instance.timelineManager.GetNormalTime(value); } /// /// 显示物体 打开高亮 /// public void Show_Light(string value) { Show(value); Light(value); } /// /// 打开高亮 打开交互 /// public void Light_EnableInteraction(string value) { Light(value); EnableInteraction(value); } /// /// 显示物体 打开高亮 打开交互 /// public void Show_Light_EnableInteraction(string value) { Show(value); Light(value); EnableInteraction(value); } /// /// 隐藏物体 关闭高亮 /// public void Hide_Unlight(string value) { Hide(value); Unlight(value); } /// /// 隐藏物体 关闭高亮 关闭交互 /// public void Hide_Unlight_DisableInteraction(string value) { Hide(value); Unlight(value); DisableInteraction(value); } /// /// 关闭高亮 关闭交互 /// public void Unlight_DisableInteraction(string value) { Unlight(value); DisableInteraction(value); } /// /// 松开物体 隐藏物体 关闭高亮 /// public void Loose_Hide_Unlight(string value) { Loose(value); Hide(value); Unlight(value); } /// /// 松开物体 隐藏物体 关闭高亮 关闭交互 /// public void Loose_Hide_Unlight_DisableInteraction(string value) { Loose(value); Hide(value); Unlight(value); DisableInteraction(value); } /// /// 松开物体 隐藏物体 关闭高亮 重置位置 /// public void Loose_Hide_Unlight_ResetTransform(string value) { Loose(value); Hide(value); Unlight(value); ResetTransfrom(value); } /// /// 松开物体 隐藏物体 关闭高亮 关闭交互 重置位置 /// public void Loose_Hide_Unlight_DisableInteraction_ResetTransform(string value) { Loose(value); Hide(value); Unlight(value); DisableInteraction(value); ResetTransfrom(value); } /// /// 关闭高亮 关闭重置 /// public void Unlight_CloseResetTransform(string value) { Unlight(value); CloseResetTransfrom(value); } /// /// 松开物体 关闭高亮 /// public void Loose_Unlight(string value) { Loose(value); Unlight(value); } /// /// 松开物体 关闭高亮 关闭交互 /// public void Loose_Unlight_DisableInteraction(string value) { Loose(value); Unlight(value); DisableInteraction(value); } /// /// 松开物体 关闭高亮 关闭交互 重置位置 /// public void Loose_Unlight_DisableInteraction_ResetTransform(string value) { Loose(value); Unlight(value); DisableInteraction(value); ResetTransfrom(value); } /// /// 松开物体 关闭高亮 重置位置 /// public void Loose_Unlight_ResetTransform(string value) { Loose(value); Unlight(value); ResetTransfrom(value); } /// /// 松开物体 重置位置 /// public void Loose_ResetTransform(string value) { Loose(value); ResetTransfrom(value); } //松开物体 public void Loose(string value) { if (GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ILoose loose)) { loose.Loose(); } } /// /// 打开交互 重置位置 /// public void Interaction_ResetTransform(string value) { EnableInteraction(value); ResetTransfrom(value); } //重置位置 public void ResetTransfrom(string value) { if (GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ResetPosRot rpp)) { rpp.isReset = true; rpp.ResetGameObject(); } } public void OpenResetTransfrom(string value) { if (GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ResetPosRot rpp)) { rpp.isReset = true; } } public void CloseResetTransfrom(string value) { if (GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ResetPosRot rpp)) { rpp.isReset = false; } } public void OpenQuestion(Action callBack) { if (MVC.GetModel().modeType == ModeType.KaoHe) { GameManager.Instance.uiManager.ShowUI(); GameManager.Instance.uiManager.GetUI().ShowQuestion(bData.state, callBack); } else { callBack?.Invoke(); } } public void OpenQuestion(int qid, Action callBack) { if (MVC.GetModel().modeType == ModeType.KaoHe) { GameManager.Instance.uiManager.ShowUI(); GameManager.Instance.uiManager.GetUI().ShowQuestion(qid, callBack); } else { callBack?.Invoke(); } } /// /// 改变VR手的材质 /// /// public void ChangeHandMaterial(int i) { HandModelSelector hms = GameManager.Instance.playerManager.player.GetComponentInChildren(); if (hms) { hms.ChangeHandsModel(i, false); } } /// /// 控制VR手的显示与隐藏 /// /// 0-左 1-右 /// true 显示 false 隐藏 public void HandVisiable(int hand, bool visable) { if (hands.Length == 0) return; for (int i = 0; i < hands.Length; i++) { if (hands[i].ControllerHand == ControllerHand.Left && hand == 0) { hands[i].gameObject.SetActive(visable); } if (hands[i].ControllerHand == ControllerHand.Right && hand == 1) { hands[i].gameObject.SetActive(visable); } } } } }