using cfg.GuideCfg;
using Gameplay.SubSystems;
using Gameplay;
using System;
using Cysharp.Threading.Tasks;
///
/// 引导状态
///
public enum E_GuideState
{
///
/// 等待引导
///
Idle,
///
/// 引导中
///
Guiding,
///
/// 引导完成
///
Complete,
}
///
/// 引导步骤基类
///
public abstract class GuideStepBase
{
///
/// 引导完成类型
///
private readonly GuideCompleteBase completeBase;
///
/// 引导配置
///
public DataGuideCfg Cfg { get; private set; }
///
/// 引导状态
///
public E_GuideState GuideState { get; private set; }
///
/// 是否引导中
///
public bool IsGuiding
{
get { return E_GuideState.Guiding == GuideState; }
}
public GuideStepBase(DataGuideCfg cfg)
{
Cfg = cfg;
GuideState = E_GuideState.Idle;
completeBase = Cfg.GuideCompleteType switch
{
E_GuideCompleteType.PlayVideoOver => new PlayVideoComplete(Cfg, Complete),
E_GuideCompleteType.OpenUI => new OpenUIComplete(Cfg, Complete),
E_GuideCompleteType.CloseUI => new CloseUIComplete(Cfg, Complete),
E_GuideCompleteType.OpenUIAndAnim => new OpenUIAndAnimComplete(Cfg, Complete),
_ => throw new Exception($"未处理类型:{Cfg.GuideCompleteType}"),
};
}
///
/// 开始引导
///
public void StartGuide()
{
DoBeforeGuide();
GuideState = E_GuideState.Guiding;
DoGuide();
}
///
/// 引导开始之前
///
protected virtual void DoBeforeGuide()
{
completeBase.AddListener();
}
///
/// 引导
///
protected abstract void DoGuide();
///
/// 引导完成之前
///
protected virtual void DoBeforeComplete()
{
completeBase.RemoveListener();
}
///
/// 完成引导
///
public void Complete()
{
if (E_GuideState.Idle == GuideState)
return;
if (E_GuideState.Complete == GuideState)
return;
DebugUtil.Log($"完成id为{Cfg.Id}的引导"); // #00FA9A绿色
GuideState = E_GuideState.Complete;
DoBeforeComplete();
GuideManager.Instance.CompleteStep(this);
}
///
/// 结束引导
///
public void EndGuide()
{
if (!IsGuiding)
return;
GuideState = E_GuideState.Idle;
completeBase.RemoveListener();
}
}
///
/// 点击按钮
///
public class ClickButtonStep : GuideStepBase
{
///
/// UI名
///
private readonly string uiName;
///
/// 按钮路径
///
private readonly string buttonPath;
public ClickButtonStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 1)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
uiName = cfg.GuideTypeParams[0];
buttonPath = cfg.GuideTypeParams[1];
}
protected override async void DoBeforeComplete()
{
base.DoBeforeComplete();
await UI_GuideController.Open();
}
protected override async void DoGuide()
{
await UI_GuideController.Open(uiName, buttonPath, Cfg);
}
}
///
/// 播放视频
///
public class PlayVideoStep : GuideStepBase
{
///
/// 视频路径
///
private readonly string videoPath;
public PlayVideoStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
videoPath = cfg.GuideTypeParams[0];
}
protected override async void DoGuide()
{
await UI_PlayVideoController.Open(videoPath);
}
}
///
/// 第一次进入主界面
///
public class FirstEnterMainStep : GuideStepBase
{
public FirstEnterMainStep(DataGuideCfg cfg) : base(cfg)
{
}
protected override void DoGuide()
{
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor()).Forget();
}
}
///
/// 显示引导提示
///
public class ShowGuideTipStep : GuideStepBase
{
///
/// 引导提示配置id
///
private int guideTipCfgId;
public ShowGuideTipStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
}
protected override async void DoGuide()
{
await UI_GuideTipController.Open(guideTipCfgId);
}
}