コード例 #1
0
        public void InstantiateCells()
        {
            if (_currentCellsArray == null)
            {
                _currentCellsArray = new List <Node>();
            }
            else
            {
                _currentCellsArray.Clear();
                _nodesMap.Clear();
            }

            _currentNodeMatrix = new Node[MapDimentions.I, MapDimentions.J];

            var currentPosition = StartPoint != null ? StartPoint.position : transform.position;

            for (int i = 0; i < MapDimentions.I; i++)
            {
                for (int j = 0; j < MapDimentions.J; j++)
                {
                    var instantiated = new Node();

                    currentPosition       = new Vector3(currentPosition.x + CellSize.x, currentPosition.y, currentPosition.z);
                    instantiated.Position = currentPosition;

                    instantiated.GridPosition = new IJ(i, j);

                    var flooredKey = new IJ(Mathf.RoundToInt(currentPosition.x), Mathf.RoundToInt(currentPosition.y));

                    if (!_nodesMap.ContainsKey(flooredKey) && !_globalNodesMap.ContainsKey(flooredKey))
                    {
                        _nodesMap.Add(flooredKey, instantiated);
                        _globalNodesMap.Add(flooredKey, instantiated);
                    }
                    instantiated.Map = this;

                    _currentNodeMatrix[i, j] = instantiated;

                    _currentCellsArray.Add(instantiated);
                }

                currentPosition = new Vector3(StartPoint != null ? StartPoint.position.x : transform.position.x, currentPosition.y + CellSize.y, currentPosition.z);
            }

            DefineInwalkables();
        }
コード例 #2
0
ファイル: MapGenerator.cs プロジェクト: minorusan/amaze-d
        public void InstantiateCells()
        {
            DoneUpdatingVerticeNodes = true;
            if (_currentCellsArray == null)
            {
                _currentCellsArray = new List <Node> ();
            }
            else
            {
                _currentCellsArray.Clear();
            }

            _currentNodeMatrix = new Node[MapDimentions.I, MapDimentions.J];

            var currentPosition = StartPoint.position;

            for (int i = 0; i < MapDimentions.I; i++)
            {
                for (int j = 0; j < MapDimentions.J; j++)
                {
                    var instantiated = new Node();

                    currentPosition       = new Vector3(currentPosition.x + CellSize.x, currentPosition.y, currentPosition.z);
                    instantiated.Position = currentPosition;

                    instantiated.GridPosition = new IJ(i, j);

                    var flooredKey = new IJ(Mathf.RoundToInt(currentPosition.x), Mathf.RoundToInt(currentPosition.z));

                    nodesMap.Add(flooredKey, instantiated);
                    _currentNodeMatrix [i, j] = instantiated;
                    _currentCellsArray.Add(instantiated);
                }
                currentPosition = new Vector3(StartPoint.localPosition.x, currentPosition.y, currentPosition.z + CellSize.y);
            }
            _walkableBiomNode = new Dictionary <EBiomType, HashSet <Node> > ();
            _walkableBiomNode.Add(EBiomType.Fel, new HashSet <Node> ());
            _walkableBiomNode.Add(EBiomType.Storm, new HashSet <Node> ());
            DefineInwalkables();
        }