diff --git a/Assets/Scripts/Drag&Drop.meta b/Assets/Scripts/Drag&Drop.meta
new file mode 100644
index 0000000..5b7916b
--- /dev/null
+++ b/Assets/Scripts/Drag&Drop.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 810b6e3dbc8ff7f4b8131a9030ae8cd6
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/DraggablePlaceholder.cs b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs
similarity index 79%
rename from Assets/Scripts/DraggablePlaceholder.cs
rename to Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs
index 5a3e184..3655553 100644
--- a/Assets/Scripts/DraggablePlaceholder.cs
+++ b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs
@@ -23,6 +23,10 @@ public abstract class DraggablePlaceholder : MonoBehaviour
UpdatePosition();
}
+ ///
+ /// check for mouse click being released (and tries to place object)
+ /// also updates placeholder's position and shows if position is valid
+ ///
protected virtual void Update()
{
if (!Input.GetMouseButton(0))
@@ -38,13 +42,16 @@ public abstract class DraggablePlaceholder : MonoBehaviour
_isOnValidPosition = CanBePlacedHere();
ShowValidity();
-
}
+ ///
+ /// sets the position of the placeholder on the grid so it follows the mouse
+ ///
protected virtual void UpdatePosition()
{
var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition));
mousePos.z = 0;
+
if (!_lvlBoundsCache.Contains(mousePos)) return;
transform.position = mousePos;
@@ -52,16 +59,17 @@ public abstract class DraggablePlaceholder : MonoBehaviour
///
/// helps determine if a unit can be placed on the tile sitting at unit's position (out of bound? obstacle? invalid tile?
- /// default behaviour is : you cant place a tile over an already existing tile
+ /// default behaviour is : you cant place anything over any already existing thing
+ /// override to change this behaviour
///
public virtual bool CanBePlacedHere()
{
- return !LevelManager.Instance.Has(obj => obj.Position.IsInTile(transform.position));
+ return !LevelManager.Instance.Has(obj => obj.Position.IsContainedIn(transform.position));
}
///
/// how your character will appear depending on the validity of the tile you want to put them on
- /// default behaviour is changes color of all sprite renderers (this one and children) 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
///
///
///
diff --git a/Assets/Scripts/DraggablePlaceholder.cs.meta b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs.meta
similarity index 100%
rename from Assets/Scripts/DraggablePlaceholder.cs.meta
rename to Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs.meta
diff --git a/Assets/Scripts/GameObjectPlacementButton.cs b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs
similarity index 100%
rename from Assets/Scripts/GameObjectPlacementButton.cs
rename to Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs
diff --git a/Assets/Scripts/GameObjectPlacementButton.cs.meta b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs.meta
similarity index 100%
rename from Assets/Scripts/GameObjectPlacementButton.cs.meta
rename to Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs.meta
diff --git a/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs b/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs
new file mode 100644
index 0000000..efa042f
--- /dev/null
+++ b/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs
@@ -0,0 +1,10 @@
+using UnityEngine;
+
+public class ObjectDraggablePlaceholder : DraggablePlaceholder
+{
+ public GameObject Prefab { get; set; }
+ public override void Place()
+ {
+ Prefab.Create(transform.position);
+ }
+}
\ No newline at end of file
diff --git a/Assets/Scripts/ObjectDraggablePlaceholder.cs.meta b/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs.meta
similarity index 100%
rename from Assets/Scripts/ObjectDraggablePlaceholder.cs.meta
rename to Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs.meta
diff --git a/Assets/TilePlaceholder.cs b/Assets/Scripts/Drag&Drop/TilePlaceholder.cs
similarity index 100%
rename from Assets/TilePlaceholder.cs
rename to Assets/Scripts/Drag&Drop/TilePlaceholder.cs
diff --git a/Assets/TilePlaceholder.cs.meta b/Assets/Scripts/Drag&Drop/TilePlaceholder.cs.meta
similarity index 100%
rename from Assets/TilePlaceholder.cs.meta
rename to Assets/Scripts/Drag&Drop/TilePlaceholder.cs.meta
diff --git a/Assets/TilePlacementButton.cs b/Assets/Scripts/Drag&Drop/TilePlacementButton.cs
similarity index 100%
rename from Assets/TilePlacementButton.cs
rename to Assets/Scripts/Drag&Drop/TilePlacementButton.cs
diff --git a/Assets/TilePlacementButton.cs.meta b/Assets/Scripts/Drag&Drop/TilePlacementButton.cs.meta
similarity index 100%
rename from Assets/TilePlacementButton.cs.meta
rename to Assets/Scripts/Drag&Drop/TilePlacementButton.cs.meta
diff --git a/Assets/Scripts/UnitPlacementButton.cs b/Assets/Scripts/Drag&Drop/UnitPlacementButton.cs
similarity index 100%
rename from Assets/Scripts/UnitPlacementButton.cs
rename to Assets/Scripts/Drag&Drop/UnitPlacementButton.cs
diff --git a/Assets/Scripts/UnitPlacementButton.cs.meta b/Assets/Scripts/Drag&Drop/UnitPlacementButton.cs.meta
similarity index 100%
rename from Assets/Scripts/UnitPlacementButton.cs.meta
rename to Assets/Scripts/Drag&Drop/UnitPlacementButton.cs.meta
diff --git a/Assets/Scripts/General/Extensions.cs b/Assets/Scripts/General/Extensions.cs
index 9156104..22d7cd2 100644
--- a/Assets/Scripts/General/Extensions.cs
+++ b/Assets/Scripts/General/Extensions.cs
@@ -86,8 +86,14 @@ public static class Extensions
}
public enum LevelObjectType { GameObject, Tile }
- public static bool IsInTile(this Vector3 vect, Vector3 tile)
+ ///
+ /// check if an object is positioned on the same postion as an other (with a size 1 buffer)
+ ///
+ ///
+ ///
+ ///
+ public static bool IsContainedIn(this Vector3 vect, Vector3 tilePosition)
{
- return Vector2.Distance(vect, tile) < 0.5f;
+ return Vector2.Distance(vect, tilePosition) < 0.5f;
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/ObjectDraggablePlaceholder.cs b/Assets/Scripts/ObjectDraggablePlaceholder.cs
deleted file mode 100644
index 0e7e9a0..0000000
--- a/Assets/Scripts/ObjectDraggablePlaceholder.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using UnityEngine;
-
-public class ObjectDraggablePlaceholder : DraggablePlaceholder
-{
- public GameObject Prefab { get; set; }
- public override void Place()
- {
- Prefab.Create(transform.position);
- }
-
- public override bool CanBePlacedHere()
- {
- var can = base.CanBePlacedHere();
-
- var hasCollidable = LevelManager.Instance.Has(obj => transform.position.IsInTile(obj.Position) && obj.IsCollidable);
-
- return can || !hasCollidable;
- }
-}
\ No newline at end of file