fix(fix-system): 修复线缆未跟随环境光变色
This commit is contained in:
@@ -37,6 +37,7 @@ public class CableMeshRenderer : MonoBehaviour
|
||||
|
||||
private float _tipTaperFraction; // 末端收窄段占全长比例(0 关闭)
|
||||
private float _tipTaperScale = 1f;
|
||||
private Color _environmentTint = Color.white;
|
||||
|
||||
private readonly List<Vector3> _vertices = new(1024);
|
||||
private readonly List<Color32> _colors = new(1024);
|
||||
@@ -69,6 +70,14 @@ public class CableMeshRenderer : MonoBehaviour
|
||||
_bands = bands ?? System.Array.Empty<Band>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置动态网格的环境光色调。RGB 会调制各色带,Alpha 保持原值。
|
||||
/// </summary>
|
||||
public void SetEnvironmentTint(Color tint)
|
||||
{
|
||||
_environmentTint = tint;
|
||||
}
|
||||
|
||||
/// <summary>末端宽度收窄:最后 fraction 段从全宽线性收到 scale 倍(线头略细于孔圈)。</summary>
|
||||
public void SetTipTaper(float fraction, float scale)
|
||||
{
|
||||
@@ -124,7 +133,11 @@ public class CableMeshRenderer : MonoBehaviour
|
||||
{
|
||||
int baseIndex = _vertices.Count;
|
||||
float half = band.width * 0.5f;
|
||||
Color32 color = band.color;
|
||||
Color32 color = new Color(
|
||||
band.color.r * _environmentTint.r,
|
||||
band.color.g * _environmentTint.g,
|
||||
band.color.b * _environmentTint.b,
|
||||
band.color.a);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
|
||||
@@ -699,6 +699,10 @@ public class PhysicCable : MonoBehaviour
|
||||
}
|
||||
|
||||
// 插接时线缆末端由平头切面改为圆头端帽(线自身的圆头,同旧 LineRenderer),读作"插进孔里"
|
||||
var panelLight = AibisDream.FixSystem.FixPanelSystem.Instance?.PanelLight;
|
||||
_cableMesh.SetEnvironmentTint(panelLight != null
|
||||
? panelLight.CurrentEnvironmentTint
|
||||
: Color.white);
|
||||
_cableMesh.UpdateMesh(src, count, FindTailStart(count), State == CableState.Plugged);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace AibisDream.FixSystem
|
||||
private const string PANEL_LIGHT_OFF_SFX = "event:/ActionFB/light_flicker_off";
|
||||
private const float MIN_FLICKER_INTERVAL = 3f;
|
||||
private const float MAX_FLICKER_INTERVAL = 8f;
|
||||
private const float ENVIRONMENT_COLOR_INFLUENCE = 0.65f;
|
||||
private const float ENVIRONMENT_INTENSITY_INFLUENCE = 0.35f;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -87,6 +89,38 @@ namespace AibisDream.FixSystem
|
||||
private Tween lightStateTransitionTween;
|
||||
private LightState currentState = LightState.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// 当前环境灯相对于 Normal 状态的实时色调。
|
||||
/// 用于无法直接接收 URP 2D Light 的动态网格等渲染对象。
|
||||
/// </summary>
|
||||
public Color CurrentEnvironmentTint
|
||||
{
|
||||
get
|
||||
{
|
||||
if (environmentLight == null) return Color.white;
|
||||
|
||||
float currentIntensity = Mathf.Max(0f, environmentLight.intensity);
|
||||
if (currentIntensity <= Mathf.Epsilon) return Color.black;
|
||||
|
||||
float intensityScale = currentIntensity /
|
||||
Mathf.Max(0.01f, normalEnvironmentIntensity);
|
||||
Color lightColor = environmentLight.color;
|
||||
Color softenedColor = Color.Lerp(
|
||||
Color.white,
|
||||
new Color(lightColor.r, lightColor.g, lightColor.b, 1f),
|
||||
ENVIRONMENT_COLOR_INFLUENCE);
|
||||
float softenedIntensity = Mathf.Lerp(
|
||||
1f,
|
||||
intensityScale,
|
||||
ENVIRONMENT_INTENSITY_INFLUENCE);
|
||||
return new Color(
|
||||
softenedColor.r * softenedIntensity,
|
||||
softenedColor.g * softenedIntensity,
|
||||
softenedColor.b * softenedIntensity,
|
||||
1f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
|
||||
Reference in New Issue
Block a user