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 = Vector3.one; 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; private Transform persistentBlockContainer; void Start() { persistentBlockContainer = new GameObject("PlacedBlocks").transform; DontDestroyOnLoad(persistentBlockContainer.gameObject); LoadPrefabs(); GenerateButtons(); } void Update() { if (IsPointerOverUI()) return; if (isPlacingBlock && currentBlock != null) HandleBlockPlacement(); else HandleBlockSelection(); HandleBlockResizing(); HandleBlockDeletion(); } void OnDestroy() { ClearEditor(); } #region UI void LoadPrefabs() { var all = Resources.LoadAll("Prefabs"); blockPrefabs.Clear(); foreach (var prefab in all) { var name = prefab.name.ToLower(); if (name == "ground" || name == "winnerwall") continue; blockPrefabs.Add(prefab); } } void GenerateButtons() { ClearCurrentButtons(); if (blockGroupContainer == null || buttonPrefabTemplate == null) { Debug.LogError("UI Container ou prefab manquant."); return; } int start = currentPage * buttonsPerPage; int end = Mathf.Min(start + buttonsPerPage, blockPrefabs.Count); for (int i = start; i < end; i++) { var btn = Instantiate(buttonPrefabTemplate, blockGroupContainer); btn.SetActive(true); SetupButtonVisual(btn.transform, blockPrefabs[i], i - start); var prefab = blockPrefabs[i]; btn.GetComponent