Add FloorVisibilityManager for dynamic floor visibility management and update material properties for transparency effects

This commit is contained in:
2025-12-13 01:35:22 +01:00
parent 189bbb7ae7
commit 7b1eb645ef
13 changed files with 348 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
using System;
using Core.Domain.Status;
using Core.Domain.Status.Effects;
using KBCore.Refs;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -23,10 +24,16 @@ namespace Infrastructure.Unity
[SerializeField] private float groundCheckDistance = 1.5f;
[Self][SerializeField] private Rigidbody rb;
[Self][SerializeField] private MeshRenderer meshRenderer;
private InputSystem_Actions _actions;
private Vector2 _moveInput;
private Transform _camTransform;
private MaterialPropertyBlock _propBlock;
private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor");
private static readonly int EmissionColorProperty = Shader.PropertyToID("_EmissionColor");
private Color _defaultColor = Color.white;
public Rigidbody Rigidbody => rb;
public StatusManager Status { get; private set; }
@@ -58,15 +65,21 @@ namespace Infrastructure.Unity
}
rb.freezeRotation = true;
// RB gravity is controlled by capabilities
_propBlock = new MaterialPropertyBlock();
if (meshRenderer.material.HasProperty(ColorProperty))
{
_defaultColor = meshRenderer.material.GetColor(ColorProperty);
}
}
private void Update()
{
Status.Tick(Time.deltaTime);
// Apply Status logic
rb.useGravity = !Status.CurrentCapabilities.CanHover;
UpdateVisuals();
}
private void FixedUpdate()
@@ -171,5 +184,40 @@ namespace Infrastructure.Unity
{
_moveInput = Vector2.zero;
}
private void UpdateVisuals()
{
var targetColor = _defaultColor;
var emissionColor = Color.black;
var caps = Status.CurrentCapabilities;
if (caps.CanHover)
{
targetColor = EffectColors.HoverColor;
emissionColor = EffectColors.HoverColor * 0.5f;
}
else if (!caps.CanTriggerDecay)
{
targetColor = EffectColors.LightFootedColor;
}
else if (caps.SpeedMultiplier > 1.2f)
{
targetColor = EffectColors.SpeedBoostColor;
emissionColor = EffectColors.SpeedBoostColor * 0.5f;
}
meshRenderer.GetPropertyBlock(_propBlock);
var currentColor = _propBlock.GetColor(ColorProperty);
if (currentColor.a == 0) currentColor = _defaultColor;
var newColor = Color.Lerp(currentColor, targetColor, Time.deltaTime * 5f);
_propBlock.SetColor(ColorProperty, newColor);
_propBlock.SetColor(EmissionColorProperty, emissionColor);
meshRenderer.SetPropertyBlock(_propBlock);
}
}
}