| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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<Bounds> SpatialHashGrid { get; private set; }
- public void Init(BroadphaseSettings settings, DungeonGenerator dungeonGenerator)
- {
- if (!(settings is SpatialHashBroadphaseSettings spatialHashSettings))
- return;
- SpatialHashGrid = new SpatialHashGrid<Bounds>(
- spatialHashSettings.CellSize,
- (b) => b,
- dungeonGenerator.UpDirection);
- }
- public void Insert(Bounds bounds)
- {
- SpatialHashGrid.Insert(bounds);
- }
- public void Query(Bounds bounds, ref List<Bounds> results)
- {
- SpatialHashGrid.Query(bounds, ref results);
- }
- public void Remove(Bounds bounds)
- {
- SpatialHashGrid.Remove(bounds);
- }
- public void DrawDebug(float duration = 0)
- {
- SpatialHashGrid.DrawDebug(duration);
- }
- }
- }
|