Tz2/Assets/Zion/Scripts/ERP/10kV变压器代保管出库/RetiredAssetOutboundManager.cs

240 lines
8.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Threading.Tasks;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;
using Cysharp.Threading.Tasks;
using DefaultNamespace.ProcessMode;
using Framework.Manager;
public class RetiredAssetOutboundManager : MonoBehaviour
{
public static RetiredAssetOutboundManager Instance;
[Header("相机设置")]
public GameObject camera1; // 固定相机
public GameObject firstcamera2; // 第一人称相机
[Header("场景对象")]
public GameObject che; // 车辆对象
[Header("UI设置")]
public Image backimage; // 黑屏Image
private bool isStart = false;
private void Awake()
{
Instance = this;
}
// private async void Start()
// {
// await StartProcess();
// }
/// <summary>
/// 启动整个流程
/// </summary>
public async UniTask StartProcess()
{
if (isStart) return;
isStart = true;
Debug.Log("=== 开始退出退役资产出库作业流程 ===");
// 初始化状态:第一人称激活
InitializeState();
// 阶段1瞬间黑屏切换到camera1不需要淡入
Debug.Log("阶段1瞬间黑屏切换到固定相机视角");
await InstantFadeOut(() => SwitchToCamera1());
// 阶段2等待20秒
Debug.Log("阶段2等待20秒");
await UniTask.Delay(200);
// 阶段3完整的淡入淡出切换回第一人称
Debug.Log("阶段3淡入淡出切换回第一人称视角");
await FadeInOut(() => SwitchToFirstPerson());
if (MotionFramework.MotionEngine.GetModule<ProcessManager>()._currentMode == ProcessMode. )
{
TutorialGuideManager.Instance.NextGuideIn();
}
Debug.Log("=== 流程执行完毕 ===");
}
/// <summary>
/// 初始化场景状态
/// </summary>
private void InitializeState()
{
firstcamera2.SetActive(true);
camera1.SetActive(false);
che.SetActive(false);
backimage.gameObject.SetActive(false);
Debug.Log("初始化完成:第一人称相机激活");
}
/// <summary>
/// 瞬间黑屏过场动画(用于第一次切换)
/// </summary>
/// <param name="switchAction">在黑屏期间执行的切换动作</param>
private async UniTask InstantFadeOut(System.Action switchAction)
{
Debug.Log("开始瞬间黑屏过场动画");
// 激活黑屏Image并瞬间设置为黑色
backimage.gameObject.SetActive(true);
backimage.color = new Color(0, 0, 0, 1f); // 瞬间黑屏
Debug.Log("瞬间黑屏完成");
// 短暂延迟后执行切换
await UniTask.Delay(200);
switchAction?.Invoke();
await UniTask.Delay(500); // 保持黑屏0.5秒
// 淡出到透明
Debug.Log("开始淡出到透明");
backimage.DOFade(0f, 1.5f).SetEase(Ease.OutQuad);
await UniTask.Delay(1500);
Debug.Log("淡出完成");
// 淡出完成后关闭黑屏Image
backimage.gameObject.SetActive(false);
}
/// <summary>
/// 完整的淡入淡出过场动画(用于第二次切换)
/// </summary>
/// <param name="switchAction">在黑屏期间执行的切换动作</param>
private async UniTask FadeInOut(System.Action switchAction)
{
Debug.Log("开始完整的淡入淡出过场动画");
// 激活黑屏Image并设置为透明
backimage.gameObject.SetActive(true);
backimage.color = new Color(0, 0, 0, 0f); // 从透明开始
// 淡入黑屏
Debug.Log("开始淡入黑屏");
backimage.DOFade(1f, 1.5f).SetEase(Ease.InQuad);
await UniTask.Delay(1500);
Debug.Log("淡入完成");
// 在黑屏期间执行切换
switchAction?.Invoke();
await UniTask.Delay(500); // 保持黑屏0.5秒
// 淡出到透明
Debug.Log("开始淡出到透明");
backimage.DOFade(0f, 1.5f).SetEase(Ease.OutQuad);
await UniTask.Delay(1500);
Debug.Log("淡出完成");
// 淡出完成后关闭黑屏Image
backimage.gameObject.SetActive(false);
}
/// <summary>
/// 切换到固定相机视角
/// </summary>
private void SwitchToCamera1()
{
// 禁用第一人称控制器
var fpsController = firstcamera2.GetComponent<FirstPersonController>();
if (fpsController != null)
{
fpsController.enabled = false;
}
// 切换相机和激活车辆
firstcamera2.SetActive(false);
camera1.SetActive(true);
che.SetActive(true);
Debug.Log("已切换到固定相机,激活车辆");
}
/// <summary>
/// 切换回第一人称视角
/// </summary>
private void SwitchToFirstPerson()
{
// 切换相机和关闭车辆
camera1.SetActive(false);
che.SetActive(false);
firstcamera2.SetActive(true);
// 设置第一人称相机位置
firstcamera2.transform.SetLocalPositionAndRotation(
new Vector3(6, 1, -12),
Quaternion.Euler(0, 0, 0)
);
// 重新启用第一人称控制器
var fpsController = firstcamera2.GetComponent<FirstPersonController>();
if (fpsController != null)
{
fpsController.enabled = true;
fpsController.InitController();
}
Debug.Log("已切换回第一人称,设置位置并启用控制器");
}
/// <summary>
/// 外部调用接口
/// </summary>
public async void Show()
{
await StartProcess();
}
/// <summary>
/// 黑屏过场动画(统一的渐变效果)
/// </summary>
/// <param name="switchAction">在黑屏期间执行的切换动作</param>
private async UniTask FadeTransition(System.Action switchAction)
{
Debug.Log("开始黑屏过场动画");
// 激活黑屏Image并设置为透明
backimage.gameObject.SetActive(true);
backimage.color = new Color(0, 0, 0, 0f); // 从透明开始
// 淡入黑屏 - 使用UniTaskCompletionSource等待动画完成
Debug.Log("开始淡入黑屏");
var fadeInComplete = new UniTaskCompletionSource();
backimage.DOFade(1f, 1.5f)
.SetEase(Ease.InQuad)
.OnComplete(() => fadeInComplete.TrySetResult());
await fadeInComplete.Task;
Debug.Log($"淡入完成当前Alpha值: {backimage.color.a}");
// 在黑屏期间执行切换
switchAction?.Invoke();
await UniTask.Delay(500); // 保持黑屏0.5秒
Debug.Log("切换完成");
// 淡出到透明 - 使用UniTaskCompletionSource等待动画完成
Debug.Log("开始淡出到透明");
var fadeOutComplete = new UniTaskCompletionSource();
backimage.DOFade(0f, 1.5f)
.SetEase(Ease.OutQuad)
.OnComplete(() => fadeOutComplete.TrySetResult());
await fadeOutComplete.Task;
Debug.Log($"淡出完成当前Alpha值: {backimage.color.a}");
// 确保Alpha值为0后再关闭黑屏Image
Debug.Log("Image渐变完成准备关闭");
backimage.gameObject.SetActive(false);
Debug.Log("黑屏Image已关闭");
}
}