using cfg.GuideCfg;
using Framework;
using PhxhSDK;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 新手引导管理器
///
public class GuideManager : Singlenton, IInitable
{
///
/// 新手引导配置字典,key:引导组,Value:引导步骤配置链表
///
private Dictionary> dicGuideCfg;
///
/// 是否启用新手引导
///
public bool IsEnable { get; private set; }
///
/// 是否引导中
///
public bool IsGuiding { get; private set; }
public void Init()
{
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, InitData);
}
public void Release()
{
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, InitData);
}
///
/// 初始化数据
///
private void InitData()
{
IsGuiding = false;
dicGuideCfg = new();
foreach (DataGuideCfg cfg in TableManager.Instance.Tables.GuideConfig.DataList)
{
if (dicGuideCfg.ContainsKey(cfg.GroupId) && !IsFirstStep(cfg))
continue;
DataGuideCfg addCfg = cfg; // 记录要添加进链表的引导步骤配置
LinkedList linkCfg = new();
dicGuideCfg[cfg.GroupId] = linkCfg;
while (null != addCfg)
{
linkCfg.AddLast(addCfg);
addCfg = TableManager.Instance.Tables.GuideConfig.Get(addCfg.NextId);
}
}
#region 检验每个引导组的步骤顺序是否正常
foreach (LinkedList linkCfg in dicGuideCfg.Values)
{
DataGuideCfg preCfg = null;
foreach (DataGuideCfg cfg in linkCfg)
{
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}");
IsEnable = false;
return;
}
else
preCfg = cfg;
}
}
#endregion
}
///
/// 是否是引导组的第一步
///
///
private bool IsFirstStep(DataGuideCfg dataGuideCfg)
{
return dataGuideCfg.Id == dataGuideCfg.GroupId;
}
}