Пример #1
0
 private void Initialize()
 {
     _grid = new map_tile[_sizeGrid_Int.x, _sizeGrid_Int.y];
     for (int x = _sizeGrid_Int.x - 1; x > -1; x--)
     {
         for (int y = _sizeGrid_Int.y - 1; y > -1; y--)
         {
             Vector3 position = Vector3.right * (x + 0.5f) * _sizeTile + Vector3.up * (y + 0.5f) * _sizeTile + _offset - Vector3.right * _sizeGrid.x / 2f - Vector3.up * _sizeGrid.y / 2f;
             // bool isSolid = Physics2D.OverlapCircle(position, _sizeTile / 2f, game_variables.Instance.ScanLayerDefault) != null;
             bool isSolid = Physics2D.OverlapCircle(position, (_sizeTile / 2f) - _correction, game_variables.Instance.ScanLayerSolid) != null;
             int  penalty = 0;
             // // * borked 200611
             // if (!isSolid)
             // {
             //     Ray ray = new Ray(position - Vector3.forward, Vector3.forward);
             //     // Debug.DrawLine(ray.origin, ray.origin + Vector3.up);
             //     RaycastHit hit;
             //     // if (Physics.Raycast(ray, out hit, 2f))
             //     if (Physics.Raycast(ray, out hit, 2f, _mask))
             //     {
             //         // Debug.Log("doh");
             //         _surfacesDictionary.TryGetValue(hit.collider.gameObject.layer, out penalty);
             //     }
             // }
             if (!isSolid)
             {
                 Collider2D collider = Physics2D.OverlapCircle(position, (_sizeTile / 2f) - _correction, _mask);
                 if (collider != null)
                 {
                     _surfacesDictionary.TryGetValue(collider.gameObject.layer, out penalty);
                 }
                 // * testing
                 if (penalty < _penaltyBounds.x)
                 {
                     _penaltyBounds.x = penalty;
                 }
                 if (penalty > _penaltyBounds.y)
                 {
                     _penaltyBounds.y = penalty;
                 }
             }
             _grid[x, y] = new map_tile(isSolid, position, x, y, penalty);
         }
     }
     // // * testing
     // if (_testSmoothWeights)
     //     SmoothWeights(_testSmoothWeight);
 }
Пример #2
0
    public List <map_tile> GetNeigbours(map_tile tile)
    {
        List <map_tile> neighbours = new List <map_tile>();

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                if (x == 0 && y == 0)
                {
                    continue;
                }
                int X = tile.X + x;
                int Y = tile.Y + y;
                if (X > -1 && X < _sizeGrid_Int.x && Y > -1 && Y < _sizeGrid_Int.y)
                {
                    neighbours.Add(_grid[X, Y]);
                }
            }
        }
        return(neighbours);
    }