move puzzle implementations out of engine
This commit is contained in:
35
Assets/Engine/Runtime/Requirements/Placement/NoOverlap.cs
Normal file
35
Assets/Engine/Runtime/Requirements/Placement/NoOverlap.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements.Placement
|
||||
{
|
||||
/// <summary>
|
||||
/// This requirement prevents modules from overlapping. For two models not to overlap, both of them need this requirement.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Requirements/No Overlap")]
|
||||
public class NoOverlap : PlacementRequirement
|
||||
{
|
||||
protected override List<Utilities.Placement> FilterCandidates(List<Utilities.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user