Работаю над системой ржавчины
This commit is contained in:
1 parent
3e13180e34
commit
9a52384dbb
19 files changed
+924
-33
No files matched your search
@@ -6,5 +6,8 @@ public class CarPartData : ScriptableObject
|
||||
[Header("Данные детали")]
|
||||
public string partName = "Передний бампер";
|
||||
public float basePrice = 150f;
|
||||
[Range(0, 100)] public float condition = 100f; // Состояние детали для оценки авто
|
||||
[Range(0, 100)] public float condition = 100f;
|
||||
|
||||
[Header("Коррозия и материалы")]
|
||||
public bool canRust = true;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0de206522eb940258e88b78fd9cd8e0c
|
||||
timeCreated: 1791330354
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CarConditionGenerator : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки спавна")]
|
||||
[Range(0f, 1f)] [SerializeField] private float rustProbability = 0.7f; // Шанс появления ржавчины
|
||||
[SerializeField] private float maxRustAmount = 0.85f;
|
||||
[SerializeField] private Color baseCarColor = Color.gray;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GenerateCondition();
|
||||
}
|
||||
|
||||
[ContextMenu("Сгенерировать состояние")]
|
||||
public void GenerateCondition()
|
||||
{
|
||||
CarPart[] allParts = GetComponentsInChildren<CarPart>(true);
|
||||
|
||||
foreach (var part in allParts)
|
||||
{
|
||||
CarPartVisuals visuals = part.GetComponent<CarPartVisuals>();
|
||||
if (visuals == null) visuals = part.gameObject.AddComponent<CarPartVisuals>();
|
||||
|
||||
// 1. Устанавливаем базовый цвет кузова
|
||||
visuals.SetPaintColor(baseCarColor);
|
||||
|
||||
// 2. Если деталь пластиковая (бампер) — пропускаем ржавчину
|
||||
if (part.Data != null && !part.Data.canRust)
|
||||
{
|
||||
visuals.SetRust(0f);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 3. Рандомизируем ржавчину для металла
|
||||
if (Random.value < rustProbability)
|
||||
{
|
||||
float randomRust = Random.Range(0.2f, maxRustAmount);
|
||||
visuals.SetRust(randomRust);
|
||||
}
|
||||
else
|
||||
{
|
||||
visuals.SetRust(0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 598fbcd97cc34477934893a1802ce999
|
||||
timeCreated: 1791330530
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de28a2301d654322a1a3aa450e964901
|
||||
timeCreated: 1791330380
|
||||
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CarRestorationTool : MonoBehaviour
|
||||
{
|
||||
[Header("Параметры")]
|
||||
[SerializeField] private float cleanSpeed = 0.25f; // Сколько ржавчины снимается в секунду
|
||||
[SerializeField] private float range = 2.5f;
|
||||
[SerializeField] private LayerMask interactableLayer;
|
||||
|
||||
private Camera playerCamera;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
playerCamera = Camera.main;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Зажата ЛКМ — процесс чистки
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
TryCleanPart();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryCleanPart()
|
||||
{
|
||||
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, range, interactableLayer))
|
||||
{
|
||||
CarPartVisuals visuals = hit.collider.GetComponentInParent<CarPartVisuals>();
|
||||
|
||||
if (visuals != null && visuals.CurrentRust > 0f)
|
||||
{
|
||||
float newRust = visuals.CurrentRust - (cleanSpeed * Time.deltaTime);
|
||||
visuals.SetRust(newRust);
|
||||
|
||||
// Здесь можно запустить систему частиц искр (Particles) и звук шлифмашинки
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be6ae3f5845047c6b571b3e3a10b5b44
|
||||
timeCreated: 1791330653
|
||||
Reference in new issue
Block a user