NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Show/ShowManager.cs

155 lines
5.1 KiB
C#

using cfg.ShowCfg;
using Gameplay.Show;
using PhxhSDK;
using PhxhSDK.Res;
using System;
using System.Collections.Generic;
/// <summary>
/// 演出管理器
/// </summary>
public class ShowManager : Singlenton<ShowManager>, IInitable, IUpdatable
{
private Dictionary<E_ShowSceneType, IShow> dicShow;
private ShopShowController shopShowController;
public void Init()
{
shopShowController = new ShopShowController();
dicShow = new()
{
[E_ShowSceneType.Main] = new ShowController(),
[E_ShowSceneType.Camp] = new ShowController(),
[E_ShowSceneType.Raffle] = new RaffleShowController(),
[E_ShowSceneType.Shop] = shopShowController,
};
}
public void Update(float deltaTime)
{
shopShowController.Update();
}
public void Release()
{
dicShow.Clear();
dicShow = null;
}
/// <summary>
/// 刷新演出
/// </summary>
/// <param name="showSceneType"></param>
/// <returns></returns>
public async void RefreshShow(E_ShowSceneType showSceneType, object data = null)
{
SceneHandle sceneHandle = GameSceneHelper.Instance.GetCurrentUIViewScene();
switch (showSceneType)
{
case E_ShowSceneType.Main:
case E_ShowSceneType.Camp:
{
ShowComponent showComponent = SceneHandle.GetSceneRootComponent<ShowComponent>(sceneHandle.Scene);
if (null == showComponent)
return;
if (!TryGetShow(showSceneType, out IShow show))
return;
if (show is not ShowController showController)
return;
showController.SetInfo(showComponent);
await show.RefreshShow(data);
}
break;
case E_ShowSceneType.Raffle:
{
RaffleShowComponent raffleShowComponent = SceneHandle.GetSceneRootComponent<RaffleShowComponent>(sceneHandle.Scene);
if (null == raffleShowComponent)
return;
if (!TryGetShow(showSceneType, out IShow show))
return;
if (show is not RaffleShowController raffleShowController)
return;
raffleShowController.SetInfo(raffleShowComponent);
await show.RefreshShow(data);
}
break;
case E_ShowSceneType.Shop:
{
ShopShowComponent shopShowComponent = SceneHandle.GetSceneRootComponent<ShopShowComponent>(sceneHandle.Scene);
if (null == shopShowComponent)
return;
if (!TryGetShow(showSceneType, out IShow show))
return;
if (show is not ShopShowController shopShowController)
return;
shopShowController.SetInfo(shopShowComponent);
await show.RefreshShow(data);
}
break;
}
}
/// <summary>
/// 播放相机动画
/// </summary>
/// <param name="showSceneType">演出场景类型</param>
/// <param name="callbackAction">动画播放完成回调</param>
public void PlayCameraAnim(E_ShowSceneType showSceneType, Action callbackAction, params string[] args)
{
SceneHandle sceneHandle = GameSceneHelper.Instance.GetCurrentUIViewScene();
switch (showSceneType)
{
case E_ShowSceneType.Main:
{
ShowComponent showComponent = SceneHandle.GetSceneRootComponent<ShowComponent>(sceneHandle.Scene);
if (null == showComponent)
return;
if (!TryGetShow(showSceneType, out IShow show))
return;
if (show is not ShowController showController)
return;
showController.SetInfo(showComponent);
show.PlayeCameraAnim(callbackAction, args);
}
break;
case E_ShowSceneType.Shop:
{
ShopShowComponent shopShowComponent = SceneHandle.GetSceneRootComponent<ShopShowComponent>(sceneHandle.Scene);
if (null == shopShowComponent)
return;
if (!TryGetShow(showSceneType, out IShow show))
return;
if (show is not ShopShowController shopShowController)
return;
shopShowController.SetInfo(shopShowComponent);
show.PlayeCameraAnim(callbackAction, args);
}
break;
}
}
/// <summary>
/// 获取演出
/// </summary>
/// <param name="showSceneType"></param>
/// <returns></returns>
private bool TryGetShow(E_ShowSceneType showSceneType, out IShow show)
{
return dicShow.TryGetValue(showSceneType, out show) && show != null;
}
}