Pull request #29: réparer le drag and drop

Merge in CGD/gather-and-defend from bug/dragAndDrop/placeholderAppearsInMiddle to main

* commit '878a80b1d7dc52f32f6edbda4fd9ce0615152a40':
  réparer le drag and drop
This commit is contained in:
Felix-gabriel Boucher-luneau 2023-07-02 13:26:17 +00:00
commit 14c15426c7

View File

@ -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
@ -26,6 +27,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
get => _outlineRenderers;
}
private List<SpriteRenderer> _allRenderers = new List<SpriteRenderer>();
/// <summary>
/// calculate level boundaries and finds main camera.
/// </summary>
@ -35,6 +38,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
_lvlBoundsCache = LevelManager.Instance.CurrentLevel.CalculateBounds();
_lvlBoundsCache.xMax += 1;
_lvlBoundsCache.yMax += 1;
_allRenderers = GetComponentsInChildren<SpriteRenderer>().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;
}