From 878a80b1d7dc52f32f6edbda4fd9ce0615152a40 Mon Sep 17 00:00:00 2001 From: Felix Boucher Date: Fri, 30 Jun 2023 17:27:26 -0400 Subject: [PATCH] =?UTF-8?q?r=C3=A9parer=20le=20drag=20and=20drop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit problème : le placeholder apparait au milieu de la map random quand on clique sur le bouton de création d'unité solution : ne pas permettre de placer l'unité quand on est à l'extérieur de la zone de jeu + ne pas la faire apparaitre. --- Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs index e8030e4..a9cb7c7 100644 --- a/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs @@ -1,6 +1,7 @@ using Codice.CM.Client.Differences; using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; public abstract class DraggablePlaceholder : MonoBehaviour @@ -25,6 +26,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour { get => _outlineRenderers; } + + private List _allRenderers = new List(); /// /// calculate level boundaries and finds main camera. @@ -35,6 +38,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour _lvlBoundsCache = LevelManager.Instance.CurrentLevel.CalculateBounds(); _lvlBoundsCache.xMax += 1; _lvlBoundsCache.yMax += 1; + + _allRenderers = GetComponentsInChildren().ToList(); UpdatePosition(); } @@ -68,7 +73,16 @@ public abstract class DraggablePlaceholder : MonoBehaviour var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition)); mousePos.z = 0; - if (!_lvlBoundsCache.Contains(mousePos)) return; + if (!_lvlBoundsCache.Contains(mousePos)) + { + _canBePlacedHere = false; + _allRenderers.ForEach(x => x.enabled = false); + } + else + { + _canBePlacedHere = true; + _allRenderers.ForEach(x => x.enabled = true); + } transform.position = mousePos; }