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

192 lines
4.1 KiB
C#
Raw Normal View History

2024-05-22 19:08:14 +08:00
using cfg.GuideCfg;
2024-05-24 15:07:50 +08:00
using Framework;
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;
using System.IO;
2024-05-22 19:08:14 +08:00
using UnityEngine;
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
{
/// <summary>
/// 引导步骤类型
/// </summary>
public string StepType;
2024-05-24 19:11:19 +08:00
/// <summary>
/// 引导配置
/// </summary>
public DataGuideCfg Cfg { get; private set; }
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-22 19:08:14 +08:00
public GuideStepBase(DataGuideCfg dataGuideCfg)
{
2024-05-24 19:11:19 +08:00
Cfg = dataGuideCfg;
GuideState = E_GuideState.Idle;
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()
{ }
/// <summary>
/// 引导
/// </summary>
protected abstract void DoGuide();
/// <summary>
/// 引导完成之前
/// </summary>
protected virtual void DoBeforeComplete()
{ }
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-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
{
public ClickButtonStep(DataGuideCfg dataGuideCfg) : base(dataGuideCfg)
{
}
2024-05-24 15:07:50 +08:00
protected override void DoGuide()
{
}
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)
throw new Exception($"引导类型:{StepType}参数错误");
videoPath = cfg.GuideTypeParams[0];
}
protected override void DoBeforeGuide()
{
EventManager.Instance.Register(EventManager.EventName.PlayVideoComplete, (Action<string>)OnPlayVideoComplete);
}
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);
}
protected override void DoBeforeComplete()
{
EventManager.Instance.Unregister(EventManager.EventName.PlayVideoComplete, (Action<string>)OnPlayVideoComplete);
}
/// <summary>
/// 播放视频完成回调
/// </summary>
/// <param name="path"></param>
private void OnPlayVideoComplete(string path)
{
if (path != videoPath)
return;
2024-05-27 13:32:18 +08:00
DebugUtil.Log($"<color=#00FA9A>完成播放视频{videoPath}引导步骤</color>"); // 绿色
Complete();
}
}
/// <summary>
/// 第一次进入主界面
/// </summary>
public class FirstEnterMain : GuideStepBase
{
public FirstEnterMain(DataGuideCfg dataGuideCfg) : base(dataGuideCfg)
{
}
protected override void DoBeforeGuide()
{
EventManager.Instance.Register(EventManager.EventName.UIOpen, (Action<string>)OnEnterMainComplete);
}
protected override void DoGuide()
{
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor()).Forget();
}
protected override void DoBeforeComplete()
{
EventManager.Instance.Unregister(EventManager.EventName.UIOpen, (Action<string>)OnEnterMainComplete);
}
private void OnEnterMainComplete(string uiName)
{
if (UINameConst.UI_MainPanel != uiName)
return;
DebugUtil.Log($"<color=#00FA9A>完成第一次进入主界面引导步骤</color>"); // 绿色
2024-05-24 15:07:50 +08:00
Complete();
2024-05-22 19:08:14 +08:00
}
}