112 lines
3.3 KiB
C#
112 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class SubwayCenter : Singleton<SubwayCenter>
|
|
{
|
|
#region 部分索引
|
|
|
|
public BubbleSlotGroup subwaySlots;
|
|
public BubbleSlotGroup tvSlots;
|
|
|
|
public CinemachineVirtualCamera subwayCam;
|
|
public CinemachineVirtualCamera tvCam;
|
|
|
|
public PlayableDirector arriveStation;
|
|
|
|
public static StateMachine<OutSideState> StateMachine { get; private set; }
|
|
|
|
#endregion
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Subway, subwayCam);
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.SubwayTV, tvCam);
|
|
|
|
StateMachine = new StateMachine<OutSideState>(CreateState);
|
|
StartCoroutine(StateMachine.Init(OutSideState.Subway));
|
|
}
|
|
|
|
public override void OnSingletonDestroy()
|
|
{
|
|
CameraKit.Instance.UnRegisterCamera(CameraEnum.SubwayTV);
|
|
CameraKit.Instance.UnRegisterCamera(CameraEnum.Subway);
|
|
}
|
|
|
|
private static IState<OutSideState> CreateState(OutSideState nextState, string arg = "")
|
|
{
|
|
IState<OutSideState> res = nextState switch
|
|
{
|
|
OutSideState.Subway => new SubwayState(),
|
|
OutSideState.SubwayTV => new SubwayTVState(),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(nextState), nextState, null)
|
|
};
|
|
|
|
res.SetArgs(arg);
|
|
return res;
|
|
}
|
|
|
|
public IEnumerator ArriveAtStation()
|
|
{
|
|
arriveStation.Play();
|
|
yield return new WaitForSeconds((float) arriveStation.playableAsset.duration);
|
|
}
|
|
}
|
|
|
|
public struct SubwayState : IState<OutSideState>
|
|
{
|
|
public OutSideState GetState => OutSideState.Subway;
|
|
|
|
public IEnumerator Enter()
|
|
{
|
|
yield return CameraKit.Instance.SwitchCamera(CameraEnum.Subway);
|
|
BubbleGroup.Instance.LoadBubbles(SubwayCenter.Instance.subwaySlots.CollectData());
|
|
}
|
|
}
|
|
|
|
public struct SubwayTVState : IState<OutSideState>
|
|
{
|
|
public OutSideState GetState => OutSideState.SubwayTV;
|
|
|
|
public IEnumerator Enter()
|
|
{
|
|
yield return CameraKit.Instance.SwitchCamera(CameraEnum.SubwayTV);
|
|
// 要加载气泡吗?
|
|
BubbleGroup.Instance.LoadBubbles(SubwayCenter.Instance.tvSlots.CollectData());
|
|
}
|
|
}
|
|
|
|
public enum OutSideState
|
|
{
|
|
Subway,
|
|
SubwayTV
|
|
}
|
|
|
|
public static class SubwayYarnCommand
|
|
{
|
|
[YarnCommand("switch_outside_to")]
|
|
public static IEnumerator SwitchOutsideTo(string targetStateStr)
|
|
{
|
|
if (!Enum.TryParse(targetStateStr, out OutSideState targetState))
|
|
{
|
|
Debug.Log($"{targetStateStr}不在OutSideState枚举中");
|
|
yield break;
|
|
}
|
|
|
|
yield return SubwayCenter.StateMachine.SwitchState(targetState);
|
|
}
|
|
|
|
[YarnCommand("arrive_at_station")]
|
|
public static IEnumerator ArriveAtStation()
|
|
{
|
|
return SubwayCenter.Instance.ArriveAtStation();
|
|
}
|
|
}
|
|
} |