From 7f2db297faf18d6caf8629684895c1dadfb5ed2d Mon Sep 17 00:00:00 2001 From: M VINCENT PETT <42676259+Vextriz@users.noreply.github.com> Date: Sun, 11 May 2025 22:30:06 +0200 Subject: [PATCH] Map editor design (#59) --- .../InGame/BlockSkin/RegularBlock01.png.meta | 4 +- .../PortalsSkin/CubePortalLabelled.png.meta | 3 +- .../PortalsSkin/ShipPortalLabelled.png.meta | 3 +- Assets/Scenes/LevelScene.unity | 116 +-- Assets/Scripts/LevelEditor.cs | 660 ++++++++++-------- 5 files changed, 426 insertions(+), 360 deletions(-) diff --git a/Assets/Resources/InGame/BlockSkin/RegularBlock01.png.meta b/Assets/Resources/InGame/BlockSkin/RegularBlock01.png.meta index 19318be..7918062 100644 --- a/Assets/Resources/InGame/BlockSkin/RegularBlock01.png.meta +++ b/Assets/Resources/InGame/BlockSkin/RegularBlock01.png.meta @@ -109,6 +109,7 @@ TextureImporter: ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 +>>>>>>> develop spriteSheet: serializedVersion: 2 sprites: @@ -147,8 +148,7 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: - RegularBlock01_0: 229215520534054086 + nameFileIdTable: {} mipmapLimitGroupName: pSDRemoveMatte: 0 userData: diff --git a/Assets/Resources/InGame/PortalsSkin/CubePortalLabelled.png.meta b/Assets/Resources/InGame/PortalsSkin/CubePortalLabelled.png.meta index 0f5d43c..a24ba88 100644 --- a/Assets/Resources/InGame/PortalsSkin/CubePortalLabelled.png.meta +++ b/Assets/Resources/InGame/PortalsSkin/CubePortalLabelled.png.meta @@ -147,8 +147,7 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: - CubePortalLabelled_0: -799402021850825835 + nameFileIdTable: {} mipmapLimitGroupName: pSDRemoveMatte: 0 userData: diff --git a/Assets/Resources/InGame/PortalsSkin/ShipPortalLabelled.png.meta b/Assets/Resources/InGame/PortalsSkin/ShipPortalLabelled.png.meta index c711c35..1750308 100644 --- a/Assets/Resources/InGame/PortalsSkin/ShipPortalLabelled.png.meta +++ b/Assets/Resources/InGame/PortalsSkin/ShipPortalLabelled.png.meta @@ -147,8 +147,7 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: - ShipPortalLabelled_0: -1834338360412052916 + nameFileIdTable: {} mipmapLimitGroupName: pSDRemoveMatte: 0 userData: diff --git a/Assets/Scenes/LevelScene.unity b/Assets/Scenes/LevelScene.unity index 205134d..be96632 100644 --- a/Assets/Scenes/LevelScene.unity +++ b/Assets/Scenes/LevelScene.unity @@ -222,63 +222,6 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 ---- !u!1001 &109370708 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 1771296619209216840, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_Name - value: BonusSlowSpeed - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalPosition.x - value: -5.4423084 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalPosition.y - value: -2.783749 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6543394447596783970, guid: e9dda45aef9258745a40efb48437d584, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: e9dda45aef9258745a40efb48437d584, type: 3} --- !u!1 &245275147 GameObject: m_ObjectHideFlags: 0 @@ -434,6 +377,63 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 487176671} m_CullTransparentMesh: 1 +--- !u!1001 &496264820 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 3025146551836412649, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_Name + value: BonusBoostSpeed + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalPosition.x + value: -2 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalPosition.y + value: -2.88 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalRotation.w + value: 0.99681437 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalRotation.z + value: -0.079757296 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7134261581051338486, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: -9.149 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 5d01d2d55c6c25541b0db90186e76c2b, type: 3} --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -7475,4 +7475,4 @@ SceneRoots: - {fileID: 1371294550} - {fileID: 521952202} - {fileID: 555497623} - - {fileID: 109370708} + - {fileID: 496264820} diff --git a/Assets/Scripts/LevelEditor.cs b/Assets/Scripts/LevelEditor.cs index 9f3e716..9f3653e 100644 --- a/Assets/Scripts/LevelEditor.cs +++ b/Assets/Scripts/LevelEditor.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; using System.Collections.Generic; public class LevelEditor : MonoBehaviour @@ -34,6 +35,21 @@ public class LevelEditor : MonoBehaviour GenerateButtons(); } + void Update() + { + if (IsPointerOverUI()) return; + + if (isPlacingBlock && currentBlock != null) + HandleBlockPlacement(); + else + HandleBlockSelection(); + + HandleBlockResizing(); + HandleBlockDeletion(); + } + + #region UI + void LoadPrefabs() { blockPrefabs.AddRange(Resources.LoadAll("Prefabs")); @@ -41,21 +57,9 @@ public class LevelEditor : MonoBehaviour void GenerateButtons() { - if (buttonPrefabTemplate == null) - { - Debug.LogError("LevelEditor.GenerateButtons(): buttonPrefabTemplate n’est pas assigné !"); - return; - } - if (blockGroupContainer == null) - { - Debug.LogError("LevelEditor.GenerateButtons(): blockGroupContainer n’est pas assigné !"); - return; - } ClearCurrentButtons(); - Transform container = blockGroupContainer; - - if (container == null || buttonPrefabTemplate == null) + if (blockGroupContainer == null || buttonPrefabTemplate == null) { Debug.LogError("UI Container ou prefab de bouton manquant."); return; @@ -66,34 +70,10 @@ public class LevelEditor : MonoBehaviour for (int i = start; i < end; i++) { - GameObject button = Instantiate(buttonPrefabTemplate, container); + GameObject button = Instantiate(buttonPrefabTemplate, blockGroupContainer); button.SetActive(true); - Transform canvas = button.transform.Find("Canvas"); - Transform bg = canvas?.Find("BlankSquare"); - Transform icon = canvas?.Find("PrefabIcon"); - - if (bg == null || icon == null) - { - Destroy(button); - continue; - } - - float xOffset = -375f + (i - start) * 125f; - bg.GetComponent().anchoredPosition = new Vector2(xOffset, bg.GetComponent().anchoredPosition.y); - icon.GetComponent().anchoredPosition = new Vector2(xOffset, icon.GetComponent().anchoredPosition.y); - - Image bgImage = bg.GetComponent(); - Image iconImage = icon.GetComponent(); - - bgImage.sprite = Resources.Load("InGame/ButtonSkin/BlankSquare"); - iconImage.sprite = blockPrefabs[i].GetComponent()?.sprite; - - string prefabName = blockPrefabs[i].name.ToLower(); - if (prefabName.Contains("smallspike") || prefabName.Contains("smallobstacle")) - icon.GetComponent().sizeDelta = new Vector2(50, 25); - else - icon.GetComponent().sizeDelta = new Vector2(50, 50); + SetupButtonVisual(button.transform, blockPrefabs[i], i - start); GameObject prefab = blockPrefabs[i]; button.GetComponent