Compare commits

...

1 Commits

3 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -16,7 +16,7 @@ public class ObjectPlaceholder : DraggablePlaceholder
return !positionIsCollidable return !positionIsCollidable
&& _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)) ;
} }
} }

View File

@ -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;
} }
} }