Снятие колес работает, покраска тоже более менее. Физика просто говно щяс
This commit is contained in:
1 parent
d4c84b10df
commit
2ce853999d
67 files changed
+155919
-1996
No files matched your search
@@ -3,10 +3,14 @@ using UnityEngine;
|
||||
public class CarConditionGenerator : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки спавна")]
|
||||
[Range(0f, 1f)] [SerializeField] private float rustProbability = 0.7f; // Шанс появления ржавчины
|
||||
[Range(0f, 1f)] [SerializeField] private float rustProbability = 0.7f;
|
||||
[SerializeField] private float minRustAmount = 0.2f;
|
||||
[SerializeField] private float maxRustAmount = 0.85f;
|
||||
[SerializeField] private Color baseCarColor = Color.gray;
|
||||
[SerializeField] private float maxRustAmount = 0.75f;
|
||||
|
||||
[Header("Цвет кузова")]
|
||||
[Tooltip("Включите, только если хотите принудительно перекрасить машину при старте")]
|
||||
[SerializeField] private bool overrideMaterialColor = false;
|
||||
[SerializeField] private Color baseCarColor = Color.blue;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -16,29 +20,46 @@ public class CarConditionGenerator : MonoBehaviour
|
||||
[ContextMenu("Сгенерировать состояние")]
|
||||
public void GenerateCondition()
|
||||
{
|
||||
// 1. Обрабатываем все съемные детали (CarPart)
|
||||
CarPart[] allParts = GetComponentsInChildren<CarPart>(true);
|
||||
|
||||
foreach (CarPart part in allParts)
|
||||
{
|
||||
CarPartVisuals visuals = part.GetComponent<CarPartVisuals>();
|
||||
if (visuals == null) visuals = part.gameObject.AddComponent<CarPartVisuals>();
|
||||
|
||||
// 1. Базовый цвет кузова
|
||||
visuals.SetPaintColor(baseCarColor);
|
||||
if (overrideMaterialColor)
|
||||
visuals.SetPaintColor(baseCarColor);
|
||||
|
||||
// 2. Пластиковые детали (бампер) не ржавеют
|
||||
if (part.Data != null && !part.Data.canRust)
|
||||
{
|
||||
visuals.SetDamage(0f);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 3. Для металла - случайное начальное повреждение
|
||||
float damage = Random.value < rustProbability
|
||||
? Random.Range(minRustAmount, maxRustAmount)
|
||||
: 0f;
|
||||
|
||||
visuals.SetDamage(damage);
|
||||
}
|
||||
|
||||
// 2. Обрабатываем основной кузов (body), на котором нет CarPart, чтобы он не оставался ржавым из материала
|
||||
int rustProp = Shader.PropertyToID("_RustAmount");
|
||||
foreach (Renderer r in GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (r.GetComponentInParent<CarPart>(true) != null) continue;
|
||||
|
||||
foreach (Material m in r.sharedMaterials)
|
||||
{
|
||||
if (m != null && m.HasProperty(rustProp))
|
||||
{
|
||||
CarPartVisuals bodyVis = r.GetComponent<CarPartVisuals>();
|
||||
if (bodyVis == null) bodyVis = r.gameObject.AddComponent<CarPartVisuals>();
|
||||
if (overrideMaterialColor) bodyVis.SetPaintColor(baseCarColor);
|
||||
bodyVis.SetDamage(Random.value < rustProbability ? Random.Range(minRustAmount, maxRustAmount) : 0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user