Exemplo n.º 1
0
        public void UpdateTileInstance(TilePool pool)
        {
            // Check if we need a new tile instance
            if (matchedTileInstance == null || matchedTileInstance.id != matchedTileId)
            {
                if (matchedTileInstance != null)
                {
                    pool.ReturnTileInstance(matchedTileInstance);
                }
                if (matchedTileId == -1)
                {
                    return;
                }

                matchedTileInstance = pool.GetTileInstance(matchedTileId);
            }

            // Align tile instance
            var tileTransform = matchedTileInstance.instance.transform;

            tileTransform.localPosition = position;

            var forward = (vertices[1] - vertices[0]).normalized;

            tileTransform.localRotation = Quaternion.AngleAxis(-90 * matchedRotation, normal) * Quaternion.LookRotation(forward, normal);
        }
Exemplo n.º 2
0
        public void FullRefresh()
        {
            if (tileset == null)
            {
                return;
            }

            // Make sure mesh has vertex colors
            if (Mesh.colors == null || Mesh.colors.Count != Mesh.positions.Count)
            {
                var colorsCount = Mesh.colors?.Count ?? 0;
                var newColors   = new List <Color>();
                for (int i = 0; i < Mesh.positions.Count - colorsCount; i++)
                {
                    newColors.Add(Color.clear);
                }
                mesh.colors = mesh.colors == null ? newColors : mesh.colors.Concat(newColors).ToList();
                mesh.Refresh();
            }

            RefreshLookups();
            if (tiles == null)
            {
                tiles = new List <TileInstance>();
            }
            else
            {
                WriteTileFlagsToVertexColors();
                tiles.Clear();
            }
            if (tileLookup == null)
            {
                tileLookup = new Dictionary <int, int>();
            }
            tileLookup.Clear();

            // Create tiles
            for (int i = 0; i < mesh.faceCount; i++)
            {
                if (!mesh.faces[i].IsQuad())
                {
                    continue;
                }
                tiles.Add(new TileInstance(this, mesh.faces[i], i, mesh));
                tileLookup.Add(i, tiles.Count - 1);
            }

            TilePool?.ReturnTiles();

            // Tiles can only be refreshed after all tiles have been setup and the lookup is ready
            foreach (var tile in tiles)
            {
                tile.matchedTileInstance = null;
                tile.FullRefresh();
                MatchTile(tile);
                tile.UpdateTileInstance(TilePool);
                tile.UpdateHideGroups();
            }

            TilePool?.ClearPool();
        }