Beispiel #1
0
        void CreateTileGameObject(Tile t, int x, int y)
        {
            // Create Tile's GameObject
            t.CreateTileObject(Name + "[" + x + ", " + y + "]",
                               LayerGameObject.transform,
                               Name,
                               BaseMap.DefaultSortingOrder + BaseMap.GetSortingOrder(x, y),
                               GetTileWorldPosition(x, y, t.TileSet),
                               BaseMaterials,
                               Opacity);

            if (t.TileSet.AnimatedTiles.ContainsKey(t.OriginalID))
            {
                AnimatedSprite _animatedTile = t.TileGameObject.AddComponent <AnimatedSprite>();
                // Tiled defaults to LOOP
                _animatedTile.AnimationMode = SpriteAnimationMode.LOOP;
                foreach (var tileFrame in t.TileSet.AnimatedTiles[t.OriginalID].TileFrames)
                {
                    Tile tile;
                    if (BaseMap.Tiles.TryGetValue(tileFrame.TileID, out tile))
                    {
                        _animatedTile.AddSpriteFrame(tile.TileSprite, tileFrame.Duration);
                    }
                    else
                    {
                        Debug.LogWarning("Invalid Tile ID while building tile animation: " + tileFrame.TileID);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates this Tile Object (an object that has OriginalID) if applicable
        /// </summary>
        /// <param name="tiledMap">The base Tile Map</param>
        /// <param name="layerDepth">Layer's zDepth</param>
        /// <param name="sortingLayerName">Layer's SortingLayerName</param>
        /// <param name="parent">Transform to parent this object to</param>
        /// <param name="materials">List of TileSet Materials</param>
        public void CreateTileObject(Map tiledMap, string sortingLayerName, int layerDepth, List <Material> materials, Transform parent = null)
        {
            if (GID > 0)
            {
                Tile objTile = null;
                if (tiledMap.Orientation != Orientation.Orthogonal)
                {
                    objTile = tiledMap.Tiles[GID].Clone(new Vector2(0.5f, 0.5f));
                }
                else
                {
                    objTile = tiledMap.Tiles[GID].Clone();
                }

                //string sortingLayer = GetPropertyAsString("SortingLayer");
                //int sortingOrder = GetPropertyAsInt("SortingOrder");

                objTile.CreateTileObject(Name,
                                         parent != null ? parent : ParentObjectLayer.LayerGameObject.transform,
                                         sortingLayerName,
                                         tiledMap.DefaultSortingOrder + tiledMap.GetSortingOrder(Bounds.x, Bounds.y),
                                         tiledMap.TiledPositionToWorldPoint(Bounds.x, Bounds.y, layerDepth),
                                         materials);
                this.Bounds = new Rect(Bounds.x, Bounds.y - 1, 1, 1);

                /*Debug.Log(Bounds);
                 * tiledMap.AddBoxCollider(objTile.TileGameObject, this);*/
                objTile.TileGameObject.SetActive(Visible);
            }
        }
        public void ReplaceTile(int id, int x, int y, Map map, Material material)
        {
            GameObject tileObject = Tiles[x, y].TileObject;

            //Debug.Log("Tile ID: " + id + " (index : " + index + ")");
            // get the tile
            Tile t = null;

            map.Tiles.TryGetValue(id, out t);

            // if the tile is non-null...
            if (t != null)
            {
                t = t.Clone();
            }

            Tiles[x, y] = t;

            List <Material> materials = new List <Material>();

            materials.Add(material);

            // Create Tile's GameObject
            t.CreateTileObject(Name + "[" + x + ", " + y + "]",
                               LayerGameObject.transform,
                               Name,
                               tileObject.transform.localPosition,
                               materials,
                               Opacity);

            GameObject.Destroy(tileObject);
        }
        /// <summary>
        /// Creates this Tile Object (an object that has GID) if applicable
        /// </summary>
        /// <param name="tiledMap">The base Tile Map</param>
        public void CreateTileObject(Map tiledMap, string sortingLayerName, int layerDepth, List <Material> materials)
        {
            if (GID > 0)
            {
                Tile objTile = tiledMap.Tiles[GID].Clone();
                objTile.CreateTileObject(Name,
                                         tiledMap.MapObject.transform,
                                         sortingLayerName,
                                         new Vector3(Bounds.x, -Bounds.y, layerDepth),
                                         materials);

                objTile.TileObject.SetActive(Visible);
            }
        }
Beispiel #5
0
        void CreateTileGameObject(Tile t, int x, int y)
        {
            // Create Tile's GameObject
            t.CreateTileObject(Name + "[" + x + ", " + y + "]",
                LayerGameObject.transform,
                Name,
                BaseMap.DefaultSortingOrder + BaseMap.GetSortingOrder(x, y),
                GetTileWorldPosition(x, y, t.TileSet),
                BaseMaterials,
                Opacity);

            if (t.TileSet.AnimatedTiles.ContainsKey(t.OriginalID))
            {
                AnimatedSprite _animatedTile = t.TileGameObject.AddComponent<AnimatedSprite>();
                // Tiled defaults to LOOP
                _animatedTile.AnimationMode = SpriteAnimationMode.LOOP;
                foreach (var tileFrame in t.TileSet.AnimatedTiles[t.OriginalID].TileFrames)
                {
                    Tile tile;
                    if (BaseMap.Tiles.TryGetValue(tileFrame.TileID, out tile))
                    {
                        _animatedTile.AddSpriteFrame(tile.TileSprite, tileFrame.Duration);
                    }
                    else
                    {
                        Debug.LogWarning("Invalid Tile ID while building tile animation: " + tileFrame.TileID);
                    }
                }
            }
        }
        void CreateTileGameObject(Tile t, int x, int y)
        {
            // if this tile contains the prefab porperty, then generate the prefab
            if (t.HasProperty(Map.Property_PrefabName))
            {
                MapObject m = new MapObject(t.CurrentID.ToString(), string.Empty, new Rect(x, y, 1, 1), t.Properties, t.OriginalID, null, 0, null);
                BaseMap.GeneratePrefab(m, XUniTMXConfiguration.Instance.GetTilePrefabsAnchorPoint(), LayerGameObject);
                return;
            }
            // Create Tile's GameObject
            if(LayerMaterial == null)
                t.CreateTileObject(Name + "[" + x + ", " + y + "]",
                    LayerGameObject.transform,
                    Name,
                    BaseMap.DefaultSortingOrder + BaseMap.GetSortingOrder(x, y),
                    GetTileWorldPosition(x, y, t.TileSet),
                    BaseMaterials,
                    Opacity);
            else
                t.CreateTileObject(Name + "[" + x + ", " + y + "]",
                    LayerGameObject.transform,
                    Name,
                    BaseMap.DefaultSortingOrder + BaseMap.GetSortingOrder(x, y),
                    GetTileWorldPosition(x, y, t.TileSet),
                    LayerMaterial,
                    Opacity);

            if (t.TileSet.AnimatedTiles.ContainsKey(t.OriginalID))
            {
                AnimatedSprite _animatedTile = t.TileGameObject.AddComponent<AnimatedSprite>();
                // Tiled defaults to LOOP
                _animatedTile.AnimationMode = SpriteAnimationMode.LOOP;
                foreach (var tileFrame in t.TileSet.AnimatedTiles[t.OriginalID].TileFrames)
                {
                    Tile tile;
                    if (BaseMap.Tiles.TryGetValue(tileFrame.TileID, out tile))
                    {
                        _animatedTile.AddSpriteFrame(tile.TileSprite, tileFrame.Duration);
                    }
                    else
                    {
                        Debug.LogWarning("Invalid Tile ID while building tile animation: " + tileFrame.TileID);
                    }
                }
            }

            MapExtensions.ApplyCustomProperties(t.TileGameObject, t);
        }