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