317 lines
9.5 KiB
C#
317 lines
9.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using AibisDream;
|
|
using AibisDream.FixSystem;
|
|
using UnityEngine.Rendering;
|
|
using Yarn.Unity;
|
|
using DG.Tweening;
|
|
using VolFx;
|
|
using System;
|
|
using AibisDream.Kit;
|
|
|
|
public class UFSystem : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
private GameObject _UFCover;
|
|
private GameObject _UAudioule;
|
|
|
|
private EyeSystem eyeSystem;
|
|
|
|
public GameObject UFPanel;
|
|
|
|
public SpriteRenderer face;
|
|
|
|
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 动画
|
|
|
|
public enum UFState
|
|
{
|
|
UF,
|
|
imagination,
|
|
memory
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
eyeSystem = FindObjectOfType<EyeSystem>();
|
|
}
|
|
|
|
public void TweenWeight(Volume postProcessingVolume, float targetWeight, float duration)
|
|
{
|
|
// 动态调整权重
|
|
DOTween.To(() => postProcessingVolume.weight, x => postProcessingVolume.weight = x, targetWeight, duration);
|
|
}
|
|
|
|
[YarnCommand("UF_spriteIn")]
|
|
public IEnumerator UF_spriteIn(float duration = 1.5f)
|
|
{
|
|
if (eyeSystem.CurrentTarget != null)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
eyeSystem.CurrentTarget.ImageIn(duration);
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
|
|
[YarnCommand("UF_spriteOut")]
|
|
public IEnumerator UF_spriteOut(float duration = 1.5f)
|
|
{
|
|
if (eyeSystem.CurrentTarget != null)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
eyeSystem.CurrentTarget.ImageOut(duration);
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
|
|
[YarnCommand("UF_AllspriteIn")]
|
|
public IEnumerator UF_AllspriteIn(float duration = 1.5f)
|
|
{
|
|
foreach (EyeTarget target in eyeSystem.Targets)
|
|
{
|
|
target.ImageIn(duration);
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
|
|
[YarnCommand("UF_AllspriteOut")]
|
|
public IEnumerator UF_AllspriteOut(float duration = 1.5f)
|
|
{
|
|
foreach (EyeTarget target in eyeSystem.Targets)
|
|
{
|
|
target.ImageOut(duration);
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
|
|
[YarnCommand("UF_faceIn")]
|
|
public IEnumerator UF_faceIn(float duration = 1.5f)
|
|
{
|
|
face.gameObject.SetActive(true);
|
|
face.DOFade(1f, duration);
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
|
|
[YarnCommand("UF_faceOut")]
|
|
public IEnumerator UF_faceOut(float duration = 1.5f)
|
|
{
|
|
face.DOFade(0f, duration);
|
|
yield return new WaitForSeconds(duration);
|
|
face.gameObject.SetActive(false);
|
|
}
|
|
|
|
[YarnCommand("UF_ImaginationEffectIn")]
|
|
public IEnumerator UF_ImaginationEffectIn(float duration = 1.5f)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(imageVolume, 1, duration);
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_ImaginationEffectOut")]
|
|
public IEnumerator UF_ImaginationEffectOut(float duration = 1.5f)
|
|
{
|
|
TweenWeight(imageVolume, 0, duration);
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_MemoryEffectIn")]
|
|
public IEnumerator UF_MemoryEffectIn(float duration = 1.5f)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(finalVolume, 1, duration);
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_MemoryEffectOut")]
|
|
public IEnumerator UF_MemoryEffectOut(float duration = 1.5f)
|
|
{
|
|
TweenWeight(finalVolume, 0, duration);
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_EyeTargetAscillIn")]
|
|
public IEnumerator UF_EyeTargetAscillIn(float duration = 1.5f)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(imageAscillVolume, 1, duration);
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_EyeTargetAscillOut")]
|
|
public IEnumerator UF_EyeTargetAscillOut(float duration = 1.5f)
|
|
{
|
|
TweenWeight(imageAscillVolume, 0, duration);
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
yield return new WaitForSeconds(0);
|
|
}
|
|
|
|
[YarnCommand("UF_SetBorkenValue")]
|
|
public void UF_Borken(int value)
|
|
{
|
|
FullAscillVolume.profile.TryGet<AsciiVol>(out ascii);
|
|
ascii.m_Depth.value = value;
|
|
ascii.m_Ascii.value = Color.red;
|
|
}
|
|
|
|
|
|
[YarnCommand("StartUFEffect_loop")]
|
|
public void UFImageLoop()
|
|
{
|
|
StartCoroutine(UFImageLoopProcess());
|
|
}
|
|
|
|
[YarnCommand("StopUFEffect_loop")]
|
|
public void StopUFImageLoop()
|
|
{
|
|
isLoopImage = false;
|
|
}
|
|
|
|
[YarnCommand("UF_fightEffect")]
|
|
public void UF_fightEffect()
|
|
{
|
|
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); // 无限循环
|
|
}
|
|
|
|
[YarnCommand("UF_StopfightEffect")]
|
|
public void UF_StopfightEffect()
|
|
{
|
|
scaleTween.Kill();
|
|
}
|
|
|
|
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(UF_spriteIn(0.5f));
|
|
StartCoroutine(UF_ImaginationEffectIn(0.5f));
|
|
eyeSystem.Targets[index].ImageIn(0.5f);
|
|
yield return new WaitForSeconds(0.5f);
|
|
StartCoroutine(UF_ImaginationEffectOut(0.5f));
|
|
StartCoroutine(UF_MemoryEffectIn(0.5f));
|
|
yield return new WaitForSeconds(1f);
|
|
eyeSystem.Targets[index].ImageOut(0.5f);
|
|
StartCoroutine(UF_MemoryEffectOut(0.5f));
|
|
index++;
|
|
// 如果到达列表末尾,则回到开头
|
|
if (index >= eyeSystem.Targets.Count - 2)
|
|
{
|
|
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>();
|
|
_UAudioule = bodyModuleSystem.FindBodyModuleByName("UF").gameObject;
|
|
if (_UAudioule.activeInHierarchy)
|
|
{
|
|
_UAudioule.SetActive(false);
|
|
}
|
|
}
|
|
|
|
[YarnCommand("UF_SwitchState")]
|
|
public IEnumerator SwitchState(string stateName, float duration)
|
|
{
|
|
UFState state;
|
|
if (!Enum.TryParse(stateName, true, out state))
|
|
{
|
|
Debug.LogError($"Invalid state name: {stateName}");
|
|
yield break;
|
|
}
|
|
|
|
switch (state)
|
|
{
|
|
case UFState.UF:
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(imageAscillVolume, 1, duration);
|
|
TweenWeight(imageVolume, 0, duration);
|
|
TweenWeight(finalVolume, 0, duration);
|
|
break;
|
|
|
|
case UFState.imagination:
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(imageAscillVolume, 0, duration);
|
|
TweenWeight(imageVolume, 1, duration);
|
|
TweenWeight(finalVolume, 0, duration);
|
|
break;
|
|
|
|
case UFState.memory:
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine");
|
|
TweenWeight(imageAscillVolume, 0, duration);
|
|
TweenWeight(imageVolume, 0, duration);
|
|
TweenWeight(finalVolume, 1, duration);
|
|
break;
|
|
|
|
default:
|
|
Debug.LogError($"Unhandled state: {state}");
|
|
yield break;
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration);
|
|
}
|
|
} |