232 lines
5.1 KiB
C#
232 lines
5.1 KiB
C#
using cfg.GuideCfg;
|
|
using Gameplay.SubSystems;
|
|
using Gameplay;
|
|
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// 引导状态
|
|
/// </summary>
|
|
public enum E_GuideState
|
|
{
|
|
/// <summary>
|
|
/// 等待引导
|
|
/// </summary>
|
|
Idle,
|
|
/// <summary>
|
|
/// 引导中
|
|
/// </summary>
|
|
Guiding,
|
|
/// <summary>
|
|
/// 引导完成
|
|
/// </summary>
|
|
Complete,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 引导步骤基类
|
|
/// </summary>
|
|
public abstract class GuideStepBase
|
|
{
|
|
/// <summary>
|
|
/// 引导完成类型
|
|
/// </summary>
|
|
private readonly GuideCompleteBase completeBase;
|
|
|
|
/// <summary>
|
|
/// 引导配置
|
|
/// </summary>
|
|
public DataGuideCfg Cfg { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 引导状态
|
|
/// </summary>
|
|
public E_GuideState GuideState { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 是否引导中
|
|
/// </summary>
|
|
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}"),
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始引导
|
|
/// </summary>
|
|
public void StartGuide()
|
|
{
|
|
DoBeforeGuide();
|
|
|
|
GuideState = E_GuideState.Guiding;
|
|
|
|
DoGuide();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 引导开始之前
|
|
/// </summary>
|
|
protected virtual void DoBeforeGuide()
|
|
{
|
|
completeBase.AddListener();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 引导
|
|
/// </summary>
|
|
protected abstract void DoGuide();
|
|
|
|
/// <summary>
|
|
/// 引导完成之前
|
|
/// </summary>
|
|
protected virtual void DoBeforeComplete()
|
|
{
|
|
completeBase.RemoveListener();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 完成引导
|
|
/// </summary>
|
|
public void Complete()
|
|
{
|
|
if (E_GuideState.Idle == GuideState)
|
|
return;
|
|
|
|
if (E_GuideState.Complete == GuideState)
|
|
return;
|
|
|
|
DebugUtil.Log($"<color=#00FA9A>完成id为{Cfg.Id}的引导</color>"); // #00FA9A绿色
|
|
|
|
GuideState = E_GuideState.Complete;
|
|
DoBeforeComplete();
|
|
GuideManager.Instance.CompleteStep(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结束引导
|
|
/// </summary>
|
|
public void EndGuide()
|
|
{
|
|
if (!IsGuiding)
|
|
return;
|
|
|
|
GuideState = E_GuideState.Idle;
|
|
completeBase.RemoveListener();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点击按钮
|
|
/// </summary>
|
|
public class ClickButtonStep : GuideStepBase
|
|
{
|
|
/// <summary>
|
|
/// UI名
|
|
/// </summary>
|
|
private readonly string uiName;
|
|
/// <summary>
|
|
/// 按钮路径
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放视频
|
|
/// </summary>
|
|
public class PlayVideoStep : GuideStepBase
|
|
{
|
|
/// <summary>
|
|
/// 视频路径
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 第一次进入主界面
|
|
/// </summary>
|
|
public class FirstEnterMainStep : GuideStepBase
|
|
{
|
|
public FirstEnterMainStep(DataGuideCfg cfg) : base(cfg)
|
|
{
|
|
}
|
|
|
|
protected override void DoGuide()
|
|
{
|
|
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor()).Forget();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示引导提示
|
|
/// </summary>
|
|
public class ShowGuideTipStep : GuideStepBase
|
|
{
|
|
/// <summary>
|
|
/// 引导提示配置id
|
|
/// </summary>
|
|
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);
|
|
}
|
|
} |