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

36 lines
1.3 KiB
C#

using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.Requirements
{
[CreateAssetMenu(menuName = "Requirements/Face Space Center")]
public class FaceSpaceCenter : PlacementRequirement
{
protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space)
{
float width = space.rrPlacement.size.x;
float length = space.rrPlacement.size.y;
candidates.RemoveAll(candidate =>
{
var bottomLeft = candidate.BottomLeft;
var center = new Vector2(bottomLeft.x, bottomLeft.z) +
new Vector2(candidate.size.x / 2f, candidate.size.y / 2f);
var xRel = center.x / width;
var zRel = center.y / length;
return candidate.orientation !=
(zRel > xRel
? zRel > 1 - xRel
? Orientation.South
: Orientation.East
: zRel > 1 - xRel
? Orientation.West
: Orientation.North);
});
return candidates;
}
}
}