address PR change requests

ranger les scripts au bon endroit

changer des noms de variables pour les rendre plus descriptif (turns out qu'elles étaient actually pas nécessaire)
This commit is contained in:
Felix Boucher 2023-06-11 14:13:55 -04:00
parent 33fb1ffeee
commit bdaedc28df
15 changed files with 38 additions and 25 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 810b6e3dbc8ff7f4b8131a9030ae8cd6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,6 +23,10 @@ public abstract class DraggablePlaceholder : MonoBehaviour
UpdatePosition();
}
/// <summary>
/// check for mouse click being released (and tries to place object)<br/>
/// also updates placeholder's position and shows if position is valid
/// </summary>
protected virtual void Update()
{
if (!Input.GetMouseButton(0))
@ -38,13 +42,16 @@ public abstract class DraggablePlaceholder : MonoBehaviour
_isOnValidPosition = CanBePlacedHere();
ShowValidity();
}
/// <summary>
/// sets the position of the placeholder on the grid so it follows the mouse
/// </summary>
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
/// <summary>
/// helps determine if a unit can be placed on the tile sitting at unit's position (out of bound? obstacle? invalid tile?<br/>
/// 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<br/>
/// override to change this behaviour
/// </summary>
public virtual bool CanBePlacedHere()
{
return !LevelManager.Instance.Has<ILevelObject>(obj => obj.Position.IsInTile(transform.position));
return !LevelManager.Instance.Has<ILevelObject>(obj => obj.Position.IsContainedIn(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 (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
/// </summary>
/// <param name="isValidPosition"></param>
/// <returns></returns>

View File

@ -0,0 +1,10 @@
using UnityEngine;
public class ObjectDraggablePlaceholder : DraggablePlaceholder
{
public GameObject Prefab { get; set; }
public override void Place()
{
Prefab.Create(transform.position);
}
}

View File

@ -86,8 +86,14 @@ public static class Extensions
}
public enum LevelObjectType { GameObject, Tile }
public static bool IsInTile(this Vector3 vect, Vector3 tile)
/// <summary>
/// check if an object is positioned on the same postion as an other (with a size 1 buffer)
/// </summary>
/// <param name="vect"></param>
/// <param name="tilePosition"></param>
/// <returns></returns>
public static bool IsContainedIn(this Vector3 vect, Vector3 tilePosition)
{
return Vector2.Distance(vect, tile) < 0.5f;
return Vector2.Distance(vect, tilePosition) < 0.5f;
}
}

View File

@ -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<ILevelObject>(obj => transform.position.IsInTile(obj.Position) && obj.IsCollidable);
return can || !hasCollidable;
}
}