177 lines
5.2 KiB
C#
177 lines
5.2 KiB
C#
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using UnityEngine;
|
|
using Cinemachine;
|
|
using System.Collections;
|
|
using DG.Tweening;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
/// <summary>
|
|
/// 维修面板系统 - 统一管理所有侧边栏面板
|
|
/// 包括常驻面板(对话、任务)和随状态切换的游戏面板
|
|
/// </summary>
|
|
public class FixPanelSystem : Singleton<FixPanelSystem>
|
|
{
|
|
private void OnEnable()
|
|
{
|
|
RegisterCanvasCamera();
|
|
RegisterPanels();
|
|
RegisterScreenView();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UnRegisterCanvasCamera();
|
|
_panelContainer.Clear();
|
|
UnRegisterScreenView();
|
|
}
|
|
|
|
#region 维修面板
|
|
|
|
private static IOCContainer _panelContainer = new();
|
|
|
|
public static T GetRepairPanel<T>() where T : class
|
|
{
|
|
return _panelContainer.Get<T>();
|
|
}
|
|
|
|
public void RegisterPanels()
|
|
{
|
|
var panels = GetComponentsInChildren<IOperatorPanel>(true);
|
|
foreach (var panel in panels)
|
|
{
|
|
_panelContainer.RegisterByInstance(panel);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 维修管理扩展
|
|
|
|
[Header("光照系统")]
|
|
[SerializeField] private FixPanelLight panelLight;
|
|
public FixPanelLight PanelLight => panelLight;
|
|
|
|
[Header("维修切换管理")]
|
|
[SerializeField] private RepairSystemManager repairSystemManager;
|
|
public RepairSystemManager RepairSystemManager => repairSystemManager;
|
|
|
|
#endregion
|
|
|
|
#region 系统启动协调
|
|
|
|
/// <summary>
|
|
/// 启动所有系统(协调灯光系统和 CablePanel 的启动顺序)
|
|
/// </summary>
|
|
public IEnumerator StartAllSystems()
|
|
{
|
|
// 1. 先启动 CablePanel 的系统自检
|
|
var cablePanel = GetRepairPanel<CablePanel>();
|
|
if (cablePanel != null)
|
|
{
|
|
yield return cablePanel.StartSystem();
|
|
}
|
|
|
|
// 2. 再启动灯光序列
|
|
if (panelLight != null)
|
|
{
|
|
yield return panelLight.StartPanelLightSequence();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置灯光状态,并同步更新相关面板的灯光效果
|
|
/// </summary>
|
|
public void SetLightState(LightState newState)
|
|
{
|
|
// 1. 更新主灯光系统
|
|
if (panelLight != null)
|
|
{
|
|
panelLight.SetLightState(newState);
|
|
}
|
|
|
|
// 2. 同步更新 CablePanel 的灯光效果
|
|
var cablePanel = GetRepairPanel<CablePanel>();
|
|
if (cablePanel != null)
|
|
{
|
|
cablePanel.UpdateBreathingLight(newState);
|
|
cablePanel.UpdateECGWave(newState);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 屏幕相关操作
|
|
[Header("默认相机")]
|
|
[SerializeField] private CinemachineVirtualCamera fixPanelCamera;
|
|
|
|
[Header("默认气泡")]
|
|
[SerializeField] private BubbleSlotGroup bubbleSlotGroup;
|
|
public BubbleSlotGroup BubbleSlotGroup => bubbleSlotGroup;
|
|
|
|
[Header("默认画布")]
|
|
[SerializeField] private Canvas canvas;
|
|
|
|
[Header("全景遮罩")]
|
|
[SerializeField] private SpriteRenderer mask;
|
|
|
|
[Header("任务面板")]
|
|
[SerializeField] private TaskPanel taskPanel;
|
|
public TaskPanel TaskPanel => taskPanel;
|
|
|
|
[Header("屏幕面板")]
|
|
[SerializeField] private ScreenPanel screenPanel;
|
|
public ScreenPanel ScreenPanel => screenPanel;
|
|
|
|
private void RegisterScreenView()
|
|
{
|
|
// 注册相机
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.BodyModule, fixPanelCamera);
|
|
|
|
DialogUIManager.Instance.RegisterScreenView(DialogViewType.Screen, screenPanel);
|
|
DialogUIManager.Instance.RegisterScreenView(DialogViewType.Task, taskPanel);
|
|
}
|
|
|
|
private void UnRegisterScreenView()
|
|
{
|
|
CameraKit.Instance.UnRegisterCamera(CameraEnum.BodyModule);
|
|
|
|
DialogUIManager.Instance.UnRegisterScreenView(DialogViewType.Screen);
|
|
DialogUIManager.Instance.UnRegisterScreenView(DialogViewType.Task);
|
|
}
|
|
|
|
private void RegisterCanvasCamera()
|
|
{
|
|
canvas.worldCamera = Camera.main;
|
|
}
|
|
|
|
private void UnRegisterCanvasCamera()
|
|
{
|
|
canvas.worldCamera = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 遮罩淡入(从当前透明度过渡到不透明)
|
|
/// </summary>
|
|
/// <param name="duration">淡入时长(秒)</param>
|
|
public IEnumerator MaskFadeIn(float duration = 1f)
|
|
{
|
|
if (mask == null) yield break;
|
|
yield return mask.DOFade(1f, duration).WaitForCompletion();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 遮罩淡出(从当前透明度过渡到透明)
|
|
/// </summary>
|
|
/// <param name="duration">淡出时长(秒)</param>
|
|
public IEnumerator MaskFadeOut(float duration = 1f)
|
|
{
|
|
if (mask == null) yield break;
|
|
yield return mask.DOFade(0f, duration).WaitForCompletion();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|