예제 #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);
                    }
                }
            }
        }
예제 #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);
            }
        }
        /// <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 static GameObject CreateTileObject(this MapObject obj, Map tiledMap, string sortingLayerName, int layerDepth, List<Material> materials, Transform parent = null)
        {
            if (obj.GID > 0)
            {
                Tile objTile = null;
                if (tiledMap.MapRenderParameter.Orientation != Orientation.Orthogonal)
                    objTile = tiledMap.Tiles[obj.GID].Clone(new Vector2(0.5f, 0.5f));
                else
                    objTile = tiledMap.Tiles[obj.GID].Clone();

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

                objTile.TileGameObject.SetActive(obj.Visible);

                // Since Tiled 0.12, TileObjects' Bounds will have the desired width and height of the image, so scale accordingly
                if(obj.Bounds.width != 1 || obj.Bounds.height != 1)
                    objTile.TileGameObject.transform.localScale = new Vector3(obj.Bounds.width / objTile.TileSprite.bounds.size.x, obj.Bounds.height / objTile.TileSprite.bounds.size.y);

                return objTile.TileGameObject;
            }
            return null;
        }
예제 #4
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);
            }
        }