2025-09-08 17:37:12 +08:00

395 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<FSMManager>
{
[HideInInspector]
public bool nextState;
public GameModel gameModel;
public Main.GameModel main_gameModel;
public string tipString;
bool tip;
//string gudieTxt_kaoHe;
//bool tip;
public void Init()
{
gameModel = MVC.GetModel<GameModel>();
main_gameModel = MVC.GetModel<Main.GameModel>();
StartCoroutine(InitData(ChangeStateEvent));
}
private void ChangeStateEvent(string stateName)
{
gameModel.ChangeState(stateName);
if (gameModel.bData != null)
{
InteractionDisableAll();
GameManager.Instance.uiManager.CloseUI<PopPanel>();
GameManager.Instance.uiManager.CloseUI<ImgSelectQuestionPanel>();
GameManager.Instance.uiManager.CloseUI<DragQuestionPanel>();
GameManager.Instance.uiManager.CloseUI<LineQuestionPanel>();
GameManager.Instance.uiManager.CloseUI<TxtSelectQuestionPanel>();
GameManager.Instance.uiManager.CloseUI<BookPanel>();
GameManager.Instance.uiManager.CloseUI<ShiXunPanel>();
GameManager.Instance.uiManager.CloseUI<ArrowPanel>();
GameManager.Instance.uiManager.CloseUI<SpeakPanel>();
GameManager.Instance.uiManager.CloseUI<VideoPanel>();
GameManager.Instance.uiManager.CloseUI<TipBtnPanel>();
GameManager.Instance.highLightManager.HideAllHighLight();
GameManager.Instance.sceneDataHandler.SaveSceneDataToJson(main_gameModel.mainData.folder + "/SaveData/" + stateName + ".json");
GameManager.Instance.uiManager.GetUI<TipPanel>().AddTip(gameModel.bData.txt);
GameManager.Instance.uiManager.GetUI<TreeViewPanel>().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<PopPanel>(null, new string[] { str });
//}
//public void ClosePopText()
//{
// GameManager.Instance.uiManager.CloseUI<PopPanel>();
//}
public void ShowTip(int i,bool isKaohe = false)
{
if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) return;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ʾ
GameManager.Instance.uiManager.GetUI<TipPanel>().ShowTip(i);
GameManager.Instance.uiManager.ShowUI<TipPanel>();
}
public void HideTip()
{
GameManager.Instance.uiManager.CloseUI<TipPanel>();
}
public void ShowCamera(string value)
{
GameManager.Instance.virtualCameraManager.ShowCamera(value);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void PlayBgm(int id, bool isKaohe = false)
{
if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) return;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ʾ
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];
}
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
public void Show(string value)
{
GameManager.Instance.interactionManager._allInteraction[value].SetActive(true);
}
//<2F><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>
public void Hide(string value)
{
GameManager.Instance.interactionManager._allInteraction[value].SetActive(false);
}
//<2F><><EFBFBD><EFBFBD>Down<77><6E><EFBFBD><EFBFBD>
public void InteractionDown(string value, Action<GameObject> callBack)
{
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IDown down);
down?.Down(callBack);
}
//<2F><><EFBFBD><EFBFBD>Down<77><6E><EFBFBD><EFBFBD>
public void InteractionUp(string value, Action<GameObject> callBack)
{
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IUp up);
up?.Up(callBack);
}
//<2F><><EFBFBD><EFBFBD>Stay<61><79><EFBFBD><EFBFBD>
public void InteractionStay(string value, Action<GameObject> callBack)
{
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IStay stay);
stay?.Stay(callBack);
}
//<2F><><EFBFBD><EFBFBD>Trigger<65><72><EFBFBD><EFBFBD>
public void InteractionTrigger(string value, Action<GameObject> callBack)
{
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ITrigger trigger);
trigger?.Trigger(callBack);
}
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
public void Light(string value, bool isKaohe = false)
{
if (main_gameModel.modeType == ModeType.KaoHe && !isKaohe) return;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Game.Instance.eventManager.Raise(new HighLightEvent()
{
name = value,
visiable = true
});
}
/// <summary>
/// <20>򿪸<EFBFBD><F2BFAAB8><EFBFBD> <20>򿪽<EFBFBD><F2BFAABD><EFBFBD>
/// </summary>
public void Light_EnableInteraction(string value, bool isKaohe = false)
{
Light(value,isKaohe);
GameManager.Instance.interactionManager.EnableInteraction(value);
}
//<2F><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
public void Unlight(string value)
{
Game.Instance.eventManager.Raise(new HighLightEvent()
{
name = value,
visiable = false
});
}
/// <summary>
/// <20>رո<D8B1><D5B8><EFBFBD> <20>رս<D8B1><D5BD><EFBFBD>
/// </summary>
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);
}
}
//<2F><><EFBFBD><EFBFBD>Timeline
Coroutine coroutine;
public void PlayClip(string value, Action callBack = null)
{
float t = GetClipLength(value);
if (t > 0.1f) GameManager.Instance.uiManager.GetUI<TreeViewPanel>().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<TreeViewPanel>().UnLockAllBtn();
callBack?.Invoke();
}));
}
}
IEnumerator WaitExecute(float length, Action callBack)
{
yield return new WaitForSeconds(length);
callBack?.Invoke();
}
//ʱ<><CAB1>Timeline
public float GetClipLength(string value)
{
return GameManager.Instance.timelineManager.GetNormalTime(value);
}
/// <summary>
/// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> <20>򿪸<EFBFBD><F2BFAAB8><EFBFBD>
/// </summary>
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);
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>رո<D8B1><D5B8><EFBFBD>
/// </summary>
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>();
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 ShowImgQuestion(int id, int score, int scoreId, Action nextFun)
{
ImgSelectQuestionPanel imgSelectQuestionPanel = GameManager.Instance.uiManager.GetUI<ImgSelectQuestionPanel>();
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>();
dragQuestionPanel.ShowDragQuestion(id);
dragQuestionPanel.nextAction = nextFun;
dragQuestionPanel.subAction = (a, b) => {
if (a)
{
AddScore(score, scoreId);
}
else
{
AddScore(0, scoreId);
}
};
}
public void ShowLineQuestion(int id, int score, int scoreId, Action nextFun)
{
LineQuestionPanel lineQuestionPanel = GameManager.Instance.uiManager.GetUI<LineQuestionPanel>();
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<TipBtnPanel>().tip == false)
{
GameManager.Instance.kaoheManager.AddScore(score, id, (s, t) => {
GameManager.Instance.uiManager.GetUI<ScorePanel>().SetScore(s.ToString(), t.ToString());
});
}
GameManager.Instance.uiManager.GetUI<TipBtnPanel>().tip = false;
}
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<ArrowPanel>().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<ArrowPanel>().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<ArrowPanel>().ShowArrow(GameManager.Instance.interactionManager._allInteraction[objName].transform,txt, arrowType, showtime, hidetime);
}
public void HideArrow()
{
GameManager.Instance.uiManager.CloseUI<ArrowPanel>();
}
public void ShowTipBtn(Action action,int showt = 2)
{
if (main_gameModel.modeType == ModeType.ShiXun) return;
GameManager.Instance.uiManager.GetUI<TipBtnPanel>().ShowTipBtn(action, showt);
}
public void HideTipBtn()
{
GameManager.Instance.uiManager.CloseUI<TipBtnPanel>();
}
public void ShowSlider(Vector2 v,float maxValue, float minValue, float initValue,Action<float> updateaction, Action<float> okaction)
{
GameManager.Instance.uiManager.GetUI<SliderPanel>().ShowPanel(v, maxValue, minValue, initValue, updateaction, okaction);
}
public void HideSlider()
{
GameManager.Instance.uiManager.CloseUI<SliderPanel>();
}
public void ShowSpeakPanel(Vector3 TransformWorldPlacement, string speakTxt, string keyword, int showtime, int hidetime, Action<int,string> action)
{
GameManager.Instance.uiManager.GetUI<SpeakPanel>().SetTransformWorldPlacement(TransformWorldPlacement);
if (main_gameModel.modeType == ModeType.ShiXun)
{
GameManager.Instance.uiManager.GetUI<SpeakPanel>().ShowSpeakPanel(speakTxt, keyword, true, true, showtime, hidetime, action);
}
else
{
GameManager.Instance.uiManager.GetUI<SpeakPanel>().ShowSpeakPanel(speakTxt, keyword, false, true, showtime, hidetime, action);
}
}
public void ShowNextPanel(Action action)
{
GameManager.Instance.uiManager.GetUI<NextPanel>().ShowPanel(action);
}
public void ShowVideoPanel(string path,Action action)
{
GameManager.Instance.uiManager.GetUI<VideoPanel>().ShowVideo(path,action);
}
public void HideVideoPanel()
{
GameManager.Instance.uiManager.CloseUI<VideoPanel>();
}
}
}