Работаю над системой ржавчины
This commit is contained in:
1 parent
3e13180e34
commit
9a52384dbb
19 files changed
+924
-33
No files matched your search
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class CarPartVisuals : MonoBehaviour
|
||||
{
|
||||
private Renderer partRenderer;
|
||||
private MaterialPropertyBlock propertyBlock;
|
||||
|
||||
private static readonly int RustAmountProp = Shader.PropertyToID("_RustAmount");
|
||||
private static readonly int BaseColorProp = Shader.PropertyToID("_BaseColor");
|
||||
|
||||
[Range(0f, 1f)] [SerializeField] private float currentRust = 0f;
|
||||
[SerializeField] private Color currentColor = Color.white;
|
||||
|
||||
public float CurrentRust => currentRust;
|
||||
public Color CurrentColor => currentColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
partRenderer = GetComponent<Renderer>();
|
||||
propertyBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
public void SetRust(float amount)
|
||||
{
|
||||
currentRust = Mathf.Clamp01(amount);
|
||||
ApplyProperties();
|
||||
}
|
||||
|
||||
public void SetPaintColor(Color newColor)
|
||||
{
|
||||
currentColor = newColor;
|
||||
ApplyProperties();
|
||||
}
|
||||
|
||||
private void ApplyProperties()
|
||||
{
|
||||
if (partRenderer == null) return;
|
||||
|
||||
partRenderer.GetPropertyBlock(propertyBlock);
|
||||
propertyBlock.SetFloat(RustAmountProp, currentRust);
|
||||
propertyBlock.SetColor(BaseColorProp, currentColor);
|
||||
partRenderer.SetPropertyBlock(propertyBlock);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user