Esempio n. 1
0
 public void Init()
 {
     gridArraySize = Mathf.CeilToInt(ConVar.Server.worldsize / (float)GRID_SIZE);
     _plugin.Puts($"Created grid of {gridArraySize} by {gridArraySize}");
     itemGrid = new ItemChunk[gridArraySize, gridArraySize];
     _drawTimer?.Destroy();
     _drawTimer = _plugin.timer.Every(drawDelay, DrawChunks);
 }
Esempio n. 2
0
            public ItemChunk GetGrid(Vector3 position, bool createIfEmpty = true)
            {
                if (itemGrid == null)
                {
                    return(null);
                }
                int x = Mathf.Clamp(((int)position.x + halfSize) / GRID_SIZE, 0, gridArraySize - 1);
                int y = Mathf.Clamp(((int)position.z + halfSize) / GRID_SIZE, 0, gridArraySize - 1);
                //_plugin.Puts($"({x},{y})");
                ItemChunk grid = itemGrid[x, y];

                if (grid == null)
                {
                    if (!createIfEmpty)
                    {
                        return(null);
                    }
                    grid           = new ItemChunk(x, y);
                    itemGrid[x, y] = grid;
                }
                return(grid);
            }