logic for placing object was not good
logic was supposed to allow placing object on farms, which it didn't now it does. + changed ObjectPlaceholder's name so it follows the TilePlaceholder's convention
This commit is contained in:
parent
f65735c330
commit
dfefec3dcc
@ -12,7 +12,7 @@ public class GameObjectPlacementButton : UnitPlacementButton
|
|||||||
foreach (var comp in instance.transform.GetAllComponents<Collider2D>()) Destroy(comp);
|
foreach (var comp in instance.transform.GetAllComponents<Collider2D>()) Destroy(comp);
|
||||||
foreach (var comp in instance.transform.GetAllComponents<MonoBehaviour>()) Destroy(comp);
|
foreach (var comp in instance.transform.GetAllComponents<MonoBehaviour>()) Destroy(comp);
|
||||||
|
|
||||||
var placeholder = instance.AddComponent<ObjectDraggablePlaceholder>();
|
var placeholder = instance.AddComponent<ObjectPlaceholder>();
|
||||||
placeholder.Prefab = _prefab;
|
placeholder.Prefab = _prefab;
|
||||||
|
|
||||||
var outline = new GameObject("Outline");
|
var outline = new GameObject("Outline");
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class ObjectDraggablePlaceholder : DraggablePlaceholder
|
|
||||||
{
|
|
||||||
public GameObject Prefab { get; set; }
|
|
||||||
public override void Place()
|
|
||||||
{
|
|
||||||
Prefab.Create(transform.position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
18
Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs
Normal file
18
Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ObjectPlaceholder : DraggablePlaceholder
|
||||||
|
{
|
||||||
|
public GameObject Prefab { get; set; }
|
||||||
|
public override void Place()
|
||||||
|
{
|
||||||
|
Prefab.Create(transform.position);
|
||||||
|
}
|
||||||
|
public override bool CanBePlacedHere()
|
||||||
|
{
|
||||||
|
var objsOnPosition = LevelManager.Instance.GetAll<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
|
||||||
|
var positionContainsFarm = objsOnPosition.Exists(obj => obj.Name.ToLower().Contains("farm"));
|
||||||
|
|
||||||
|
//either no object, or object is farm
|
||||||
|
return objsOnPosition.Count == 0 || (objsOnPosition.Count == 1 && positionContainsFarm);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user