diff --git a/Assets/Scripts/MiniGame/Peipei/Eye/EyeTarget.cs b/Assets/Scripts/MiniGame/Peipei/Eye/EyeTarget.cs
index 53e3f7a3c..2fb0a934f 100644
--- a/Assets/Scripts/MiniGame/Peipei/Eye/EyeTarget.cs
+++ b/Assets/Scripts/MiniGame/Peipei/Eye/EyeTarget.cs
@@ -1,3 +1,4 @@
+using System;
using AibisDream;
using AibisDream.Kit;
using AibisDream.Utility;
@@ -6,17 +7,23 @@ using UnityEngine;
public class EyeTarget : MonoBehaviour
{
+ private static readonly int AlphaId = Shader.PropertyToID("_Alpha");
+
public Transform targetTransform;
[Header("Optional overlay sprite for UF imagination")]
[SerializeField] private SpriteRenderer imageSpriteRender;
+ [Header("Wrong-color overlay (e.g. plantError); auto-resolved from sibling if unset")]
+ [SerializeField] private SpriteRenderer wrongColorSpriteRenderer;
+
[SerializeField] private Shader unifiedSpriteShader;
[SerializeField] private EyeTargetVisual unifiedVisual;
public Color _color;
private EyeVisualSettings visualSettings = new();
+ private Material wrongColorMaterial;
private void Awake()
{
@@ -27,6 +34,7 @@ public class EyeTarget : MonoBehaviour
return;
}
+ EnsureWrongColorOverlay();
EnsureUnifiedVisual(spriteRenderer);
DisableLegacyChildRenderers();
DisableLegacySiblingRenderers();
@@ -53,6 +61,7 @@ public class EyeTarget : MonoBehaviour
public void KillVisualTweens()
{
unifiedVisual?.KillActiveTweens();
+ wrongColorMaterial?.DOKill();
}
private void EnsureVisualReady()
@@ -115,11 +124,13 @@ public class EyeTarget : MonoBehaviour
public void SetToNoWrongColor()
{
unifiedVisual?.SetWrongColor(0f);
+ SetWrongColorOverlayAlpha(0f);
}
public void SetToWrongColor()
{
unifiedVisual?.SetWrongColor(1f);
+ SetWrongColorOverlayAlpha(1f);
}
public void FadeOut(float duration)
@@ -139,11 +150,13 @@ public class EyeTarget : MonoBehaviour
public void WrongColorIn(float duration)
{
unifiedVisual?.TweenWrongColor(1f, duration)?.SetEase(Ease.InOutSine);
+ TweenWrongColorOverlay(1f, duration);
}
public void WrongColorOut(float duration)
{
unifiedVisual?.TweenWrongColor(0f, duration)?.SetEase(Ease.InOutSine);
+ TweenWrongColorOverlay(0f, duration);
}
public void BlurIn(float duration)
@@ -291,6 +304,90 @@ public class EyeTarget : MonoBehaviour
///
/// 禁用同组下旧版 overlay(如 posterNoColor / computernocolor),避免盖住 unified 效果。
///
+ private void EnsureWrongColorOverlay()
+ {
+ if (wrongColorSpriteRenderer == null && transform.parent != null)
+ {
+ string errorName = $"{gameObject.name}Error";
+ foreach (var renderer in transform.parent.GetComponentsInChildren(true))
+ {
+ if (string.Equals(renderer.gameObject.name, errorName, StringComparison.OrdinalIgnoreCase))
+ {
+ wrongColorSpriteRenderer = renderer;
+ break;
+ }
+ }
+ }
+
+ if (wrongColorSpriteRenderer == null)
+ {
+ return;
+ }
+
+ wrongColorMaterial = Application.isPlaying
+ ? wrongColorSpriteRenderer.material
+ : wrongColorSpriteRenderer.sharedMaterial;
+ wrongColorSpriteRenderer.enabled = true;
+ SetWrongColorOverlayAlpha(0f);
+ }
+
+ private void SetWrongColorOverlayAlpha(float alpha)
+ {
+ if (wrongColorSpriteRenderer == null)
+ {
+ return;
+ }
+
+ alpha = Mathf.Clamp01(alpha);
+ if (alpha > 0f)
+ {
+ wrongColorSpriteRenderer.gameObject.SetActive(true);
+ wrongColorSpriteRenderer.enabled = true;
+ }
+
+ if (wrongColorMaterial != null && wrongColorMaterial.HasProperty(AlphaId))
+ {
+ wrongColorMaterial.SetFloat(AlphaId, alpha);
+ }
+
+ if (alpha <= 0f)
+ {
+ wrongColorSpriteRenderer.gameObject.SetActive(false);
+ }
+ }
+
+ private void TweenWrongColorOverlay(float alpha, float duration)
+ {
+ if (wrongColorSpriteRenderer == null || wrongColorMaterial == null || !wrongColorMaterial.HasProperty(AlphaId))
+ {
+ return;
+ }
+
+ if (alpha > 0f)
+ {
+ wrongColorSpriteRenderer.gameObject.SetActive(true);
+ wrongColorSpriteRenderer.enabled = true;
+ }
+
+ wrongColorMaterial.DOKill();
+ wrongColorMaterial
+ .DOFloat(alpha, AlphaId, duration)
+ .SetEase(Ease.InOutSine)
+ .OnComplete(() =>
+ {
+ if (alpha <= 0f && wrongColorSpriteRenderer != null)
+ {
+ wrongColorSpriteRenderer.gameObject.SetActive(false);
+ }
+ });
+ }
+
+ private static bool IsWrongColorOverlayRenderer(SpriteRenderer renderer)
+ {
+ return renderer != null
+ && renderer.gameObject.name.EndsWith("Error", StringComparison.OrdinalIgnoreCase);
+ }
+
private void DisableLegacySiblingRenderers()
{
Transform groupRoot = transform.parent;
@@ -316,6 +413,11 @@ public class EyeTarget : MonoBehaviour
continue;
}
+ if (IsWrongColorOverlayRenderer(renderer))
+ {
+ continue;
+ }
+
renderer.enabled = false;
}
}