using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections.Generic; public class LevelEditor : MonoBehaviour { [Header("Placement")] private GameObject currentBlock; private bool isPlacingBlock = false; private Vector3 currentScale = new Vector3(1f, 1f, 1); private float scaleStep = 0.1f; [Header("UI")] public Transform blockGroupContainer; public GameObject buttonPrefabTemplate; private int currentPage = 0; private const int buttonsPerPage = 4; private List blockPrefabs = new(); private List currentButtons = new(); private GameObject resizingTarget = null; private bool isResizing = false; private Vector3 originalMousePos; private Vector3 originalScale; private enum ResizeAxis { None, Horizontal, Vertical } private ResizeAxis currentResizeAxis = ResizeAxis.None; void Start() { LoadPrefabs(); GenerateButtons(); } void Update() { if (IsPointerOverUI()) return; if (isPlacingBlock && currentBlock != null) HandleBlockPlacement(); else HandleBlockSelection(); HandleBlockResizing(); HandleBlockDeletion(); } #region UI void LoadPrefabs() { blockPrefabs.AddRange(Resources.LoadAll("Prefabs")); } void GenerateButtons() { ClearCurrentButtons(); if (blockGroupContainer == null || buttonPrefabTemplate == null) { Debug.LogError("UI Container ou prefab de bouton manquant."); return; } int start = currentPage * buttonsPerPage; int end = Mathf.Min(start + buttonsPerPage, blockPrefabs.Count); for (int i = start; i < end; i++) { GameObject button = Instantiate(buttonPrefabTemplate, blockGroupContainer); button.SetActive(true); SetupButtonVisual(button.transform, blockPrefabs[i], i - start); GameObject prefab = blockPrefabs[i]; button.GetComponent