using System; using System.Collections.Generic; using System.ComponentModel; using UnityEngine; namespace DunGen.Collision { [Serializable] [DisplayName("Spatial Hashing")] public class SpatialHashBroadphaseSettings : BroadphaseSettings { public float CellSize = 40.0f; public override ICollisionBroadphase Create() { return new SpatialHashBroadphase(); } } public class SpatialHashBroadphase : ICollisionBroadphase { public SpatialHashGrid SpatialHashGrid { get; private set; } public void Init(BroadphaseSettings settings, DungeonGenerator dungeonGenerator) { if (!(settings is SpatialHashBroadphaseSettings spatialHashSettings)) return; SpatialHashGrid = new SpatialHashGrid( spatialHashSettings.CellSize, (b) => b, dungeonGenerator.UpDirection); } public void Insert(Bounds bounds) { SpatialHashGrid.Insert(bounds); } public void Query(Bounds bounds, ref List results) { SpatialHashGrid.Query(bounds, ref results); } public void Remove(Bounds bounds) { SpatialHashGrid.Remove(bounds); } public void DrawDebug(float duration = 0) { SpatialHashGrid.DrawDebug(duration); } } }