235 lines
7.3 KiB
C#
235 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AibisDream;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class EyeTransitionManager : MonoBehaviour
|
|
{
|
|
private float zoomDuration = 1.5f;
|
|
|
|
public Image blackScreenImage;
|
|
|
|
// 视图配置类
|
|
[System.Serializable]
|
|
public class ViewConfig
|
|
{
|
|
public ViewState viewState;
|
|
public MonoBehaviour manager;
|
|
public GameObject viewPanel; // 视图的面板
|
|
public float cameraSize;
|
|
|
|
public UnityEngine.Vector2 cameraPos;
|
|
}
|
|
|
|
// 在 Unity 编辑器中配置视图(不包括MainView)
|
|
[SerializeField] private List<ViewConfig> viewConfigs;
|
|
|
|
// 视图状态和视图配置的映射
|
|
private Dictionary<ViewState, ViewConfig> viewConfigDictionary;
|
|
|
|
// 是否正在进行视图过渡
|
|
private bool isTransitioning = false;
|
|
|
|
public Transform projector;
|
|
|
|
// 视图状态枚举
|
|
public enum ViewState
|
|
{
|
|
MainView,
|
|
EyeView,
|
|
UFView,
|
|
MemoryView,
|
|
// 为未来的视图添加更多状态
|
|
}
|
|
|
|
// 当前的视图状态,默认为 MainView
|
|
private ViewState currentViewState = ViewState.MainView;
|
|
|
|
public event Action OnGetMainView;
|
|
public event Action OnGetDeepView;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
|
}
|
|
|
|
private void OnSceneUnloaded(Scene currentScene)
|
|
{
|
|
if (currentScene.name == "佩佩视觉模块")
|
|
{
|
|
//SaveState();
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
// 初始化视图
|
|
InitializeView();
|
|
|
|
// 初始化视图状态和视图配置的映射
|
|
viewConfigDictionary = new Dictionary<ViewState, ViewConfig>();
|
|
foreach (var config in viewConfigs)
|
|
{
|
|
viewConfigDictionary[config.viewState] = config;
|
|
}
|
|
}
|
|
|
|
private void InitializeView()
|
|
{
|
|
// 默认激活 MainView
|
|
SetView(ViewState.MainView);
|
|
}
|
|
|
|
private void SetView(ViewState viewState)
|
|
{
|
|
// 如果是 MainView,就设置为默认值
|
|
if (viewState == ViewState.MainView)
|
|
{
|
|
foreach (var viewConfig in viewConfigs)
|
|
{
|
|
if (viewConfig.viewPanel != null)
|
|
viewConfig.viewPanel.SetActive(false);
|
|
//viewConfig.viewLifecycle?.OnExit(); // 初始化视图
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
|
|
|
if (config.viewPanel != null)
|
|
{
|
|
config.viewPanel.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void ExitView(ViewState viewState)
|
|
{
|
|
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
|
|
|
if (config.viewPanel != null)
|
|
{
|
|
config.viewPanel.SetActive(false);
|
|
}
|
|
}
|
|
|
|
// 开始视图过渡
|
|
private void StartTransition(ViewState targetViewState)
|
|
{
|
|
// 如果正在进行视图过渡,或者目标视图是当前视图,或者 MemoryProcess 正在处理,就不进行视图过渡
|
|
//if (isTransitioning || currentViewState == targetViewState || (memoryProcess != null && memoryProcess.IsProcessing()))
|
|
if (isTransitioning || currentViewState == targetViewState)
|
|
{
|
|
Debug.LogWarning("Transition is currently not allowed. Please wait until the current process is finished.");
|
|
return;
|
|
}
|
|
|
|
// 开始视图过渡
|
|
isTransitioning = true;
|
|
|
|
if (targetViewState == ViewState.MainView)
|
|
{
|
|
Debug.Log("into mainview");
|
|
// Zoom Out 的时候,先黑屏淡入
|
|
blackScreenImage.gameObject.SetActive(true);
|
|
Sequence zoomOutSequence = DOTween.Sequence();
|
|
zoomOutSequence.Append(blackScreenImage.DOFade(1f, zoomDuration / 2));
|
|
|
|
// 在黑屏淡入完成后关闭 Panel
|
|
zoomOutSequence.AppendCallback(() => { ExitView(currentViewState); });
|
|
|
|
// 开始淡出黑屏
|
|
zoomOutSequence.Append(blackScreenImage.DOFade(0f, zoomDuration)
|
|
.OnComplete(() => blackScreenImage.gameObject.SetActive(false)));
|
|
zoomOutSequence.Insert(zoomDuration / 2, Camera.main.DOOrthoSize(5f, zoomDuration).SetEase(Ease.OutCubic));
|
|
zoomOutSequence.Insert(zoomDuration / 2,
|
|
Camera.main.transform.DOMove(new UnityEngine.Vector3(0, 0, -10), zoomDuration).SetEase(Ease.OutCubic));
|
|
|
|
if (projector.localPosition.y <= -1)
|
|
{
|
|
zoomOutSequence.Append(projector.DOLocalMoveY(-1, zoomDuration).SetEase(Ease.OutCubic));
|
|
}
|
|
|
|
// 在整个动画完成后更新视图状态
|
|
zoomOutSequence.OnComplete(() =>
|
|
{
|
|
currentViewState = ViewState.MainView;
|
|
isTransitioning = false;
|
|
OnGetMainView.Invoke();
|
|
//MouseCursorManager.Instance.isInDeepView=false;
|
|
DialogController.Instance.StartDialogNode("主维修界面游戏状态检查");
|
|
});
|
|
}
|
|
|
|
else
|
|
{
|
|
if (!viewConfigDictionary.TryGetValue(targetViewState, out ViewConfig targetConfig)) return;
|
|
|
|
// AudioManager.RandomPlayInteraction(targetConfig.soundName);
|
|
// Zoom In 的时候,开始 Zoom
|
|
Sequence zoomInSequence = DOTween.Sequence();
|
|
|
|
float FadeTiming = zoomDuration / 4;
|
|
if (targetViewState == ViewState.MemoryView)
|
|
{
|
|
FadeTiming *= 5f;
|
|
|
|
zoomInSequence.Append(projector.DOLocalMoveY(-5, zoomDuration).SetEase(Ease.OutElastic, 0.5f));
|
|
zoomInSequence.AppendCallback(() => { });
|
|
}
|
|
|
|
zoomInSequence.Append(Camera.main.DOOrthoSize(targetConfig.cameraSize, zoomDuration)
|
|
.SetEase(Ease.OutCubic));
|
|
zoomInSequence.Join(Camera.main.transform
|
|
.DOMove(new UnityEngine.Vector3(targetConfig.cameraPos.x, targetConfig.cameraPos.y, -10), zoomDuration)
|
|
.SetEase(Ease.OutCubic));
|
|
|
|
// 在 Zoom 到一半时开始黑屏过渡
|
|
zoomInSequence.Insert(FadeTiming,
|
|
blackScreenImage.DOFade(1f, zoomDuration / 2)
|
|
.OnStart(() => blackScreenImage.gameObject.SetActive(true)));
|
|
|
|
|
|
// 在整个 Zoom 完成后激活 Eye View
|
|
zoomInSequence.OnComplete(() =>
|
|
{
|
|
if (zoomInSequence != null)
|
|
{
|
|
zoomInSequence.Kill();
|
|
}
|
|
|
|
ExitView(currentViewState);
|
|
SetView(targetViewState);
|
|
FadeFromBlack(() =>
|
|
{
|
|
//MouseCursorManager.Instance.isInDeepView=true;
|
|
currentViewState = targetViewState;
|
|
isTransitioning = false;
|
|
OnGetDeepView.Invoke();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
private void FadeFromBlack(TweenCallback onComplete)
|
|
{
|
|
blackScreenImage.DOFade(0f, 1f).OnComplete(() =>
|
|
{
|
|
blackScreenImage.gameObject.SetActive(false);
|
|
onComplete?.Invoke();
|
|
});
|
|
}
|
|
|
|
public void RequestViewChange(ViewState targetViewState)
|
|
{
|
|
StartTransition(targetViewState);
|
|
}
|
|
} |