2024-05-22 16:31:29 +08:00
|
|
|
|
using cfg.GuideCfg;
|
2024-05-22 15:41:05 +08:00
|
|
|
|
using Framework;
|
2024-06-05 14:04:26 +08:00
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using NLDPB;
|
2024-05-22 15:41:05 +08:00
|
|
|
|
using PhxhSDK;
|
2024-06-28 17:34:50 +08:00
|
|
|
|
using System;
|
2024-05-22 15:41:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
namespace Gameplay.Guide
|
2024-05-22 15:41:05 +08:00
|
|
|
|
{
|
2024-05-22 16:31:29 +08:00
|
|
|
|
/// <summary>
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// 新手引导管理器
|
2024-05-22 16:31:29 +08:00
|
|
|
|
/// </summary>
|
2024-05-29 16:36:30 +08:00
|
|
|
|
public class GuideManager : Singlenton<GuideManager>, IInitable
|
2024-05-24 19:11:19 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新手引导配置字典,key:引导组,Value:引导步骤配置链表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Dictionary<int, LinkedList<DataGuideCfg>> dicGuideCfg;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前的引导组
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private GuideGroup curGroup;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否引导中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsGuiding
|
2024-05-24 19:11:19 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
get { return curGroup != null && curGroup.IsGuiding; }
|
2024-05-24 19:11:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-03 14:07:54 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 控制地板点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsControlFloor = true;
|
2024-07-01 13:08:37 +08:00
|
|
|
|
/// <summary>
|
2024-07-03 19:15:36 +08:00
|
|
|
|
/// 是否改名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsChangeName = true;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否跳过剧情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsSkipStory = false;
|
|
|
|
|
|
/// <summary>
|
2024-07-01 13:08:37 +08:00
|
|
|
|
/// 指定地板索引
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int FloorIndex = -1;
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
public void Init()
|
2024-05-24 19:11:19 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, InitData);
|
|
|
|
|
|
}
|
2024-05-29 13:04:51 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
public void Release()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, InitData);
|
2024-05-24 19:11:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 开始引导
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool BeginGuide()
|
2024-05-24 19:11:19 +08:00
|
|
|
|
{
|
2024-06-05 13:13:11 +08:00
|
|
|
|
#if GUIDE
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (IsGuiding)
|
|
|
|
|
|
return false;
|
2024-05-28 18:47:23 +08:00
|
|
|
|
|
2024-06-28 17:34:50 +08:00
|
|
|
|
try
|
2024-05-24 19:11:19 +08:00
|
|
|
|
{
|
2024-06-28 17:34:50 +08:00
|
|
|
|
foreach (var guide in dicGuideCfg)
|
2024-05-29 16:36:30 +08:00
|
|
|
|
{
|
2024-06-28 17:34:50 +08:00
|
|
|
|
int completeGroupId = (int)Actor.Instance.Logic.GetCount((uint)LogicID.NewGuideProgress);
|
|
|
|
|
|
if (guide.Key > completeGroupId)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.Log($"<color=#00FA9A>已完成的引导组id:{completeGroupId},开始引导组id:{guide.Key}</color>");
|
|
|
|
|
|
curGroup = new(guide.Key, guide.Value); // TODO 测试
|
|
|
|
|
|
curGroup.BeginGuide();
|
2024-06-05 14:04:26 +08:00
|
|
|
|
|
2024-06-28 17:34:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-05-29 16:36:30 +08:00
|
|
|
|
}
|
2024-05-24 19:11:19 +08:00
|
|
|
|
}
|
2024-06-28 17:34:50 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"跳过引导,错误信息:{e}");
|
|
|
|
|
|
}
|
2024-06-05 13:13:11 +08:00
|
|
|
|
#endif
|
2024-05-29 16:36:30 +08:00
|
|
|
|
return false;
|
2024-05-24 19:11:19 +08:00
|
|
|
|
}
|
2024-05-24 15:07:50 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 完成指定引导步骤
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="step"></param>
|
|
|
|
|
|
public void CompleteStep(GuideStepBase step)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (null == curGroup)
|
|
|
|
|
|
return;
|
2024-05-29 13:04:51 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (step != curGroup.CurStep)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("要完成的引导步骤不是当前步骤");
|
|
|
|
|
|
EndGuide(true);
|
2024-05-29 13:04:51 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-29 13:04:51 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (curGroup.IsComplete)
|
|
|
|
|
|
{
|
2024-06-05 14:04:26 +08:00
|
|
|
|
NetHelper.SaveGuideProgress((uint)curGroup.GroupId); // 完成引导组,保存服务器
|
|
|
|
|
|
DebugUtil.Log($"<color=#00FA9A>完成引导组,服务器保存id:{curGroup.GroupId}</color>");
|
2024-05-29 16:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
int nextGroupId = curGroup.NextGroupId;
|
|
|
|
|
|
if (dicGuideCfg.TryGetValue(nextGroupId, out LinkedList<DataGuideCfg> linkCfg))
|
|
|
|
|
|
{
|
|
|
|
|
|
curGroup = new(nextGroupId, linkCfg);
|
|
|
|
|
|
curGroup.BeginGuide();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
EndGuide(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
curGroup.BeginNextStep();
|
|
|
|
|
|
}
|
2024-05-22 16:31:29 +08:00
|
|
|
|
|
2024-07-03 13:08:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 回到指定步骤
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="step"></param>
|
|
|
|
|
|
public void ReturnStep(int stepId)
|
|
|
|
|
|
{
|
|
|
|
|
|
curGroup.EndGuide();
|
|
|
|
|
|
curGroup.BeginGuideById(stepId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结束引导
|
|
|
|
|
|
/// </summary>
|
2024-06-06 14:41:02 +08:00
|
|
|
|
public void EndGuide(bool isReEnterMain)
|
2024-05-22 16:31:29 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (IsGuiding)
|
|
|
|
|
|
curGroup.EndGuide();
|
2024-05-22 16:31:29 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
curGroup = null;
|
|
|
|
|
|
UIManager.Instance.CloseWindow(UINameConst.UI_Guide);
|
|
|
|
|
|
UIManager.Instance.CloseWindow(UINameConst.UI_GuideTip);
|
2024-05-22 15:41:05 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (isReEnterMain)
|
2024-06-04 19:13:48 +08:00
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
2024-05-22 16:31:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void InitData()
|
2024-05-22 16:31:29 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
dicGuideCfg = new();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (DataGuideCfg cfg in TableManager.Instance.Tables.GuideConfig.DataList)
|
2024-05-22 16:31:29 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (dicGuideCfg.ContainsKey(cfg.GroupId) && !IsFirstStep(cfg))
|
2024-05-22 16:31:29 +08:00
|
|
|
|
continue;
|
2024-05-29 16:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
DataGuideCfg addCfg = cfg; // 记录要添加进链表的引导步骤配置
|
|
|
|
|
|
int groudId = cfg.GroupId;
|
|
|
|
|
|
LinkedList<DataGuideCfg> linkCfg = new();
|
|
|
|
|
|
dicGuideCfg[groudId] = linkCfg;
|
|
|
|
|
|
|
|
|
|
|
|
while (null != addCfg && addCfg.GroupId == groudId)
|
|
|
|
|
|
{
|
|
|
|
|
|
linkCfg.AddLast(addCfg);
|
2024-07-01 19:12:47 +08:00
|
|
|
|
|
2024-07-02 13:45:19 +08:00
|
|
|
|
if (0 == addCfg.NextId)
|
|
|
|
|
|
addCfg = null;
|
|
|
|
|
|
else if (addCfg.Id >= addCfg.NextId)
|
|
|
|
|
|
throw new Exception($"{addCfg.Id}引导的下一步id配置错误,下一步id小于等于当前id可能导致死循环");
|
|
|
|
|
|
else
|
|
|
|
|
|
addCfg = TableManager.Instance.Tables.GuideConfig.Get(addCfg.NextId);
|
2024-05-22 16:31:29 +08:00
|
|
|
|
}
|
2024-05-29 16:36:30 +08:00
|
|
|
|
}
|
2024-05-22 16:31:29 +08:00
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
#region 检验每个引导组的步骤顺序是否正常
|
|
|
|
|
|
foreach (LinkedList<DataGuideCfg> linkCfg in dicGuideCfg.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataGuideCfg preCfg = null;
|
|
|
|
|
|
foreach (DataGuideCfg cfg in linkCfg)
|
2024-05-22 16:31:29 +08:00
|
|
|
|
{
|
2024-05-29 16:36:30 +08:00
|
|
|
|
if (null == preCfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
preCfg = cfg;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (preCfg.NextId != cfg.Id)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"新手引导配置出错,组id:{cfg.GroupId}, 当前步骤id:{preCfg.Id}, 实际下一步步骤id:{preCfg.NextId}, 当前下一步步骤id:{cfg.Id}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
preCfg = cfg;
|
2024-05-22 16:31:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-29 16:36:30 +08:00
|
|
|
|
#endregion
|
2024-05-22 16:31:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 16:36:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否是引导组的第一步
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private bool IsFirstStep(DataGuideCfg dataGuideCfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dataGuideCfg.Id == dataGuideCfg.GroupId;
|
|
|
|
|
|
}
|
2024-05-22 15:41:05 +08:00
|
|
|
|
}
|
2024-05-24 19:11:19 +08:00
|
|
|
|
}
|