- Implémentation incompléte du code qui empêche l'utilisateur de mettre deux unités sur la même case.

This commit is contained in:
MaximilienBlanchardBizien1 2024-02-04 18:23:56 -05:00
parent 47338ecdaf
commit 734c754882
3 changed files with 14 additions and 4 deletions

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -20,6 +21,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
protected Rect _lvlBoundsCache;
protected bool _canBePlacedHere;
protected static bool alreadyHasUnit = false;
private List<SpriteRenderer> _outlineRenderers = new List<SpriteRenderer>();
public List<SpriteRenderer> OutlineRenderers
{
@ -50,14 +53,15 @@ public abstract class DraggablePlaceholder : MonoBehaviour
{
if (!Input.GetMouseButton(0))
{
if (_canBePlacedHere)
if (_canBePlacedHere && !alreadyHasUnit)
{
ResourceManager.Instance.Remove(Rock, Wood, Food);
Place();
alreadyHasUnit = true;
}
Destroy(gameObject);
}
alreadyHasUnit = AlreadyHasUnit();
_canBePlacedHere = CanBePlacedHere();
UpdatePosition();
@ -96,6 +100,11 @@ public abstract class DraggablePlaceholder : MonoBehaviour
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food);
}
public virtual bool AlreadyHasUnit()
{
return !_lvlBoundsCache.Contains(transform.position);
}
/// <summary>
/// how your character will appear depending on the validity of the tile you want to put them on<br/>
/// default behaviour is changes color of all sprite renderers of the Outline Transform to red if invalid, green otherwise

View File

@ -16,7 +16,7 @@ public class ObjectPlaceholder : DraggablePlaceholder
return !positionIsCollidable
&& _lvlBoundsCache.Contains(transform.position)
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
&& (Prefab.GetComponent<Building>()
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost));
&& (Prefab.GetComponent<Building>()
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost)) ;
}
}

View File

@ -6,5 +6,6 @@ public class TilePlaceholder : DraggablePlaceholder
public override void Place()
{
LevelManager.Instance.DynamicTilemap.SetTile(Vector3Int.RoundToInt(transform.position), Tile);
alreadyHasUnit = true;
}
}