Esempio n. 1
0
        //-----------------------------------------------------------------------------------------------------------//

        /// <summary>
        /// Adds _tileToAdd tile into the dirty queue
        /// </summary>
        /// <param name="_tileToAdd"> The tile to be added to the dirty queue</param>
        public void AddToDirtyQueue(TileGOData _tileToAdd)
        {
            if (_tileToAdd.isMaskable)
            {
                WorldLoader.m_Terrain.dirtyTiles.Enqueue(_tileToAdd);
            }
        }
Esempio n. 2
0
        //-----------------------------------------------------------------------------------------------------------//

        /// <summary>
        /// Recalculates the dirty tiles corners for the shader
        /// </summary>
        private void RedrawDirtyTiles()
        {
            while (dirtyTiles.Count != 0)
            {
                TileGOData _tileToRedraw = dirtyTiles.Dequeue();

                // Create the bitMask with the neighbours
                byte bitmaskValue = 0;

                if (_tileToRedraw.UpLeft() != null && _tileToRedraw.UpLeft().type != _tileToRedraw.type)
                {
                    bitmaskValue += 1;
                }

                if (_tileToRedraw.Up() != null && _tileToRedraw.Up().type != _tileToRedraw.type)
                {
                    bitmaskValue += 2;
                }

                if (_tileToRedraw.UpRight() != null && _tileToRedraw.UpRight().type != _tileToRedraw.type)
                {
                    bitmaskValue += 4;
                }

                if (_tileToRedraw.Left() != null && _tileToRedraw.Left().type != _tileToRedraw.type)
                {
                    bitmaskValue += 8;
                }

                if (_tileToRedraw.Right() != null && _tileToRedraw.Right().type != _tileToRedraw.type)
                {
                    bitmaskValue += 16;
                }

                if (_tileToRedraw.DownLeft() != null && _tileToRedraw.DownLeft().type != _tileToRedraw.type)
                {
                    bitmaskValue += 32;
                }

                if (_tileToRedraw.Down() != null && _tileToRedraw.Down().type != _tileToRedraw.type)
                {
                    bitmaskValue += 64;
                }

                if (_tileToRedraw.DownRight() != null && _tileToRedraw.DownRight().type != _tileToRedraw.type)
                {
                    bitmaskValue += 128;
                }

                // Cache the material
                Material _tileMaterial = _tileToRedraw.GetComponentInChildren <SpriteRenderer>().material;

                // Get the mask index
                byte _value = GetMaskIntTL(bitmaskValue & Bits.TOP_LEFT);

                // Set the value in the shader
                _tileMaterial.SetFloat("_TopLeftMaskTile", _value);

                _value = GetMaskIntTR(bitmaskValue & Bits.TOP_RIGHT);

                _tileMaterial.SetFloat("_TopRightMaskTile", _value);

                _value = GetMaskIntBL(bitmaskValue & Bits.BOTTOM_LEFT);

                _tileMaterial.SetFloat("_BottomLeftMaskTile", _value);

                _value = GetMaskIntBR(bitmaskValue & Bits.BOTTOL_RIGHT);

                _tileMaterial.SetFloat("_BottomRightMaskTile", _value);

                float _x = _tileToRedraw.transform.position.x;
                float _y = _tileToRedraw.transform.position.y;

                // Change the offset of the shader based on the tiles position
                _tileMaterial.SetVector("_UVOffset", GetUVOffset(_x, _y));
            }
        }