Color Interpolation

This commit is contained in:
Tim
2025-07-21 23:19:27 +02:00
parent a3ecb5774b
commit 67eb99b749

View File

@@ -39,6 +39,9 @@ public class ModelBehaviour : MonoBehaviour, IResettable
public PortSelector PortSelector;
public int Index = -1;
const int FinalColorTick = 60; //shouldnt take too long
Color _oldColor = Color.black;
int colorTick = FinalColorTick;
Color _color = Color.black;
Color Color
{
@@ -46,10 +49,8 @@ public class ModelBehaviour : MonoBehaviour, IResettable
set
{
var clonedMaterial = new Material(meshRenderer.material); //clone da sonst alle anderen mit dem mat auch colorchanged werden
clonedMaterial.color = value;
meshRenderer.material = clonedMaterial;
meshRenderer.material = clonedMaterial; // Actual color setting happens in Update
Debug.Log($"{name}: Set color from {_color} to {value}");
_color = value;
if (Model.Passthrough)
{
Debug.Log($"{name}: Passthrough {_children.Count}");
@@ -59,6 +60,9 @@ public class ModelBehaviour : MonoBehaviour, IResettable
go.GetComponent<ChildModelBehaviour>().Color = value;
}
}
_oldColor = _color;
_color = value;
colorTick = 0;
}
}
@@ -73,6 +77,15 @@ public class ModelBehaviour : MonoBehaviour, IResettable
ModelManager = FindFirstObjectByType<ModelManager>();
}
void Update()
{
if (colorTick < FinalColorTick)
{
meshRenderer.material.color = Color.Lerp(_oldColor, _color, colorTick * 1.0f / FinalColorTick);
colorTick++;
}
}
void LateUpdate()
{
if (!lateInited)