Добавил цвета из атлса, надо добавить иконки для них
This commit is contained in:
1 parent
2fd7b76285
commit
7f1386882d
126 files changed
+4802
-774
No files matched your search
@@ -8,19 +8,19 @@ public class FurnitureController : MonoBehaviour
|
||||
public enum EditTool { Move, Rotate }
|
||||
|
||||
[Header("Настройки")]
|
||||
public FurnitureItemSO currentItemData; // Заменили GameObject на SO
|
||||
public FurnitureItemSO currentItemData;
|
||||
public LayerMask floorLayer;
|
||||
public LayerMask wallLayer;
|
||||
public LayerMask furnitureLayer;
|
||||
|
||||
[Header("Связь с UI")]
|
||||
[SerializeField] private GameObject shopPanel;
|
||||
|
||||
[Header("Режим редактирования (UI)")]
|
||||
[SerializeField] private GameObject editPanel;
|
||||
[SerializeField] private GameObject rotate90Button;
|
||||
public FurniturePaletteUI paletteUI; // Ссылка на скрипт палитры цветов
|
||||
|
||||
[Header("Настройки взаимодействия")]
|
||||
public float rotationSpeed = 5f;
|
||||
|
||||
[Header("Настройки двойного клика")]
|
||||
public float doubleClickThreshold = 0.3f;
|
||||
|
||||
[Header("Связь с камерой")]
|
||||
@@ -34,8 +34,6 @@ public class FurnitureController : MonoBehaviour
|
||||
private bool _isInteracting = false;
|
||||
private Vector3 _lastInputPos;
|
||||
private Vector3 _dragOffset;
|
||||
[Header("Связь с UI Цветов")]
|
||||
public FurniturePaletteUI paletteUI; // Ссылка на новый скрипт
|
||||
private float _lastClickTime = 0f;
|
||||
|
||||
private void Start()
|
||||
@@ -51,15 +49,18 @@ public class FurnitureController : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 1. Если мебель уже выбрана и находится в режиме редактирования
|
||||
if (_activeFurniture != null)
|
||||
{
|
||||
HandleEditing();
|
||||
}
|
||||
// 2. Если мы выбрали предмет в магазине и готовы его поставить
|
||||
else if (currentItemData != null)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) && !shopPanel.activeSelf && !IsPointerOverUI())
|
||||
TryPlaceFurniture();
|
||||
}
|
||||
// 3. Режим ожидания: ловим двойной клик по УЖЕ стоящей мебели
|
||||
else
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) && !shopPanel.activeSelf && !IsPointerOverUI())
|
||||
@@ -133,9 +134,14 @@ public class FurnitureController : MonoBehaviour
|
||||
{
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, floorLayer))
|
||||
{
|
||||
// Вычисляем настоящий низ мебели
|
||||
Vector3 worldBottomOffset = _activeFurniture.transform.TransformVector(_activeFurnitureScript.bottomOffset);
|
||||
|
||||
Vector3 currentPos = _activeFurniture.transform.position;
|
||||
Vector3 targetPos = hit.point + _dragOffset;
|
||||
targetPos.y = currentPos.y;
|
||||
|
||||
// Жестко привязываем дно к полу
|
||||
targetPos.y = hit.point.y - worldBottomOffset.y;
|
||||
|
||||
Vector3 moveDir = targetPos - currentPos;
|
||||
float moveDist = moveDir.magnitude;
|
||||
@@ -167,7 +173,8 @@ public class FurnitureController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
targetPos.y = currentPos.y;
|
||||
|
||||
targetPos.y = hit.point.y - worldBottomOffset.y;
|
||||
_activeFurniture.transform.position = targetPos;
|
||||
}
|
||||
}
|
||||
@@ -176,10 +183,13 @@ public class FurnitureController : MonoBehaviour
|
||||
{
|
||||
float deltaX = Input.mousePosition.x - _lastInputPos.x;
|
||||
|
||||
// Вращаем вокруг геометрического центра коллайдеров
|
||||
Vector3 worldCenter = _activeFurniture.transform.TransformPoint(_activeFurnitureScript.centerOffset);
|
||||
|
||||
if (_activeFurnitureScript.isWallObject)
|
||||
_activeFurniture.transform.Rotate(Vector3.forward, -deltaX * rotationSpeed * 0.2f, Space.Self);
|
||||
_activeFurniture.transform.RotateAround(worldCenter, _activeFurniture.transform.forward, -deltaX * rotationSpeed * 0.2f);
|
||||
else
|
||||
_activeFurniture.transform.Rotate(Vector3.up, -deltaX * rotationSpeed * 0.2f, Space.World);
|
||||
_activeFurniture.transform.RotateAround(worldCenter, Vector3.up, -deltaX * rotationSpeed * 0.2f);
|
||||
}
|
||||
|
||||
_lastInputPos = Input.mousePosition;
|
||||
@@ -204,7 +214,7 @@ public class FurnitureController : MonoBehaviour
|
||||
_currentTool = EditTool.Move;
|
||||
if (rotate90Button != null) rotate90Button.SetActive(false);
|
||||
|
||||
// Показываем панель цветов при выборе предмета
|
||||
// Показываем палитру цветов
|
||||
if (paletteUI != null) paletteUI.ShowColors(_activeFurnitureScript);
|
||||
|
||||
_isInteracting = false;
|
||||
@@ -256,19 +266,19 @@ public class FurnitureController : MonoBehaviour
|
||||
{
|
||||
Ray ray = _cam.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
// Берем слой для первичной установки из карточки товара SO!
|
||||
// Определяем, куда пускать луч (на стену или на пол)
|
||||
LayerMask targetLayer = currentItemData.isWallObject ? wallLayer : floorLayer;
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, targetLayer))
|
||||
{
|
||||
// Блокируем новые клики, пока грузится ассет
|
||||
_isInteracting = true;
|
||||
_isInteracting = true; // Блокируем новые клики, пока идет асинхронная загрузка
|
||||
|
||||
// Считаем стартовый поворот (для стен - "лицом" от стены)
|
||||
Quaternion spawnRot = Quaternion.identity;
|
||||
if (currentItemData.isWallObject)
|
||||
spawnRot = Quaternion.LookRotation(hit.normal);
|
||||
|
||||
// Запускаем асинхронную загрузку из Addressables
|
||||
// Асинхронно загружаем префаб через Addressables
|
||||
currentItemData.prefabRef.InstantiateAsync(hit.point, spawnRot).Completed += handle =>
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
@@ -276,33 +286,51 @@ public class FurnitureController : MonoBehaviour
|
||||
_activeFurniture = handle.Result;
|
||||
_activeFurnitureScript = _activeFurniture.GetComponent<FurnitureObject>();
|
||||
|
||||
// --- МАГИЯ АРХИТЕКТУРЫ ---
|
||||
// Инъекция карточки товара в объект на сцене!
|
||||
// ==========================================
|
||||
// 1. ИНЪЕКЦИЯ ДАННЫХ В ПРЕФАБ
|
||||
// ==========================================
|
||||
_activeFurnitureScript.runtimeItemData = currentItemData;
|
||||
|
||||
// ==========================================
|
||||
// 2. ПРИМЕНЕНИЕ ЦВЕТОВ (НОВАЯ АРХИТЕКТУРА)
|
||||
// ==========================================
|
||||
FurnitureVisuals visuals = _activeFurniture.GetComponent<FurnitureVisuals>();
|
||||
if (visuals != null && currentItemData.availablePresets != null && currentItemData.availablePresets.Count > 0)
|
||||
if (visuals != null)
|
||||
{
|
||||
visuals.ApplyPreset(currentItemData.availablePresets[0]);
|
||||
// Автоматически красим все детали первыми доступными цветами из списков
|
||||
visuals.ApplyDefaultColors(currentItemData);
|
||||
}
|
||||
|
||||
// Показываем панель цветов для только что заспавненного объекта
|
||||
// Открываем обновленную палитру с вкладками
|
||||
if (paletteUI != null) paletteUI.ShowColors(_activeFurnitureScript);
|
||||
// -------------------------
|
||||
|
||||
// ==========================================
|
||||
// 3. УМНЫЙ ПИВОТ (АВТО-ВЫРАВНИВАНИЕ)
|
||||
// ==========================================
|
||||
if (!currentItemData.isWallObject)
|
||||
{
|
||||
// Вычисляем, где находится математическое дно у модели с учетом ее поворота
|
||||
Vector3 worldBottomOffset = _activeFurniture.transform.TransformVector(_activeFurnitureScript.bottomOffset);
|
||||
|
||||
// Смещаем объект так, чтобы его дно оказалось ровно в точке клика на полу
|
||||
_activeFurniture.transform.position = hit.point - worldBottomOffset;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 4. ПЕРЕХОД В РЕЖИМ РЕДАКТИРОВАНИЯ
|
||||
// ==========================================
|
||||
_activeFurnitureScript.SetEditMode(true);
|
||||
|
||||
_currentTool = EditTool.Move;
|
||||
if (rotate90Button != null) rotate90Button.SetActive(false);
|
||||
|
||||
currentItemData = null; // Сбрасываем карточку из буфера
|
||||
currentItemData = null; // Очищаем карточку из "буфера" контроллера
|
||||
_isInteracting = false;
|
||||
LockCamera(false);
|
||||
UpdateUIPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Не удалось загрузить {currentItemData.itemName}. Проверьте галочку Addressables на префабе!");
|
||||
Debug.LogError($"Не удалось загрузить {currentItemData.itemName}. Проверьте галочку Addressable на префабе!");
|
||||
_isInteracting = false;
|
||||
}
|
||||
};
|
||||
@@ -313,15 +341,18 @@ public class FurnitureController : MonoBehaviour
|
||||
{
|
||||
if (_activeFurniture != null)
|
||||
{
|
||||
Vector3 worldCenter = _activeFurniture.transform.TransformPoint(_activeFurnitureScript.centerOffset);
|
||||
|
||||
if (_activeFurnitureScript.isWallObject)
|
||||
{
|
||||
_activeFurniture.transform.Rotate(0, 0, 90f, Space.Self);
|
||||
_activeFurniture.transform.RotateAround(worldCenter, _activeFurniture.transform.forward, 90f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float currentY = _activeFurniture.transform.eulerAngles.y;
|
||||
float snappedY = Mathf.Round(currentY / 90f) * 90f;
|
||||
_activeFurniture.transform.rotation = Quaternion.Euler(0, snappedY + 90f, 0);
|
||||
_activeFurniture.transform.RotateAround(worldCenter, Vector3.up, 90f);
|
||||
|
||||
Vector3 euler = _activeFurniture.transform.eulerAngles;
|
||||
_activeFurniture.transform.eulerAngles = new Vector3(euler.x, Mathf.Round(euler.y / 90f) * 90f, euler.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,8 +367,10 @@ public class FurnitureController : MonoBehaviour
|
||||
_activeFurnitureScript.SetEditMode(false);
|
||||
_activeFurniture = null;
|
||||
_activeFurnitureScript = null;
|
||||
|
||||
editPanel.SetActive(false);
|
||||
if (paletteUI != null) paletteUI.HideColors();
|
||||
if (paletteUI != null) paletteUI.HideColors(); // Прячем палитру
|
||||
|
||||
LockCamera(false);
|
||||
}
|
||||
}
|
||||
@@ -346,18 +379,18 @@ public class FurnitureController : MonoBehaviour
|
||||
{
|
||||
if (_activeFurniture != null)
|
||||
{
|
||||
// ПРАВИЛЬНОЕ удаление объекта, заспавненного через Addressables
|
||||
Addressables.ReleaseInstance(_activeFurniture);
|
||||
|
||||
_activeFurniture = null;
|
||||
_activeFurnitureScript = null;
|
||||
|
||||
editPanel.SetActive(false);
|
||||
if (paletteUI != null) paletteUI.HideColors();
|
||||
if (paletteUI != null) paletteUI.HideColors(); // Прячем палитру
|
||||
|
||||
LockCamera(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Эта функция вызывается из ShopManager
|
||||
public void SelectFurnitureAndCloseShop(FurnitureItemSO itemToSelect)
|
||||
{
|
||||
currentItemData = itemToSelect;
|
||||
|
||||
Reference in new issue
Block a user