Files
aibis-dream/Assets/Scripts/MiniGame/Peipei/UF/UFSystem.cs
T

204 lines
6.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AibisDream;
using AibisDream.FixSystem;
using AibisDream.Framework;
using Cinemachine;
using UnityEngine.Rendering;
using Yarn.Unity;
using DG.Tweening;
using VolFx;
using System.Drawing.Text; // 引入 DoTween 命名空间
public class UFSystem : MonoBehaviour
{
// Start is called before the first frame update
private GameObject _UFCover;
private GameObject _UFModule;
private EyeSystem eyeSystem;
public GameObject UFPanel;
private bool isLoopImage = false;
[SerializeField] private Volume FullAscillVolume;
[SerializeField] private Volume imageAscillVolume;
[SerializeField] private Volume imageVolume;
[SerializeField] private Volume finalVolume;
private AsciiVol ascii;
private Tween scaleTween; // 存储 Tween 动画
private void Awake()
{
FixSystemCenter.SystemDic.Register(this);
var virtualCam = transform.Find("UF Camera").GetComponent<ICinemachineCamera>();
CameraKit.Instance.RegisterCamera(CameraEnum.UF, virtualCam);
eyeSystem = FindObjectOfType<EyeSystem>();
}
public void TweenWeight(Volume postProcessingVolume, float targetWeight, float duration)
{
// 动态调整权重
DOTween.To(() => postProcessingVolume.weight, x => postProcessingVolume.weight = x, targetWeight, duration);
}
[YarnCommand("UFEffect_ImageIn")]
public IEnumerator UFImageIn(float duration = 1.5f)
{
if (eyeSystem.CurrentTarget != null)
{
AudioManager.RandomPlayInteraction("colorimagine");
eyeSystem.CurrentTarget.ImageIn(duration);
TweenWeight(imageVolume, 1, duration);
}
yield return new WaitForSeconds(duration);
}
[YarnCommand("UFEffect_ImageOut")]
public IEnumerator UFImageOut(float duration = 1.5f)
{
if (eyeSystem.CurrentTarget != null)
{
eyeSystem.CurrentTarget.ImageOut(duration);
TweenWeight(imageVolume, 0, duration);
TweenWeight(imageAscillVolume, 1, duration);
TweenWeight(finalVolume, 0, duration);
AudioManager.RandomPlayInteraction("colorimagine");
}
yield return new WaitForSeconds(0);
}
// [YarnCommand("UFEffect_Processing")]
// public IEnumerator UFProcessing(EyeTarget eyeSystem.CurrentTarget)
// {
// if (eyeSystem.CurrentTarget != null)
// {
// TweenWeight(imageVolume,1,1);
// TweenWeight(imageAscillVolume,1,1);
// TweenWeight(finalVolume,0,1);
// AudioManager.RandomPlayInteraction("colorimagine");
// }
// yield return new WaitForSeconds(1);
// }
// [YarnCommand("UFEffect_ImageOutFinfish")]
// public IEnumerator UFImageOutFinfish(float duration=1.5f)
// {
// if (eyeSystem.CurrentTarget != null)
// {
// AudioManager.RandomPlayInteraction("colorimagine");
// eyeSystem.CurrentTarget.ImageOut(2);
// TweenWeight(imageVolume,0,2);
// }
// yield return new WaitForSeconds(2);
// }
[YarnCommand("UFEffect_ImageFinish")]
public IEnumerator UFImageFinish(float duration = 1.5f)
{
if (eyeSystem.CurrentTarget != null)
{
AudioManager.RandomPlayInteraction("colorimagine");
TweenWeight(imageVolume, 0, duration);
TweenWeight(imageAscillVolume, 0, duration);
TweenWeight(finalVolume, 1, duration);
}
yield return new WaitForSeconds(duration);
}
[YarnCommand("StartUFEffect_loop")]
public void UFImageLoop()
{
StartCoroutine(UFImageLoopProcess());
}
[YarnCommand("StopUFEffect_loop")]
public void StopUFImageLoop()
{
isLoopImage = false;
}
[YarnCommand("UFEffect_ImageAll")]
public void ImageAll()
{
UFImageIn(1);
foreach (EyeTarget target in eyeSystem.Targets)
{
target.ImageIn(1);
}
scaleTween = DOTween.To(() => 0f, t =>
{
// 根据 t(0 到 1 的变化)更新多个值
imageVolume.weight = Mathf.Lerp(0f, 1f, t); // 例如:imageVolume 的 weight
imageAscillVolume.weight = Mathf.Lerp(0f, 1f, t); // 假设 saturation 是另一个值
finalVolume.weight = Mathf.Lerp(1f, 0f, t); // 假设 contrast 是另一个值
}, 1f, 1f)
.SetEase(Ease.InOutSine) // 平滑缓动
.SetLoops(-1, LoopType.Yoyo); // 无限循环
}
public IEnumerator UFImageLoopProcess()
{
int index = 0;
isLoopImage = true;
while (isLoopImage) // 无限循环
{
eyeSystem.StartCoroutine(eyeSystem.SetTargetCoroutine(eyeSystem.Targets[index].name, false));
yield return new WaitForSeconds(0.5f);
StartCoroutine(UFImageIn(0.5f));
eyeSystem.Targets[index].ImageIn(0.5f);
yield return new WaitForSeconds(0.5f);
StartCoroutine(UFImageFinish(0.5f));
yield return new WaitForSeconds(1f);
eyeSystem.Targets[index].ImageOut(0.5f);
StartCoroutine(UFImageOut(0.5f));
index++;
// 如果到达列表末尾,则回到开头
if (index >= eyeSystem.Targets.Count)
{
index = 0;
}
//yield return new WaitForSeconds(1f); // 每隔1秒打印一次
}
}
public void OpenUFView()
{
if (!FullAscillVolume.gameObject.activeInHierarchy)
{
FullAscillVolume.gameObject.SetActive(true);
imageAscillVolume.weight = 1;
imageVolume.weight = 0;
finalVolume.weight = 0;
}
}
public void CloseUFView()
{
if (FullAscillVolume.gameObject.activeInHierarchy)
{
FullAscillVolume.gameObject.SetActive(false);
imageAscillVolume.weight = 1;
imageVolume.weight = 0;
finalVolume.weight = 0;
//scaleTween.Kill();
}
}
public void OpenCover()
{
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
_UFCover = bodyModuleSystem.FindBodyModuleByName("UF").transform.Find("Cover").gameObject;
if (_UFCover.activeInHierarchy)
{
_UFCover.SetActive(false);
}
}
public void RemoveUF()
{
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
_UFModule = bodyModuleSystem.FindBodyModuleByName("UF").gameObject;
if (_UFModule.activeInHierarchy)
{
_UFModule.SetActive(false);
}
}
}