public int Retrieve(ref ICollideable[] shapes, ICollideable shape) { int ll = 0; Entity a = shape.GetEntity(); Entity b; for (int i = 0; i < a.Nodes.Count; i++) { _node = Nodes[a.Nodes[i]]; for (int j = 0; j < _node.Bodies.Count; j++) { _temp = _node.Bodies[j]; b = _temp.GetEntity(); if (Phys2D.MaskHasLayer(a.Type, b.Type) && !shapes.ContainsID(b.ID, ll)) { shapes[ll] = _temp; ll++; if (ll >= shapes.Length) { return(ll); } } } } return(ll); }
public SpatialHashGrid(Vector2Int _size, float cellSize) { CellSize = cellSize; gridXRes = _size.x; gridYRes = _size.y; girdX = Maths.CeilToInt(_size.x); girdY = Maths.CeilToInt(_size.y); float halfC = CellSize * 0.5f; CenterOffsetRaw = new Vector2((-(gridXRes * halfC)), (-(gridXRes * halfC))); Bounds = new Rect2D(Vector2.zero, girdX * CellSize, girdY * CellSize); _length = girdX * girdY; Nodes = new SpatialHashNode[_length]; for (int i = 0; i < _length; i++) { Nodes[i] = new SpatialHashNode(i); } }