467 lines
15 KiB
C#
467 lines
15 KiB
C#
using BNG;
|
||
using FSM;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
using ZXKFramework;
|
||
|
||
namespace YiLiao.SiBuChuZhen
|
||
{
|
||
public class FSMManager : FsmBase<FSMManager>
|
||
{
|
||
[HideInInspector]
|
||
public bool nextState;
|
||
|
||
//ÊÖ²¿Ä£ÐÍ
|
||
ControllerOffsetHelper[] hands;
|
||
public BaseData bData;
|
||
public QuestionData qData;
|
||
public void Init()
|
||
{
|
||
StartCoroutine(InitData(ChangeStateEvent));
|
||
hands = GameManager.Instance.playerManager.player.GetComponentsInChildren<ControllerOffsetHelper>();
|
||
}
|
||
private void ChangeStateEvent(string stateName)
|
||
{
|
||
bData = MVC.GetModel<GameModel>().excelData.GetBaseDatastate(stateName);
|
||
qData = MVC.GetModel<GameModel>().excelData.GetQuestionDatastate(stateName);
|
||
if (bData != null && bData.modeType.Split('|').Contains(MVC.GetModel<Main.GameModel>().modeType.ToString()))
|
||
{
|
||
if (bData.isBtn == "True")
|
||
{
|
||
GameManager.Instance.sceneDataHandler.SaveSceneDataToJson(MVC.GetModel<Main.GameModel>().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));//¸Ä±äÊֵIJÄÖÊ
|
||
}
|
||
if (MVC.GetModel<Main.GameModel>().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<TipPanel>().ShowConfirmGroup(value, callBack);
|
||
}
|
||
else
|
||
{
|
||
if (MVC.GetModel<Main.GameModel>().modeType == ModeType.ShiXun)
|
||
{
|
||
GameManager.Instance.uiManager.GetUI<TipPanel>().AddText(value);
|
||
}
|
||
}
|
||
}
|
||
public void AddButtonByID(int value)
|
||
{
|
||
GameManager.Instance.uiManager.GetUI<TipPanel>().AddBtnByID(value);
|
||
}
|
||
public void HighlightText(int value)
|
||
{
|
||
GameManager.Instance.uiManager.GetUI<TipPanel>().HighlightText(value);
|
||
}
|
||
public void ScrollToButton(int value)
|
||
{
|
||
GameManager.Instance.uiManager.GetUI<TipPanel>().ScrollTo(value);
|
||
}
|
||
public void ShowCamera(string value)
|
||
{
|
||
GameManager.Instance.virtualCameraManager.ShowCamera(value);
|
||
}
|
||
public void PlayVideo(string path, Action callBack = null)
|
||
{
|
||
GameManager.Instance.uiManager.GetUI<TipPanel>().ShowVideo(path, callBack);
|
||
}
|
||
//²¥·ÅÓïÒô
|
||
public void PlayBgm(string path)
|
||
{
|
||
if (MVC.GetModel<Main.GameModel>().modeType == ModeType.ShiXun)
|
||
{
|
||
Game.Instance.eventManager.Raise(new PlaySoundEvent()
|
||
{
|
||
path = path
|
||
});
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// ÉèÖÃÎïÌåµÄ¸¸ÎïÌåΪNull
|
||
/// </summary>
|
||
/// <param name="name"></param>
|
||
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<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IDown down);
|
||
down?.Down(callBack);
|
||
}
|
||
//Ìí¼ÓUp½»»¥
|
||
public void InteractionUp(string value, Action<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IUp up);
|
||
up?.Up(callBack);
|
||
}
|
||
//Ìí¼ÓStay½»»¥
|
||
public void InteractionStay(string value, Action<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IStay stay);
|
||
stay?.Stay(callBack);
|
||
}
|
||
//Ìí¼ÓEnter½»»¥
|
||
public void InteractionEnter(string value, Action<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IEnter enter);
|
||
enter?.Enter(callBack);
|
||
}
|
||
//Ìí¼ÓExit½»»¥
|
||
public void InteractionExit(string value, Action<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out IExit exit);
|
||
exit?.Exit(callBack);
|
||
}
|
||
//Ìí¼ÓTrigger½»»¥
|
||
public void InteractionTrigger(string value, Action<GameObject> callBack)
|
||
{
|
||
GameManager.Instance.interactionManager._allInteraction[value].TryGetComponent(out ITrigger trigger);
|
||
trigger?.Trigger(callBack);
|
||
}
|
||
//ÏÔʾ¸ßÁÁ
|
||
public void Light(string value)
|
||
{
|
||
if (MVC.GetModel<Main.GameModel>().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);
|
||
}
|
||
/// <summary>
|
||
/// ÏÔʾÎïÌå ´ò¿ª¸ßÁÁ
|
||
/// </summary>
|
||
public void Show_Light(string value)
|
||
{
|
||
Show(value);
|
||
Light(value);
|
||
}
|
||
/// <summary>
|
||
/// ´ò¿ª¸ßÁÁ ´ò¿ª½»»¥
|
||
/// </summary>
|
||
public void Light_EnableInteraction(string value)
|
||
{
|
||
Light(value);
|
||
EnableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// ÏÔʾÎïÌå ´ò¿ª¸ßÁÁ ´ò¿ª½»»¥
|
||
/// </summary>
|
||
public void Show_Light_EnableInteraction(string value)
|
||
{
|
||
Show(value);
|
||
Light(value);
|
||
EnableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ
|
||
/// </summary>
|
||
public void Hide_Unlight(string value)
|
||
{
|
||
Hide(value);
|
||
Unlight(value);
|
||
}
|
||
/// <summary>
|
||
/// Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥
|
||
/// </summary>
|
||
public void Hide_Unlight_DisableInteraction(string value)
|
||
{
|
||
Hide(value);
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥
|
||
/// </summary>
|
||
public void Unlight_DisableInteraction(string value)
|
||
{
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ
|
||
/// </summary>
|
||
public void Loose_Hide_Unlight(string value)
|
||
{
|
||
Loose(value);
|
||
Hide(value);
|
||
Unlight(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥
|
||
/// </summary>
|
||
public void Loose_Hide_Unlight_DisableInteraction(string value)
|
||
{
|
||
Loose(value);
|
||
Hide(value);
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
public void Loose_Hide_Unlight_ResetTransform(string value)
|
||
{
|
||
Loose(value);
|
||
Hide(value);
|
||
Unlight(value);
|
||
ResetTransfrom(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå Òþ²ØÎïÌå ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥ ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
public void Loose_Hide_Unlight_DisableInteraction_ResetTransform(string value)
|
||
{
|
||
Loose(value);
|
||
Hide(value);
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
ResetTransfrom(value);
|
||
}
|
||
/// <summary>
|
||
/// ¹Ø±Õ¸ßÁÁ ¹Ø±ÕÖØÖÃ
|
||
/// </summary>
|
||
public void Unlight_CloseResetTransform(string value)
|
||
{
|
||
Unlight(value);
|
||
CloseResetTransfrom(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå ¹Ø±Õ¸ßÁÁ
|
||
/// </summary>
|
||
public void Loose_Unlight(string value)
|
||
{
|
||
Loose(value);
|
||
Unlight(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥
|
||
/// </summary>
|
||
public void Loose_Unlight_DisableInteraction(string value)
|
||
{
|
||
Loose(value);
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå ¹Ø±Õ¸ßÁÁ ¹Ø±Õ½»»¥ ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
public void Loose_Unlight_DisableInteraction_ResetTransform(string value)
|
||
{
|
||
Loose(value);
|
||
Unlight(value);
|
||
DisableInteraction(value);
|
||
ResetTransfrom(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå ¹Ø±Õ¸ßÁÁ ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
public void Loose_Unlight_ResetTransform(string value)
|
||
{
|
||
Loose(value);
|
||
Unlight(value);
|
||
ResetTransfrom(value);
|
||
}
|
||
/// <summary>
|
||
/// ËÉ¿ªÎïÌå ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
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();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// ´ò¿ª½»»¥ ÖØÖÃλÖÃ
|
||
/// </summary>
|
||
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<Main.GameModel>().modeType == ModeType.KaoHe)
|
||
{
|
||
GameManager.Instance.uiManager.ShowUI<QuestionPanel>();
|
||
GameManager.Instance.uiManager.GetUI<QuestionPanel>().ShowQuestion(bData.state, callBack);
|
||
}
|
||
else
|
||
{
|
||
callBack?.Invoke();
|
||
}
|
||
}
|
||
public void OpenQuestion(int qid, Action callBack)
|
||
{
|
||
if (MVC.GetModel<Main.GameModel>().modeType == ModeType.KaoHe)
|
||
{
|
||
GameManager.Instance.uiManager.ShowUI<QuestionPanel>();
|
||
GameManager.Instance.uiManager.GetUI<QuestionPanel>().ShowQuestion(qid, callBack);
|
||
}
|
||
else
|
||
{
|
||
callBack?.Invoke();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// ¸Ä±äVRÊֵIJÄÖÊ
|
||
/// </summary>
|
||
/// <param name="i"></param>
|
||
public void ChangeHandMaterial(int i)
|
||
{
|
||
HandModelSelector hms = GameManager.Instance.playerManager.player.GetComponentInChildren<HandModelSelector>();
|
||
if (hms)
|
||
{
|
||
hms.ChangeHandsModel(i, false);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// ¿ØÖÆVRÊÖµÄÏÔʾÓëÒþ²Ø
|
||
/// </summary>
|
||
/// <param name="hand">0-×ó 1-ÓÒ</param>
|
||
/// <param name="visable">true ÏÔʾ false Òþ²Ø</param>
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|