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

174 lines
4.3 KiB
C#

using cfg.GuideCfg;
using Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 新手引导步骤完成基类
/// </summary>
public abstract class GuideCompleteBase
{
/// <summary>
/// 引导完成回调
/// </summary>
protected readonly Action completeAction;
public GuideCompleteBase(Action complete)
{
completeAction = complete;
}
/// <summary>
/// 添加监听
/// </summary>
public abstract void AddListener();
/// <summary>
/// 移除监听
/// </summary>
public abstract void RemoveListener();
}
/// <summary>
/// 播放视频完成
/// </summary>
public class PlayVideoComplete : GuideCompleteBase
{
/// <summary>
/// 视频路径
/// </summary>
private readonly string videoPath;
public PlayVideoComplete(DataGuideCfg cfg, Action complete) : base(complete)
{
if (cfg.CompleteTypeParams.Length <= 0)
throw new Exception($"引导类型:{cfg.GuideCompleteType}参数错误");
videoPath = cfg.CompleteTypeParams[0];
}
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.PlayVideoComplete, (Action<string>)OnPlayVideoComplete);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.PlayVideoComplete, (Action<string>)OnPlayVideoComplete);
}
/// <summary>
/// 播放视频完成回调
/// </summary>
/// <param name="path"></param>
private void OnPlayVideoComplete(string path)
{
if (path != videoPath)
return;
completeAction?.Invoke();
}
}
/// <summary>
/// 打开UI完成
/// </summary>
public class OpenUIComplete : GuideCompleteBase
{
private readonly string uiName;
public OpenUIComplete(DataGuideCfg cfg, Action complete) : base(complete)
{
if (cfg.CompleteTypeParams.Length <= 0)
throw new Exception($"引导类型:{cfg.GuideCompleteType}参数错误");
uiName = cfg.CompleteTypeParams[0];
}
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.UIOpen, (Action<string>)OnComplete);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.UIOpen, (Action<string>)OnComplete);
}
private void OnComplete(string uiName)
{
if (this.uiName != uiName)
return;
completeAction?.Invoke();
}
}
/// <summary>
/// 关闭UI完成
/// </summary>
public class CloseUIComplete : GuideCompleteBase
{
private readonly string uiName;
public CloseUIComplete(DataGuideCfg cfg, Action complete) : base(complete)
{
if (cfg.CompleteTypeParams.Length <= 0)
throw new Exception($"引导类型:{cfg.GuideCompleteType}参数错误");
uiName = cfg.CompleteTypeParams[0];
}
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.UIClose, (Action<string>)OnComplete);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.UIClose, (Action<string>)OnComplete);
}
private void OnComplete(string uiName)
{
if (this.uiName != uiName)
return;
completeAction?.Invoke();
}
}
/// <summary>
/// 打开UI并且UI动画播放完成
/// </summary>
public class OpenUIAndAnimComplete : GuideCompleteBase
{
private readonly string uiName;
public OpenUIAndAnimComplete(DataGuideCfg cfg, Action complete) : base(complete)
{
if (cfg.CompleteTypeParams.Length <= 0)
throw new Exception($"引导类型:{cfg.GuideCompleteType}参数错误");
uiName = cfg.CompleteTypeParams[0];
}
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.UIOpenAndAnim, (Action<string>)OnComplete);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.UIOpenAndAnim, (Action<string>)OnComplete);
}
private void OnComplete(string uiName)
{
if (this.uiName != uiName)
return;
completeAction?.Invoke();
}
}