Files
modular-vr/Assets/Engine/Runtime/Requirements/NoOverlap.cs

32 lines
1.2 KiB
C#

using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.Requirements
{
[CreateAssetMenu(menuName = "Requirements/No Overlap")]
public class NoOverlap : PlacementRequirement
{
protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space)
{
space.AllModules.ForEach(other => // for all other module ...
other.srPlacement.ForEachPosition(otherPosition => // ... positions ...
candidates.RemoveAll(candidate => // ... remove every candidate that ...
{
var remove = false;
candidate.ForEachPosition(position => // ... anywhere inside its bounds ...
{
if (!remove)
{
remove = position.Equals(otherPosition); // ... overlaps with other modules' position
}
});
return remove;
})));
return candidates;
}
}
}