Ejemplo n.º 1
0
        public Vector2 FindflowValueFromPosition(Vector3 worldPosition, FlowField flowField, Seeker seeker)
        {
            seeker.currentWorldArea = null;
            seeker.currentTile      = null;

            Vector2   vec  = Vector2.zero;
            WorldArea area = worldData.tileManager.GetWorldAreaAtPosition(worldPosition);

            if (area != null)
            {
                int worldX = worldData.tileManager.locationToWorldGridX(worldPosition);
                int worldY = worldData.tileManager.locationToWorldGridY(worldPosition);

                Tile tile = area.tileGrid[worldX - area.leftOffset][worldY - area.topOffset];
                if (tile != null)
                {
                    seeker.currentWorldArea = area;
                    seeker.currentTile      = tile;

                    key.x = area.index;
                    key.y = tile.sectorIndex;

                    if (flowField.field.ContainsKey(key))
                    {
                        vec = worldData.flowFieldManager.DirToVector(flowField.field[key][tile.indexWithinSector]);
                    }
                }
            }

            return(vec);
        }
Ejemplo n.º 2
0
        public Vector2 FindFlowValueFromPosition(Vector3 worldPosition, FlowField flowField, Seeker seeker)
        {
            seeker.currentWorldArea = null;
            seeker.currentTile      = null;

            Vector2   vec  = Vector2.zero;
            WorldArea area = _worldData.TileManager.GetWorldAreaAtPosition(worldPosition);

            if (area != null)
            {
                int worldX = _worldData.TileManager.LocationToWorldGridX(worldPosition);
                int worldY = _worldData.TileManager.LocationToWorldGridY(worldPosition);

                //Debug.Log("Area Index: " + area.Index);
                //Debug.Log("WorldX: " + (worldX - area.LeftOffset));

                Tile tile = area.TileGrid[worldX - area.LeftOffset][worldY - area.TopOffset];
                if (tile != null)
                {
                    seeker.currentWorldArea = area;
                    seeker.currentTile      = tile;

                    _key.X = area.Index;
                    _key.Y = tile.SectorIndex;

                    if (flowField.Field.ContainsKey(_key))
                    {
                        vec = _worldData.FlowFieldManager.DirToVector(flowField.Field[_key][tile.IndexWithinSector]);
                    }
                }
            }

            return(vec);
        }
Ejemplo n.º 3
0
 public void Create(Tile _destination, List <int> _worldAreas, IntergrationField _intergrationField, FlowField _flowField, int _key)
 {
     worldAreas        = _worldAreas;
     destination       = _destination;
     intergrationField = _intergrationField;
     flowField         = _flowField;
     key = _key;
 }
Ejemplo n.º 4
0
        public FlowField CreateFlowField(List <int> sectors, WorldArea area)
        {
            FlowField flowField = new FlowField();

            flowField.AddFields(sectors, worldData.multiLevelSectorManager.GetSectorWidthAtLevel(area, 0) * worldData.multiLevelSectorManager.GetSectorHeightAtLevel(area, 0), area);//.amountOfTilesPerSector);

            return(flowField);
        }
Ejemplo n.º 5
0
        private void DrawFlowField(FlowField flowField)
        {
            if (_flowFieldHolder != null)
            {
                Destroy(_flowFieldHolder);
            }

            GameObject arrow = Resources.Load("Prefab/FlowArrow") as GameObject;

            if (worldData.Pathfinder.showFlowField)
            {
                _flowFieldHolder = new GameObject();
                for (int x = 0; x < worldData.WorldAreas.Count; x++)
                {
                    for (int i = 0; i < worldData.WorldAreas[x].SectorGrid[0].Length; i++)
                    {
                        if (flowField.Field.ContainsKey(new IntVector2(x, i)))
                        {
                            MultiLevelSector sector    = worldData.WorldAreas[x].SectorGrid[0][i];
                            Vector2          sectorPos = new Vector2(sector.Left, sector.Top);

                            for (int j = 0; j < sector.TilesInWidth * sector.TilesInHeight; j++)
                            {
                                int y = Mathf.FloorToInt((float)j / sector.TilesInWidth);

                                Vector2 node = sectorPos + new Vector2(j - (sector.TilesInWidth * y), y);

                                if (worldData.WorldAreas[x].TileGrid[(int)node.x][(int)node.y] != null)
                                {
                                    GameObject b = Instantiate(arrow,
                                                               worldData.TileManager.GetTileWorldPosition(
                                                                   worldData.WorldAreas[x].TileGrid[(int)node.x][(int)node.y],
                                                                   worldData.WorldAreas[x]) + new Vector3(0, 0.2f, 0), Quaternion.identity);

                                    Vector2 flow =
                                        worldData.FlowFieldManager.DirToVector(
                                            flowField.Field[new IntVector2(x, i)][j]);
                                    b.transform.LookAt(b.transform.position + new Vector3(flow.x, 0, flow.y));

                                    b.transform.parent     = _flowFieldHolder.transform;
                                    b.transform.localScale = new Vector3(worldData.Pathfinder.tileSize,
                                                                         worldData.Pathfinder.tileSize, worldData.Pathfinder.tileSize);
                                }
                            }
                        }
                    }
                }
            }
        }