Beispiel #1
0
        private void UpdatePath()
        {
            //pathFound.Clear();
            if (cachedPathfinder != null)
            {
                uiPath.RemoveAllPoints();

                if (cachedPathfinder.state == PathfindingState.Found)
                {
                    cachedPathfinder.GetResult(pathFound);

                    Vector2 rectSize = (this.transform as RectTransform).rect.size;
                    foreach (var g in pathFound)
                    {
                        UISquareTileElement ele     = this.tiles[g.x, g.y];
                        RectTransform       eleRect = ele.transform as RectTransform;
                        Vector2             elePos  = eleRect.anchoredPosition;
                        Vector2             eleSize = eleRect.rect.size;
                        Vector2             pos     = new Vector2((elePos.x - eleSize.x / 2) / rectSize.x, (elePos.y - eleSize.y / 2) / rectSize.y);
                        uiPath.AddPoint(pos);
                    }

                    uiPath.rectTransform.anchoredPosition = (tiles[0, 0].transform as RectTransform).anchoredPosition;
                    //uiPath.rectTransform.Strentch();
                }
            }
        }
Beispiel #2
0
        private void UpdateElements()
        {
            IGraphData <Tile> data  = cachedContext.GetGraphData();
            SquareTileMapData sData = data as SquareTileMapData;

            if (tiles == null || tiles.Length == 0)
            {
                tiles = new UISquareTileElement[sData.RangeX, sData.RangeY];
                for (int i = 0; i < sData.RangeX; ++i)
                {
                    for (int j = 0; j < sData.RangeY; ++j)
                    {
                        UISquareTileElement tile = Instantiate <UISquareTileElement>(template, this.tilesRoot);
                        tile.Init(i, j, cachedContext);
                        (tile.transform as RectTransform).anchoredPosition = new Vector2((i + 0.5f) * 60f, (j + 0.5f) * 60f);
                        tiles[i, j] = tile;
                        tile.UpdateView();
                    }
                }
            }
            else
            {
                foreach (var cord in dirtyElements)
                {
                    UISquareTileElement tile = this.tiles[cord.x, cord.y];
                    tile.UpdateView();
                }
                dirtyElements.Clear();
            }
        }