Добавил цвета из атлса, надо добавить иконки для них
This commit is contained in:
1 parent
2fd7b76285
commit
7f1386882d
126 files changed
+4802
-774
No files matched your search
@@ -2,45 +2,64 @@ using UnityEngine;
|
||||
|
||||
public class FurnitureObject : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public FurnitureItemSO runtimeItemData;
|
||||
|
||||
[Header("Тип объекта")]
|
||||
public bool isWallObject = false;
|
||||
|
||||
[Header("Настройки")]
|
||||
public LayerMask obstacleLayers;
|
||||
public bool isWallObject;
|
||||
|
||||
private int _obstaclesCount = 0;
|
||||
public bool IsPlacementValid => _obstaclesCount == 0;
|
||||
[HideInInspector] public FurnitureItemSO runtimeItemData;
|
||||
|
||||
private GameObject _highlightBox;
|
||||
private Material _highlightMaterial;
|
||||
|
||||
// --- НОВЫЕ ПЕРЕМЕННЫЕ ДЛЯ УМНОГО ПИВОТА ---
|
||||
[HideInInspector] public Vector3 bottomOffset;
|
||||
[HideInInspector] public Vector3 centerOffset;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
CalculateSmartPivot();
|
||||
CreateHighlightBox();
|
||||
}
|
||||
|
||||
private void CalculateSmartPivot()
|
||||
{
|
||||
BoxCollider[] colliders = GetComponents<BoxCollider>();
|
||||
if (colliders.Length == 0) return;
|
||||
|
||||
// Вычисляем общую коробку, охватывающую все коллайдеры
|
||||
Bounds totalBounds = new Bounds(colliders[0].center, colliders[0].size);
|
||||
for (int i = 1; i < colliders.Length; i++)
|
||||
{
|
||||
totalBounds.Encapsulate(new Bounds(colliders[i].center, colliders[i].size));
|
||||
}
|
||||
|
||||
// Локальный центр (для идеального вращения)
|
||||
centerOffset = totalBounds.center;
|
||||
|
||||
// Локальный низ (пол) - отнимаем половину высоты от центра
|
||||
bottomOffset = totalBounds.center;
|
||||
bottomOffset.y -= totalBounds.extents.y;
|
||||
}
|
||||
|
||||
private void CreateHighlightBox()
|
||||
{
|
||||
// Ищем ВСЕ коллайдеры на объекте
|
||||
BoxCollider[] colliders = GetComponents<BoxCollider>();
|
||||
if (colliders.Length == 0) return;
|
||||
|
||||
// Создаем "виртуальную коробку", которая охватит первый коллайдер
|
||||
Bounds totalBounds = new Bounds(colliders[0].center, colliders[0].size);
|
||||
|
||||
// Добавляем в эту коробку все остальные коллайдеры (для формы буквы Г)
|
||||
for (int i = 1; i < colliders.Length; i++)
|
||||
{
|
||||
Bounds b = new Bounds(colliders[i].center, colliders[i].size);
|
||||
totalBounds.Encapsulate(b);
|
||||
}
|
||||
for (int i = 1; i < colliders.Length; i++) totalBounds.Encapsulate(new Bounds(colliders[i].center, colliders[i].size));
|
||||
|
||||
_highlightBox = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||||
Destroy(_highlightBox.GetComponent<Collider>());
|
||||
|
||||
_highlightBox.transform.SetParent(transform);
|
||||
|
||||
// Ставим зеленую коробку в общий центр и задаем общий размер
|
||||
_highlightBox.transform.localPosition = totalBounds.center;
|
||||
_highlightBox.transform.localRotation = Quaternion.identity;
|
||||
// Умножаем на 1.02, чтобы зеленая коробка была чуть-чуть больше мебели (для красоты)
|
||||
_highlightBox.transform.localScale = totalBounds.size * 1.02f;
|
||||
|
||||
_highlightMaterial = new Material(Shader.Find("Sprites/Default"));
|
||||
|
||||
Reference in new issue
Block a user