feat: 梦境门、热力图、身体模块与终端 UI 全流程逻辑

Made-with: Cursor
This commit is contained in:
2026-03-28 19:37:52 +08:00
parent 215725d2a0
commit fc03cfdd4a
5 changed files with 86 additions and 20 deletions
@@ -143,6 +143,39 @@ public class HeatMapController : MonoBehaviour
SetDataToMaterial();
}
/// <summary>
/// 热点尺寸:优先 SpriteRenderer,其次 UI Image,最后用 RectTransform 尺寸。
/// </summary>
private static bool TryGetHotspotSize(Transform t, out Vector2 size)
{
size = default;
if (t == null) return false;
var sr = t.GetComponent<SpriteRenderer>();
if (sr != null && sr.sprite != null)
{
var b = sr.sprite.bounds.size;
size = new Vector2(b.x, b.y);
return true;
}
var image = t.GetComponent<Image>();
if (image != null && image.sprite != null)
{
var b = image.sprite.bounds.size;
size = new Vector2(b.x, b.y);
return true;
}
if (t is RectTransform rt)
{
size = new Vector2(rt.rect.width, rt.rect.height);
return size.x > 0f || size.y > 0f;
}
return false;
}
public void SetDataToMaterial()
{
if (tempture == 0)
@@ -169,9 +202,18 @@ public class HeatMapController : MonoBehaviour
// }
if (Pos == null || heatMaterial == null)
return;
for (int i = 0; i < 7; i++)
{
//RectTransform transform=Pos[i].GetComponent<RectTransform>();
if (Pos[i] == null)
{
points[i] = Vector4.zero;
properties[i] = Vector4.zero;
continue;
}
Transform currentTransform = Pos[i].GetComponent<Transform>();
if (i == 0)
@@ -188,12 +230,10 @@ public class HeatMapController : MonoBehaviour
0); // (x, y, z, temperature)
}
Sprite currentSprite = currentTransform.GetComponent<SpriteRenderer>().sprite;
properties[i] =
new Vector4(currentSprite.bounds.size.x, currentSprite.bounds.size.y, 0.0f,
0.0f); // (boxsize x, boxsize y, unused, unused)
//properties[i] = new Vector4(transform.rect.width*1, transform.rect.height*1, 0.0f, 0.0f); // (boxsize x, boxsize y, unused, unused)
//properties[i] = new Vector4(transform.rect.width*1, transform.rect.height*1, 0.0f, 0.0f); // (boxsize x, boxsize y, unused, unused)
if (!TryGetHotspotSize(currentTransform, out var boxSize))
boxSize = Vector2.one;
properties[i] = new Vector4(boxSize.x, boxSize.y, 0.0f, 0.0f);
}
// 将数据传递给 Shader
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -180,7 +180,7 @@ namespace AibisDream.FixSystem
{
HeatValue = targetHeatValue;
heatMapController.SetTemptureDirect(HeatValue);
heatMapController?.SetTemptureDirect(HeatValue);
}
public void ShowHeatMap()
@@ -1,4 +1,4 @@
using System;
using System;
using AibisDream.Framework;
using Newtonsoft.Json;
using UnityEngine;
@@ -24,6 +24,11 @@ namespace AibisDream.FixSystem
private Material _alarmMaterial;
private Material _originalMaterial; // 原材质
/// <summary>
/// Yarn 可能在 Start 里异步加载材质完成前就调用 ModuleHightLight,需记下来待加载后再套材质。
/// </summary>
private bool _wantsHighlight;
[SerializeField]
private SpriteRenderer targetSpriteRenderer; // 目标的 SpriteRenderer
@@ -93,6 +98,8 @@ namespace AibisDream.FixSystem
_alarmMaterial = alarmHandle.Result;
else
Debug.LogError("[BodyModule] Failed to load AlarmMaterial");
ApplyHighlightVisual();
}
#region
@@ -157,11 +164,16 @@ namespace AibisDream.FixSystem
public void Highlight(bool enable)
{
if (targetSpriteRenderer != null && _highlightMaterial != null &&
targetSpriteRenderer.material != _alarmMaterial)
{
targetSpriteRenderer.material = enable ? _highlightMaterial : _originalMaterial;
}
_wantsHighlight = enable;
ApplyHighlightVisual();
}
private void ApplyHighlightVisual()
{
if (targetSpriteRenderer == null || _highlightMaterial == null) return;
if (_alarmMaterial != null && targetSpriteRenderer.material == _alarmMaterial) return;
targetSpriteRenderer.material = _wantsHighlight ? _highlightMaterial : _originalMaterial;
}
public void Alarm(bool enable)
@@ -40,7 +40,9 @@ namespace AibisDream
[SerializeField] private float postMorphBootDelay = 0.12f;
[SerializeField] private float referenceSnapMorphProgress = 0.08f;
[SerializeField] private Vector2 referenceSnapPadding = new(0.18f, 0.18f);
[Tooltip("终端变形时 sceneBlackOverlay 淡入目标透明度(背景压暗)")]
[SerializeField] private float blackoutAlpha = 0.92f;
[Tooltip("黑场淡入时长(与终端 morph 并行)")]
[SerializeField] private float blackoutFadeInDuration = 0.08f;
[SerializeField] private float blackoutFadeOutDuration = 0.12f;
@@ -217,7 +219,13 @@ namespace AibisDream
flashOverlay.SetAlpha(0f);
if (sceneBlackOverlay != null)
{
sceneBlackOverlay.gameObject.SetActive(true);
sceneBlackOverlay.SetAlpha(0f);
}
if (backgroundCutDelay > 0f)
yield return new WaitForSeconds(backgroundCutDelay);
if (preMorphHoldDuration > 0f)
yield return new WaitForSeconds(preMorphHoldDuration);
@@ -225,11 +233,16 @@ namespace AibisDream
if (terminalUI != null)
{
float morph = 0f;
yield return DOTween.To(() => morph, v =>
var morphTween = DOTween.To(() => morph, v =>
{
morph = v;
terminalUI.MorphProgress = v;
}, 1f, 0.82f).SetEase(morphEase).WaitForCompletion();
}, 1f, 0.82f).SetEase(morphEase);
if (sceneBlackOverlay != null)
sceneBlackOverlay.DOFade(blackoutAlpha, Mathf.Max(0.01f, blackoutFadeInDuration));
yield return morphTween.WaitForCompletion();
}
ResetDoorShellScale();
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using AibisDream;
using DG.Tweening;
using Shapes;
using TMPro;
@@ -761,8 +762,7 @@ namespace AibisDream.UI
}
else if (c == '\n' || c == '\r')
{
if (_inputBuffer.Length > 0)
EnterConfirmPhase();
EnterConfirmPhase();
return;
}
else if (!char.IsControl(c) && _inputBuffer.Length < maxInputLength)
@@ -784,7 +784,7 @@ namespace AibisDream.UI
private void HandleConfirmInput()
{
if (Input.GetKeyDown(KeyCode.Y))
if (Input.GetKeyDown(KeyCode.Y) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
{
CommitPendingInputToHistory(includeConfirmPrompt: true);
_phase = TerminalPhase.EndAnimation;
@@ -812,6 +812,7 @@ namespace AibisDream.UI
yield return PlayCrashEnding();
_phase = TerminalPhase.Done;
DreamDoorSystem.Instance?.HideAll();
yield return new WaitForSeconds(1f);
DialogController.Instance.StartDialogNode(onCompleteNode);
}