public void BuildIntGridValues()
        {
            RoundTilemapPos();
            SortingOrder.Next();

            int[] intGridValues = Layer.IntGridCsv.Select(p => (int)p).ToArray();

            for (int i = 0; i < intGridValues.Length; i++)
            {
                int intGridValue = intGridValues[i];

                //all empty intgrid values are 0
                if (intGridValue == 0)
                {
                    continue;
                }

                LayerDefinition        intGridDef      = Layer.Definition;
                IntGridValueDefinition intGridValueDef = intGridDef.IntGridValues[intGridValue - 1];

                string          intGridValueKey = LDtkKeyFormatUtil.IntGridValueFormat(intGridDef, intGridValueDef);
                LDtkIntGridTile intGridTile     = TryGetIntGridTile(intGridValueKey);

                if (intGridTile == null)
                {
                    Debug.LogError("LDtk: Issue loading a IntGridTile. This is always expected to not be null");
                    continue;
                }

                TilemapKey key = new TilemapKey(intGridTile.TilemapTag, intGridTile.TilemapLayerMask, intGridTile.PhysicsMaterial);
                Tilemap    tilemapToBuildOn = GetTilemapToBuildOn(key);

                BuildIntGridValue(tilemapToBuildOn, intGridValueDef, i, intGridTile);
            }

            foreach (KeyValuePair <TilemapKey, Tilemap> pair in _tilemaps)
            {
                TilemapKey key     = pair.Key;
                Tilemap    tilemap = pair.Value;

                tilemap.SetOpacity(Layer);
                AddLayerOffset(tilemap);

                GameObject obj = tilemap.gameObject;
                obj.tag   = key.Tag;
                obj.layer = key.LayerMask;
                if (obj.TryGetComponent(out Rigidbody2D rb))
                {
                    rb.sharedMaterial = key.PhysicsMaterial;
                }
            }
        }
        public void BuildIntGridValues()
        {
            RoundTilemapPos();

            SortingOrder.Next();

            GameObject tilemapGameObject = LayerGameObject.CreateChildGameObject(Layer.Type);

            /*if (Importer.DeparentInRuntime)
             * {
             *  tilemapGameObject.AddComponent<LDtkDetachChildren>();
             * }*/

            Tilemap = tilemapGameObject.AddComponent <Tilemap>();


            if (Importer.IntGridValueColorsVisible)
            {
                TilemapRenderer renderer = tilemapGameObject.AddComponent <TilemapRenderer>();
                renderer.sortingOrder = SortingOrder.SortingOrderValue;
            }

            TilemapCollider2D collider = tilemapGameObject.AddComponent <TilemapCollider2D>();

            int[] intGridValues = Layer.IntGridCsv.Select(p => (int)p).ToArray();

            for (int i = 0; i < intGridValues.Length; i++)
            {
                int intGridValue = intGridValues[i];

                //all empty intgrid values are 0
                if (intGridValue == 0)
                {
                    continue;
                }

                LayerDefinition        intGridDef      = Layer.Definition;
                IntGridValueDefinition intGridValueDef = intGridDef.IntGridValues[intGridValue - 1];

                string          intGridValueKey = LDtkKeyFormatUtil.IntGridValueFormat(intGridDef, intGridValueDef);
                LDtkIntGridTile intGridTile     = Importer.GetIntGridValueTile(intGridValueKey);

                if (intGridTile == null)
                {
                    intGridTile = LDtkResourcesLoader.LoadDefaultTile();
                }

                BuildIntGridValue(intGridValueDef, i, intGridTile);
            }

            Tilemap.SetOpacity(Layer);
        }
Esempio n. 3
0
        private Tilemap ConstructNewTilemap()
        {
            SortingOrder.Next();

            string     objName    = $"{GetLayerName(Layer)}_{_layerCount}";
            GameObject tilemapObj = LayerGameObject.CreateChildGameObject(objName);
            Tilemap    tilemap    = tilemapObj.AddComponent <Tilemap>();

            TilemapRenderer renderer = tilemapObj.AddComponent <TilemapRenderer>();

            renderer.sortingOrder = SortingOrder.SortingOrderValue;

            _layerCount++;

            return(tilemap);
        }
Esempio n. 4
0
        public void BuildEntityLayerInstances()
        {
            if (Importer.DeparentInRuntime)
            {
                LayerGameObject.AddComponent <LDtkDetachChildren>();
            }

            SortingOrder.Next();

            LDtkFieldParser.CacheRecentBuilder(this);

            foreach (EntityInstance entityData in Layer.EntityInstances)
            {
                GameObject entityPrefab = Importer.GetEntity(entityData.Identifier);
                BuildEntityInstance(entityData, entityPrefab);
            }
        }
Esempio n. 5
0
        public void BuildEntityLayerInstances()
        {
            if (Importer.DeparentInRuntime)
            {
                LayerGameObject.AddComponent <LDtkDetachChildren>();
            }

            SortingOrder.Next();

            LDtkParsedPoint.InformOfRecentLayerVerticalCellCount(Layer.UnityWorldPosition, (int)Layer.CHei);

            foreach (EntityInstance entityData in Layer.EntityInstances)
            {
                GameObject entityPrefab = Importer.GetEntity(entityData.Identifier);
                if (entityPrefab == null)
                {
                    continue;
                }

                BuildEntityInstance(entityData, entityPrefab);
            }
        }