新加入一些屏幕效果的脚本
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b09cbe87914234241a07c227fe12e06a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class ScreenEffectManager : MonoBehaviour
|
||||
{
|
||||
public static ScreenEffectManager Instance { get; private set; }
|
||||
|
||||
public Image blackoutPanel; // 黑屏面板
|
||||
public Image redFlashPanel; // 红色闪烁面板
|
||||
public float shakeDuration = 1.0f; // 震屏持续时间
|
||||
public float shakeIntensity = 0.1f; // 震屏强度
|
||||
|
||||
private Vector3 originalCameraPosition;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 确保单例模式
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject); // 可选:保持在场景加载之间
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 保存初始相机位置
|
||||
originalCameraPosition = Camera.main.transform.localPosition;
|
||||
}
|
||||
|
||||
// 震屏效果
|
||||
[YarnCommand("shakeScreen")]
|
||||
public void ShakeScreen()
|
||||
{
|
||||
Camera.main.transform.DOPunchPosition(Vector3.one * shakeIntensity, shakeDuration, 10, 1);
|
||||
}
|
||||
|
||||
// 黑屏淡入淡出效果
|
||||
[YarnCommand("fadeIn")]
|
||||
public void FadeBlackout(bool enable, float duration)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
blackoutPanel.gameObject.SetActive(true);
|
||||
blackoutPanel.DOFade(1, duration).OnComplete(() => blackoutPanel.gameObject.SetActive(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
blackoutPanel.DOFade(0, duration).OnComplete(() => blackoutPanel.gameObject.SetActive(false));
|
||||
}
|
||||
}
|
||||
|
||||
// 红色闪烁效果
|
||||
[YarnCommand("flashRed")]
|
||||
public void FlashRed(float duration)
|
||||
{
|
||||
redFlashPanel.gameObject.SetActive(true);
|
||||
redFlashPanel.DOFade(1, duration / 2).OnComplete(() =>
|
||||
{
|
||||
redFlashPanel.DOFade(0, duration / 2).OnComplete(() =>
|
||||
{
|
||||
redFlashPanel.gameObject.SetActive(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca4bf19c2266a604d87f4050b78b7d05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -18,7 +18,7 @@ public class MessageBox : MonoBehaviour
|
||||
else
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject); // 可选:保持在场景加载之间
|
||||
//DontDestroyOnLoad(gameObject); // 可选:保持在场景加载之间
|
||||
}
|
||||
}
|
||||
// Yarn Command处理方法
|
||||
@@ -67,7 +67,7 @@ public class MessageBox : MonoBehaviour
|
||||
}
|
||||
|
||||
// 设置为Null状态
|
||||
public void SetNull()
|
||||
private void SetNull()
|
||||
{
|
||||
state.text = "NO SIGNAL";
|
||||
state.color = Color.blue; // 蓝色
|
||||
|
||||
Reference in New Issue
Block a user