NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Guide/GuideStep.cs

213 lines
4.7 KiB
C#
Raw Normal View History

2024-05-22 19:08:14 +08:00
using cfg.GuideCfg;
2024-05-27 13:32:18 +08:00
using Gameplay.SubSystems;
using Gameplay;
2024-05-24 15:07:50 +08:00
using System;
2024-05-27 13:32:18 +08:00
using Cysharp.Threading.Tasks;
2024-05-22 19:08:14 +08:00
2024-05-24 15:07:50 +08:00
/// <summary>
/// 引导状态
/// </summary>
public enum E_GuideState
{
/// <summary>
2024-05-24 19:11:19 +08:00
/// 等待引导
2024-05-24 15:07:50 +08:00
/// </summary>
2024-05-24 19:11:19 +08:00
Idle,
2024-05-24 15:07:50 +08:00
/// <summary>
/// 引导中
/// </summary>
Guiding,
/// <summary>
/// 引导完成
/// </summary>
Complete,
}
2024-05-22 19:08:14 +08:00
/// <summary>
/// 引导步骤基类
/// </summary>
public abstract class GuideStepBase
{
2024-05-27 15:39:03 +08:00
/// <summary>
/// 引导完成类型
/// </summary>
2024-05-27 18:10:15 +08:00
private readonly GuideCompleteBase completeBase;
2024-05-27 15:39:03 +08:00
2024-05-24 19:11:19 +08:00
/// <summary>
/// 引导配置
/// </summary>
public DataGuideCfg Cfg { get; private set; }
2024-05-27 18:10:15 +08:00
2024-05-24 15:07:50 +08:00
/// <summary>
/// 引导状态
/// </summary>
2024-05-24 19:11:19 +08:00
public E_GuideState GuideState { get; private set; }
2024-05-24 15:07:50 +08:00
2024-05-27 15:39:03 +08:00
public GuideStepBase(DataGuideCfg cfg)
2024-05-22 19:08:14 +08:00
{
2024-05-27 15:39:03 +08:00
Cfg = cfg;
2024-05-24 19:11:19 +08:00
GuideState = E_GuideState.Idle;
2024-05-27 15:39:03 +08:00
2024-05-27 18:10:15 +08:00
completeBase = Cfg.CompleteType switch // TODO 方便测试,后续配置改枚举
2024-05-27 15:39:03 +08:00
{
2024-05-27 16:57:51 +08:00
"播放视频结束" => new PlayVideoComplete(Cfg, Complete),
2024-05-27 15:39:03 +08:00
"打开界面" => new OpenUIComplete(Cfg, Complete),
2024-05-28 13:40:44 +08:00
"关闭界面" => new CloseUIComplete(Cfg, Complete),
2024-05-27 16:57:51 +08:00
"打开界面并等动画播放完成" => new OpenUIAndAnimComplete(Cfg, Complete),
2024-05-27 15:39:03 +08:00
"" => default,
_ => throw new Exception($"未处理类型:{Cfg.CompleteType}"),
};
2024-05-24 15:07:50 +08:00
}
2024-05-27 15:39:03 +08:00
/// <summary>
/// 开始引导
/// </summary>
2024-05-24 15:07:50 +08:00
public void StartGuide()
{
DoBeforeGuide();
2024-05-24 19:11:19 +08:00
GuideState = E_GuideState.Guiding;
2024-05-24 15:07:50 +08:00
DoGuide();
2024-05-22 19:08:14 +08:00
}
2024-05-24 15:07:50 +08:00
2024-05-27 13:32:18 +08:00
/// <summary>
/// 引导开始之前
/// </summary>
protected virtual void DoBeforeGuide()
2024-05-27 15:39:03 +08:00
{
completeBase.AddListener();
}
2024-05-27 13:32:18 +08:00
/// <summary>
/// 引导
/// </summary>
protected abstract void DoGuide();
/// <summary>
/// 引导完成之前
/// </summary>
protected virtual void DoBeforeComplete()
2024-05-27 15:39:03 +08:00
{
completeBase.RemoveListener();
}
2024-05-27 13:32:18 +08:00
2024-05-24 15:07:50 +08:00
/// <summary>
/// 完成引导
/// </summary>
public void Complete()
{
2024-05-24 19:11:19 +08:00
if (E_GuideState.Idle == GuideState)
2024-05-24 15:07:50 +08:00
return;
2024-05-24 19:11:19 +08:00
if (E_GuideState.Complete == GuideState)
2024-05-24 15:07:50 +08:00
return;
2024-05-27 15:39:03 +08:00
DebugUtil.Log($"<color=#00FA9A>完成id为{Cfg.Id}的引导</color>"); // #00FA9A绿色
2024-05-24 19:11:19 +08:00
GuideState = E_GuideState.Complete;
2024-05-24 15:07:50 +08:00
DoBeforeComplete();
2024-05-24 19:11:19 +08:00
GuideManager.Instance.CompleteStep(this);
2024-05-24 15:07:50 +08:00
}
2024-05-22 19:08:14 +08:00
}
/// <summary>
/// 点击按钮
/// </summary>
public class ClickButtonStep : GuideStepBase
{
2024-05-27 15:39:03 +08:00
/// <summary>
/// UI名
/// </summary>
private readonly string uiName;
/// <summary>
/// 按钮路径
/// </summary>
private readonly string buttonPath;
public ClickButtonStep(DataGuideCfg cfg) : base(cfg)
2024-05-22 19:08:14 +08:00
{
2024-05-27 15:39:03 +08:00
if (cfg.GuideTypeParams.Length <= 1)
2024-05-27 18:10:15 +08:00
throw new Exception($"引导类型:{Cfg.GuideType},参数错误");
2024-05-27 15:39:03 +08:00
uiName = cfg.GuideTypeParams[0];
buttonPath = cfg.GuideTypeParams[1];
2024-05-22 19:08:14 +08:00
}
2024-05-24 15:07:50 +08:00
2024-05-28 18:47:23 +08:00
protected override async void DoBeforeComplete()
{
base.DoBeforeComplete();
await UI_GuideController.Open();
}
2024-05-27 15:39:03 +08:00
protected override async void DoGuide()
2024-05-24 15:07:50 +08:00
{
2024-05-28 16:19:56 +08:00
await UI_GuideController.Open(uiName, buttonPath, Cfg);
2024-05-24 15:07:50 +08:00
}
2024-05-22 19:08:14 +08:00
}
2024-05-24 15:07:50 +08:00
/// <summary>
/// 播放视频
/// </summary>
2024-05-22 19:08:14 +08:00
public class PlayVideoStep : GuideStepBase
{
2024-05-24 15:07:50 +08:00
/// <summary>
/// 视频路径
/// </summary>
private readonly string videoPath;
public PlayVideoStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
2024-05-27 18:10:15 +08:00
throw new Exception($"引导类型:{Cfg.GuideType},参数错误");
2024-05-24 15:07:50 +08:00
videoPath = cfg.GuideTypeParams[0];
}
protected override async void DoGuide()
2024-05-22 19:08:14 +08:00
{
2024-05-24 15:07:50 +08:00
await UI_PlayVideoController.Open(videoPath);
}
2024-05-27 13:32:18 +08:00
}
/// <summary>
/// 第一次进入主界面
/// </summary>
2024-05-28 13:40:44 +08:00
public class FirstEnterMainStep : GuideStepBase
2024-05-27 13:32:18 +08:00
{
2024-05-28 13:40:44 +08:00
public FirstEnterMainStep(DataGuideCfg cfg) : base(cfg)
2024-05-27 13:32:18 +08:00
{
}
protected override void DoGuide()
{
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor()).Forget();
}
2024-05-28 13:40:44 +08:00
}
/// <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.GuideType},参数错误");
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
}
protected override async void DoGuide()
{
await UI_GuideTipController.Open(guideTipCfgId);
}
2024-05-22 19:08:14 +08:00
}