réparer le drag and drop

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.
This commit is contained in:
Felix Boucher 2023-06-30 17:27:26 -04:00
parent 93e3ab1929
commit 878a80b1d7

View File

@ -1,6 +1,7 @@
using Codice.CM.Client.Differences; using Codice.CM.Client.Differences;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
public abstract class DraggablePlaceholder : MonoBehaviour public abstract class DraggablePlaceholder : MonoBehaviour
@ -25,6 +26,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
{ {
get => _outlineRenderers; get => _outlineRenderers;
} }
private List<SpriteRenderer> _allRenderers = new List<SpriteRenderer>();
/// <summary> /// <summary>
/// calculate level boundaries and finds main camera. /// calculate level boundaries and finds main camera.
@ -35,6 +38,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
_lvlBoundsCache = LevelManager.Instance.CurrentLevel.CalculateBounds(); _lvlBoundsCache = LevelManager.Instance.CurrentLevel.CalculateBounds();
_lvlBoundsCache.xMax += 1; _lvlBoundsCache.xMax += 1;
_lvlBoundsCache.yMax += 1; _lvlBoundsCache.yMax += 1;
_allRenderers = GetComponentsInChildren<SpriteRenderer>().ToList();
UpdatePosition(); UpdatePosition();
} }
@ -68,7 +73,16 @@ public abstract class DraggablePlaceholder : MonoBehaviour
var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition)); var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition));
mousePos.z = 0; 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; transform.position = mousePos;
} }