Пример #1
0
        /// <summary>
        /// Gets the edited version of the original texture
        /// </summary>
        /// <param name="trim">True - Trims clear pixels off the sides</param>
        /// <param name="fileName">If not null, writes a PNG file to the game data folder. Exclude '.png' in the file name</param>
        /// <returns></returns>
        public Texture2D GetTexture2D(bool trim = true, string fileName = null)
        {
            Color[] newTexColor = new Color[_texture2DColor.Width * _texture2DColor.Height];
            for (int y = 0; y < _texture2DColor.Height; y++)
            {
                for (int x = 0; x < _texture2DColor.Width; x++)
                {
                    int pos = (y * _texture2DColor.Width) + x;
                    newTexColor[pos] = _command.GetPixel(pos);
                }
            }
            int width  = _texture2DColor.Width;
            int height = _texture2DColor.Height;

            if (trim)
            {
                newTexColor = this.trim(newTexColor, out width, out height);
            }
            Texture2D newTex = new Texture2D(width, height);

            newTex.SetPixels(newTexColor);
            newTex.Apply();
            if (fileName != null)
            {
                SaveFile(fileName, newTex);
            }
            return(newTex);
        }