- 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:
parent
47338ecdaf
commit
734c754882
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -20,6 +21,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
protected Rect _lvlBoundsCache;
|
protected Rect _lvlBoundsCache;
|
||||||
protected bool _canBePlacedHere;
|
protected bool _canBePlacedHere;
|
||||||
|
|
||||||
|
protected static bool alreadyHasUnit = false;
|
||||||
|
|
||||||
private List<SpriteRenderer> _outlineRenderers = new List<SpriteRenderer>();
|
private List<SpriteRenderer> _outlineRenderers = new List<SpriteRenderer>();
|
||||||
public List<SpriteRenderer> OutlineRenderers
|
public List<SpriteRenderer> OutlineRenderers
|
||||||
{
|
{
|
||||||
@ -50,14 +53,15 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (!Input.GetMouseButton(0))
|
if (!Input.GetMouseButton(0))
|
||||||
{
|
{
|
||||||
if (_canBePlacedHere)
|
if (_canBePlacedHere && !alreadyHasUnit)
|
||||||
{
|
{
|
||||||
ResourceManager.Instance.Remove(Rock, Wood, Food);
|
ResourceManager.Instance.Remove(Rock, Wood, Food);
|
||||||
Place();
|
Place();
|
||||||
|
alreadyHasUnit = true;
|
||||||
}
|
}
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
alreadyHasUnit = AlreadyHasUnit();
|
||||||
_canBePlacedHere = CanBePlacedHere();
|
_canBePlacedHere = CanBePlacedHere();
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
|
|
||||||
@ -96,6 +100,11 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food);
|
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool AlreadyHasUnit()
|
||||||
|
{
|
||||||
|
return !_lvlBoundsCache.Contains(transform.position);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// how your character will appear depending on the validity of the tile you want to put them on<br/>
|
/// 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
|
/// default behaviour is changes color of all sprite renderers of the Outline Transform to red if invalid, green otherwise
|
||||||
|
|||||||
@ -17,6 +17,6 @@ public class ObjectPlaceholder : DraggablePlaceholder
|
|||||||
&& _lvlBoundsCache.Contains(transform.position)
|
&& _lvlBoundsCache.Contains(transform.position)
|
||||||
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
|
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
|
||||||
&& (Prefab.GetComponent<Building>()
|
&& (Prefab.GetComponent<Building>()
|
||||||
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost));
|
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost)) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,5 +6,6 @@ public class TilePlaceholder : DraggablePlaceholder
|
|||||||
public override void Place()
|
public override void Place()
|
||||||
{
|
{
|
||||||
LevelManager.Instance.DynamicTilemap.SetTile(Vector3Int.RoundToInt(transform.position), Tile);
|
LevelManager.Instance.DynamicTilemap.SetTile(Vector3Int.RoundToInt(transform.position), Tile);
|
||||||
|
alreadyHasUnit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user