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:
parent
33fb1ffeee
commit
bdaedc28df
8
Assets/Scripts/Drag&Drop.meta
Normal file
8
Assets/Scripts/Drag&Drop.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 810b6e3dbc8ff7f4b8131a9030ae8cd6
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -23,6 +23,10 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
UpdatePosition();
|
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()
|
protected virtual void Update()
|
||||||
{
|
{
|
||||||
if (!Input.GetMouseButton(0))
|
if (!Input.GetMouseButton(0))
|
||||||
@ -38,13 +42,16 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
|
|
||||||
_isOnValidPosition = CanBePlacedHere();
|
_isOnValidPosition = CanBePlacedHere();
|
||||||
ShowValidity();
|
ShowValidity();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sets the position of the placeholder on the grid so it follows the mouse
|
||||||
|
/// </summary>
|
||||||
protected virtual void UpdatePosition()
|
protected virtual void UpdatePosition()
|
||||||
{
|
{
|
||||||
var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition));
|
var mousePos = Vector3Int.RoundToInt(_mainCamCache.ScreenToWorldPoint(Input.mousePosition));
|
||||||
mousePos.z = 0;
|
mousePos.z = 0;
|
||||||
|
|
||||||
if (!_lvlBoundsCache.Contains(mousePos)) return;
|
if (!_lvlBoundsCache.Contains(mousePos)) return;
|
||||||
transform.position = mousePos;
|
transform.position = mousePos;
|
||||||
|
|
||||||
@ -52,16 +59,17 @@ public abstract class DraggablePlaceholder : MonoBehaviour
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// helps determine if a unit can be placed on the tile sitting at unit's position (out of bound? obstacle? invalid tile?<br/>
|
/// 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>
|
/// </summary>
|
||||||
public virtual bool CanBePlacedHere()
|
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>
|
/// <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 (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>
|
/// </summary>
|
||||||
/// <param name="isValidPosition"></param>
|
/// <param name="isValidPosition"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
10
Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs
Normal file
10
Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ObjectDraggablePlaceholder : DraggablePlaceholder
|
||||||
|
{
|
||||||
|
public GameObject Prefab { get; set; }
|
||||||
|
public override void Place()
|
||||||
|
{
|
||||||
|
Prefab.Create(transform.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -86,8 +86,14 @@ public static class Extensions
|
|||||||
}
|
}
|
||||||
public enum LevelObjectType { GameObject, Tile }
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user