using System; using System.Collections; using UnityEngine; using AibisDream; using AibisDream.FixSystem; using UnityEngine.Rendering; using Yarn.Unity; using DG.Tweening; using VolFx; using AibisDream.Kit; public class UFSystem : MonoBehaviour { private GameObject _UFCover; private GameObject _UAudioule; private EyeSystem eyeSystem; public GameObject UFPanel; public SpriteRenderer face; private bool isLoopImage; [Header("Global UF Cover")] [SerializeField] private Volume FullAscillVolume; [Header("Legacy Volumes (unused; kept for scene refs)")] [SerializeField] private Volume imageAscillVolume; [SerializeField] private Volume imageVolume; [SerializeField] private Volume finalVolume; private AsciiVol ascii; private Tween scaleTween; public enum UFState { UF, imagination, memory } private void Awake() { FixSystemCenter.SystemDic.Register(this); eyeSystem = FindObjectOfType(); ResetLegacyTargetVolumes(); } private void ResetLegacyTargetVolumes() { if (imageAscillVolume != null) imageAscillVolume.weight = 0f; if (imageVolume != null) imageVolume.weight = 0f; if (finalVolume != null) finalVolume.weight = 0f; } [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"); eyeSystem?.TweenUnifiedUfWeights(0f, 1f, 0f, duration); yield return new WaitForSeconds(duration); } [YarnCommand("UF_ImaginationEffectOut")] public IEnumerator UF_ImaginationEffectOut(float duration = 1.5f) { eyeSystem?.TweenUnifiedUfWeights(0f, 0f, 0f, duration); AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); yield return new WaitForSeconds(duration); } [YarnCommand("UF_MemoryEffectIn")] public IEnumerator UF_MemoryEffectIn(float duration = 1.5f) { AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); eyeSystem?.TweenUnifiedUfWeights(0f, 0f, 1f, duration); yield return new WaitForSeconds(duration); } [YarnCommand("UF_MemoryEffectOut")] public IEnumerator UF_MemoryEffectOut(float duration = 1.5f) { eyeSystem?.TweenUnifiedUfWeights(0f, 0f, 0f, duration); AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); yield return new WaitForSeconds(duration); } [YarnCommand("UF_EyeTargetAscillIn")] public IEnumerator UF_EyeTargetAscillIn(float duration = 1.5f) { AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); eyeSystem?.TweenUnifiedUfWeights(1f, 0f, 0f, duration); yield return new WaitForSeconds(duration); } [YarnCommand("UF_EyeTargetAscillOut")] public IEnumerator UF_EyeTargetAscillOut(float duration = 1.5f) { eyeSystem?.TweenUnifiedUfWeights(0f, 0f, 0f, duration); AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); yield return new WaitForSeconds(duration); } [YarnCommand("UF_SetBorkenValue")] public void UF_Borken(int value) { if (FullAscillVolume != null && FullAscillVolume.profile.TryGet(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 => { float dreamWeight = Mathf.Lerp(0f, 1f, t); float asciiWeight = Mathf.Lerp(0f, 1f, t); float memoryWeight = Mathf.Lerp(1f, 0f, t); eyeSystem?.SetUnifiedUfWeights(asciiWeight, dreamWeight, memoryWeight); }, 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)); yield return new WaitForSeconds(0.5f); StartCoroutine(UF_ImaginationEffectOut(0.5f)); StartCoroutine(UF_MemoryEffectIn(0.5f)); yield return new WaitForSeconds(1f); StartCoroutine(UF_MemoryEffectOut(0.5f)); index++; if (index >= eyeSystem.Targets.Count - 2) { index = 0; } } } public void OpenUFView() { if (FullAscillVolume != null && !FullAscillVolume.gameObject.activeInHierarchy) { FullAscillVolume.gameObject.SetActive(true); } ResetLegacyTargetVolumes(); eyeSystem?.SetUnifiedUfWeights(1f, 0f, 0f); } public void CloseUFView() { if (FullAscillVolume != null && FullAscillVolume.gameObject.activeInHierarchy) { FullAscillVolume.gameObject.SetActive(false); } ResetLegacyTargetVolumes(); eyeSystem?.SetUnifiedUfWeights(0f, 0f, 0f); } public void OpenCover() { var bodyModuleSystem = FixSystemCenter.SystemDic.Get(); _UFCover = bodyModuleSystem.FindBodyModuleByName("UF").transform.Find("Cover").gameObject; if (_UFCover.activeInHierarchy) { _UFCover.SetActive(false); } } public void RemoveUF() { var bodyModuleSystem = FixSystemCenter.SystemDic.Get(); _UAudioule = bodyModuleSystem.FindBodyModuleByName("UF").gameObject; if (_UAudioule.activeInHierarchy) { _UAudioule.SetActive(false); } } [YarnCommand("UF_SwitchState")] public IEnumerator SwitchState(string stateName, float duration) { if (!Enum.TryParse(stateName, true, out UFState state)) { Debug.LogError($"Invalid state name: {stateName}"); yield break; } AudioManager.Instance.PlaySfx("event:/ActionFB/color_imagine"); switch (state) { case UFState.UF: eyeSystem?.TweenUnifiedUfWeights(1f, 0f, 0f, duration); break; case UFState.imagination: eyeSystem?.TweenUnifiedUfWeights(0f, 1f, 0f, duration); break; case UFState.memory: eyeSystem?.TweenUnifiedUfWeights(0f, 0f, 1f, duration); break; default: Debug.LogError($"Unhandled state: {state}"); yield break; } yield return new WaitForSeconds(duration); } }