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

482 lines
14 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;
2024-05-24 15:07:50 +08:00
using System;
2024-05-27 13:32:18 +08:00
using Cysharp.Threading.Tasks;
2024-05-29 16:36:30 +08:00
using Gameplay.Level;
2024-05-30 16:49:27 +08:00
using Framework;
2024-05-22 19:08:14 +08:00
2024-05-29 16:36:30 +08:00
namespace Gameplay.Guide
2024-05-24 15:07:50 +08:00
{
/// <summary>
/// 引导状态
/// </summary>
2024-05-29 16:36:30 +08:00
public enum E_GuideState
{
/// <summary>
/// 等待引导
/// </summary>
Idle,
/// <summary>
/// 引导中
/// </summary>
Guiding,
/// <summary>
/// 引导完成
/// </summary>
Complete,
}
2024-05-24 15:07:50 +08:00
2024-05-29 13:04:51 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 引导步骤基类
2024-05-29 13:04:51 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
public abstract class GuideStepBase
2024-05-29 13:04:51 +08:00
{
2024-05-29 16:36:30 +08:00
/// <summary>
/// 引导完成类型
/// </summary>
2024-05-30 19:55:53 +08:00
private readonly GuideCompleteBase completeBase;
2024-05-29 16:36:30 +08:00
/// <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; }
}
2024-05-29 13:04:51 +08:00
2024-05-29 16:36:30 +08:00
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),
E_GuideCompleteType.EnterLevelComplete => new EnterLevelComplete(Cfg, Complete),
E_GuideCompleteType.EmbattleComplete => new LevelEmbattleComplete(Cfg, Complete),
2024-05-30 15:01:43 +08:00
E_GuideCompleteType.FightBegin => new FightBeginComplete(Cfg, Complete),
2024-05-30 16:49:27 +08:00
E_GuideCompleteType.FightMoveComplete => new FightMoveComplete(Cfg, Complete),
2024-05-30 19:00:56 +08:00
E_GuideCompleteType.FightAttackComplete => new FightAttackComplete(Cfg, Complete),
2024-05-30 19:55:53 +08:00
E_GuideCompleteType.FightEmbattleComplete => new FightEmbattleComplete(Cfg, Complete),
E_GuideCompleteType.FightMoraleAndRepressionComplete => new FightMoraleAndRepressionComplete(Cfg, Complete),
2024-05-30 19:00:56 +08:00
E_GuideCompleteType.FightUseSkillComplete => new FightUseSkillComplete(Cfg, Complete),
2024-05-30 19:55:53 +08:00
E_GuideCompleteType.LevelComplete => new LevelComplete(Cfg, Complete),
2024-05-31 15:01:21 +08:00
E_GuideCompleteType.WaitTimeComplete => new WaitTimeComplete(Cfg, Complete),
2024-05-31 16:51:38 +08:00
E_GuideCompleteType.SelectModel => new SelectModeComplete(Cfg, Complete),
2024-05-31 19:02:13 +08:00
E_GuideCompleteType.SelectChapter => new SelectChapterComplete(Cfg, Complete),
2024-05-31 19:21:41 +08:00
E_GuideCompleteType.OpenCommandSkill => new OpenCommandSkillComplete(Cfg, Complete),
2024-06-03 14:10:55 +08:00
E_GuideCompleteType.CloseCommandSkill => new CloseCommandSkillComplete(Cfg, Complete),
2024-06-03 15:57:43 +08:00
E_GuideCompleteType.CharacterLevelUp => new CharacterLevelUpComplete(Cfg, Complete),
E_GuideCompleteType.ClickGuideButton => new ClickGuideButtonComplete(Cfg, Complete),
2024-05-29 16:36:30 +08:00
_ => throw new Exception($"未处理类型:{Cfg.GuideCompleteType}"),
};
}
/// <summary>
/// 开始引导
/// </summary>
public void StartGuide()
{
DoBeforeGuide();
GuideState = E_GuideState.Guiding;
2024-05-24 19:11:19 +08:00
2024-05-29 16:36:30 +08:00
DoGuide();
}
2024-05-27 15:39:03 +08:00
2024-05-29 16:36:30 +08:00
/// <summary>
/// 引导开始之前
/// </summary>
protected virtual void DoBeforeGuide()
2024-05-27 15:39:03 +08:00
{
2024-05-29 16:36:30 +08:00
completeBase.AddListener();
}
/// <summary>
/// 引导
/// </summary>
2024-05-30 16:49:27 +08:00
protected virtual void DoGuide()
{
EventManager.Instance.Send(EventManager.EventName.GuideStepBegin);
}
2024-05-29 16:36:30 +08:00
/// <summary>
/// 引导完成之前
/// </summary>
protected virtual void DoBeforeComplete()
{
completeBase.RemoveListener();
}
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
/// <summary>
/// 完成引导
/// </summary>
public void Complete()
{
2024-05-31 15:01:21 +08:00
if (!IsGuiding)
2024-05-29 16:36:30 +08:00
return;
DebugUtil.Log($"<color=#00FA9A>完成id为{Cfg.Id}的引导</color>"); // #00FA9A绿色
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
GuideState = E_GuideState.Complete;
DoBeforeComplete();
GuideManager.Instance.CompleteStep(this);
}
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
/// <summary>
/// 结束引导
/// </summary>
public void EndGuide()
{
if (!IsGuiding)
return;
GuideState = E_GuideState.Idle;
completeBase.RemoveListener();
}
2024-05-22 19:08:14 +08:00
}
2024-05-24 15:07:50 +08:00
2024-05-30 16:49:27 +08:00
/// <summary>
2024-05-31 15:01:21 +08:00
/// 等待指定时间引导步骤
2024-05-30 16:49:27 +08:00
/// </summary>
2024-05-31 15:01:21 +08:00
internal sealed class WaitTimeStep : GuideStepBase
2024-05-30 16:49:27 +08:00
{
/// <summary>
2024-05-31 15:01:21 +08:00
/// 等待时间(单位毫秒)
2024-05-30 16:49:27 +08:00
/// </summary>
private readonly int time;
2024-05-31 15:01:21 +08:00
public WaitTimeStep(DataGuideCfg cfg) : base(cfg)
2024-05-30 16:49:27 +08:00
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
if (float.TryParse(cfg.GuideTypeParams[0], out float t))
time = (int)(t * 1000f);
}
protected override async void DoGuide()
{
await UniTask.Delay(time);
base.DoGuide();
await UI_GuideController.Open();
}
protected override void DoBeforeComplete()
{
base.DoBeforeComplete();
UIManager.Instance.CloseWindow(UINameConst.UI_Guide);
}
}
2024-05-27 13:32:18 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 点击按钮
2024-05-27 13:32:18 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
internal sealed class ClickButtonStep : GuideStepBase
2024-05-27 15:39:03 +08:00
{
2024-05-29 16:36:30 +08:00
/// <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},参数错误");
2024-05-27 13:32:18 +08:00
2024-05-29 16:36:30 +08:00
uiName = cfg.GuideTypeParams[0];
buttonPath = cfg.GuideTypeParams[1];
}
2024-05-27 13:32:18 +08:00
2024-05-29 16:36:30 +08:00
protected override async void DoBeforeComplete()
{
base.DoBeforeComplete();
await UI_GuideController.Open();
}
protected override async void DoGuide()
{
await UI_GuideController.Open(uiName, buttonPath, Cfg);
}
2024-05-27 15:39:03 +08:00
}
2024-05-27 13:32:18 +08:00
2024-05-24 15:07:50 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 播放视频
2024-05-24 15:07:50 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
internal sealed class PlayVideoStep : GuideStepBase
2024-05-24 15:07:50 +08:00
{
2024-05-29 16:36:30 +08:00
/// <summary>
/// 视频路径
/// </summary>
private readonly string videoPath;
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
public PlayVideoStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
videoPath = cfg.GuideTypeParams[0];
}
2024-05-27 15:39:03 +08:00
2024-05-29 16:36:30 +08:00
protected override async void DoGuide()
{
await UI_PlayVideoController.Open(videoPath);
}
2024-05-24 15:07:50 +08:00
}
2024-05-29 13:04:51 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 第一次进入主界面
2024-05-29 13:04:51 +08:00
/// </summary>
2024-05-31 15:01:21 +08:00
internal sealed class EnterMainStep : GuideStepBase
2024-05-29 13:04:51 +08:00
{
2024-05-31 15:01:21 +08:00
public EnterMainStep(DataGuideCfg cfg) : base(cfg)
2024-05-29 16:36:30 +08:00
{
}
2024-05-29 13:04:51 +08:00
2024-05-29 16:36:30 +08:00
protected override void DoGuide()
{
2024-05-31 15:01:21 +08:00
GameStateManager.Instance.ChangeState(new GameStateMainScene());
2024-05-29 16:36:30 +08:00
}
2024-05-29 13:04:51 +08:00
}
2024-05-22 19:08:14 +08:00
2024-05-27 15:39:03 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 显示引导提示
2024-05-27 15:39:03 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
internal sealed class ShowGuideTipStep : GuideStepBase
2024-05-22 19:08:14 +08:00
{
2024-05-29 16:36:30 +08:00
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
2024-05-27 15:39:03 +08:00
2024-05-29 16:36:30 +08:00
public ShowGuideTipStep(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-28 18:47:23 +08:00
2024-05-29 16:36:30 +08:00
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
}
2024-05-28 18:47:23 +08:00
2024-05-29 16:36:30 +08:00
protected override async void DoGuide()
{
await UI_GuideTipController.Open(guideTipCfgId);
}
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>
2024-05-29 16:36:30 +08:00
/// 进入关卡
2024-05-24 15:07:50 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
internal sealed class EnterLevelStep : GuideStepBase
2024-05-24 15:07:50 +08:00
{
2024-05-29 16:36:30 +08:00
/// <summary>
/// 关卡id
/// </summary>
private readonly int levelId;
2024-05-24 15:07:50 +08:00
2024-05-29 16:36:30 +08:00
public EnterLevelStep(DataGuideCfg cfg) : base(cfg)
{
if (Cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-27 13:32:18 +08:00
2024-05-29 16:36:30 +08:00
if (int.TryParse(Cfg.GuideTypeParams[0], out int id))
levelId = id;
}
2024-05-27 13:32:18 +08:00
2024-05-30 15:01:43 +08:00
protected override async void DoGuide()
2024-05-29 16:36:30 +08:00
{
2024-05-30 15:01:43 +08:00
await UI_GuideController.Open();
2024-05-30 13:48:26 +08:00
LevelManager.Instance.TryEnterLevel(levelId);
2024-05-29 16:36:30 +08:00
}
2024-05-27 13:32:18 +08:00
}
2024-05-28 13:40:44 +08:00
/// <summary>
2024-05-29 16:36:30 +08:00
/// 关卡上阵
2024-05-28 13:40:44 +08:00
/// </summary>
2024-05-29 16:36:30 +08:00
internal sealed class LevelEmbattleStep : GuideStepBase
2024-05-28 13:40:44 +08:00
{
2024-05-29 16:36:30 +08:00
public LevelEmbattleStep(DataGuideCfg cfg) : base(cfg)
{
2024-05-28 13:40:44 +08:00
2024-05-29 16:36:30 +08:00
}
2024-05-28 13:40:44 +08:00
2024-05-29 16:36:30 +08:00
protected override void DoGuide()
{
}
2024-05-28 13:40:44 +08:00
}
2024-05-30 16:49:27 +08:00
/// <summary>
/// 教学战斗移动
/// </summary>
internal sealed class TeachFightMoveStep : GuideStepBase
{
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
public TeachFightMoveStep(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()
{
LevelManager.Instance.CurrentLevel.SetPause(true);
await UI_GuideTipController.Open(guideTipCfgId);
}
}
/// <summary>
/// 教学战斗攻击
/// </summary>
internal sealed class TeachFightAttackStep : GuideStepBase
{
2024-05-30 19:00:56 +08:00
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
2024-05-30 16:49:27 +08:00
public TeachFightAttackStep(DataGuideCfg cfg) : base(cfg)
{
2024-05-30 19:00:56 +08:00
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()
{
LevelManager.Instance.CurrentLevel.SetPause(true);
await UI_GuideTipController.Open(guideTipCfgId);
}
}
/// <summary>
/// 教学士气与压制
/// </summary>
internal sealed class TeachMoraleAndRepression : GuideStepBase
{
2024-05-30 19:55:53 +08:00
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
2024-05-30 19:00:56 +08:00
public TeachMoraleAndRepression(DataGuideCfg cfg) : base(cfg)
{
2024-05-30 19:55:53 +08:00
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-30 19:00:56 +08:00
2024-05-30 19:55:53 +08:00
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
2024-05-30 19:00:56 +08:00
}
protected override async void DoGuide()
{
2024-05-30 19:55:53 +08:00
LevelManager.Instance.CurrentLevel.SetPause(true);
await UI_GuideTipController.Open(guideTipCfgId);
2024-05-30 19:00:56 +08:00
}
}
/// <summary>
/// 教学使用技能
/// </summary>
internal sealed class TeachUseSkill : GuideStepBase
{
2024-05-31 15:01:21 +08:00
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
2024-05-30 19:00:56 +08:00
public TeachUseSkill(DataGuideCfg cfg) : base(cfg)
{
2024-05-31 15:01:21 +08:00
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-30 19:00:56 +08:00
2024-05-31 15:01:21 +08:00
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
2024-05-30 19:00:56 +08:00
}
2024-05-31 15:01:21 +08:00
protected override async void DoGuide()
2024-05-30 19:00:56 +08:00
{
2024-05-31 15:01:21 +08:00
LevelManager.Instance.CurrentLevel.SetPause(true);
await UI_GuideTipController.Open(guideTipCfgId);
2024-05-30 19:00:56 +08:00
}
}
/// <summary>
/// 教学战斗中上阵
/// </summary>
internal sealed class TeachFightEmbattle : GuideStepBase
{
2024-05-30 19:55:53 +08:00
/// <summary>
/// 引导提示配置id
/// </summary>
private readonly int guideTipCfgId;
2024-05-30 19:00:56 +08:00
public TeachFightEmbattle(DataGuideCfg cfg) : base(cfg)
{
2024-05-30 19:55:53 +08:00
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
2024-05-30 19:00:56 +08:00
2024-05-30 19:55:53 +08:00
if (int.TryParse(cfg.GuideTypeParams[0], out int id))
guideTipCfgId = id;
2024-05-30 16:49:27 +08:00
}
2024-05-30 19:55:53 +08:00
protected override async void DoGuide()
2024-05-30 16:49:27 +08:00
{
2024-05-30 19:55:53 +08:00
LevelManager.Instance.CurrentLevel.SetPause(true);
await UI_GuideTipController.Open(guideTipCfgId);
2024-05-30 16:49:27 +08:00
}
}
2024-05-31 14:06:02 +08:00
/// <summary>
/// 等待关卡结束
/// </summary>
internal sealed class WaitLevelComplete : GuideStepBase
{
private readonly bool isContinue;
public WaitLevelComplete(DataGuideCfg cfg) : base(cfg)
{
if (cfg.GuideTypeParams.Length <= 0)
throw new Exception($"引导类型:{Cfg.GuideStepType},参数错误");
if (bool.TryParse(cfg.GuideTypeParams[0], out bool isContinue))
this.isContinue = isContinue;
}
protected override void DoGuide()
{
LevelManager.Instance.ExitLevelChangeMainFunc = () => { return isContinue; };
}
}
2024-05-22 19:08:14 +08:00
}