Пример #1
0
        private void ExportTexture(Texture2D texture, ExportTextureFormat format, AssetImage asset, bool canCopy)
        {
            // force PNG if alpha??
            string sourcePath      = AssetDatabase.GetAssetPath(asset.Texture);
            string sourceExtension = Path.GetExtension(sourcePath);
            bool   forceConversion = room.TextureForceReExport && !JanusUtil.IgnoreReExport(sourcePath);

            string rootDir = room.RootFolder;

            if (!forceConversion && canCopy && JanusUtil.SupportsImageFormat(sourceExtension))
            {
                asset.src = asset.src + sourceExtension;
                if (room.ExportOnlyHtml)
                {
                    return;
                }
                string texPath = Path.Combine(rootDir, asset.src);
                File.Copy(sourcePath, texPath, true);
            }
            else
            {
                try
                {
                    asset.src = asset.src + JanusUtil.GetImageExtension(format);
                    if (room.ExportOnlyHtml)
                    {
                        return;
                    }
                    string texPath = Path.Combine(rootDir, asset.src);

                    using (Stream output = File.OpenWrite(texPath))
                    {
                        TempTextureData data = TextureUtil.LockTexture(texture, sourcePath);
                        TextureUtil.ExportTexture(texture, output, format, room.TextureData, false);
                        TextureUtil.UnlockTexture(data);
                    }
                }
                catch
                {
                    Debug.LogError("Failure exporting texture " + asset.id);
                }
            }
        }
Пример #2
0
        public static TempTextureData LockTexture(Texture texture, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                TempTextureData da = new TempTextureData();
                da.empty = true;
                return(da);
            }

            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
            TempTextureData data     = new TempTextureData();

#if UNITY_5_5_OR_NEWER
            TextureImporterPlatformSettings settings = importer.GetPlatformTextureSettings("Standalone");
            data.settings           = settings;
            data.textureCompression = importer.textureCompression;
#else
            data.format = importer.textureFormat;
#endif
            data.isReadable          = importer.isReadable;
            data.alphaIsTransparency = importer.alphaIsTransparency;
            data.path = path;

#if UNITY_5_5_OR_NEWER
            if (!importer.isReadable || importer.textureCompression != TextureImporterCompression.Uncompressed)
#else
            if (!importer.isReadable || importer.textureFormat != TextureImporterFormat.ARGB32)
#endif
            {
                importer.isReadable = true;
#if UNITY_5_5_OR_NEWER
                importer.textureCompression = TextureImporterCompression.Uncompressed;
#else
                importer.textureFormat = TextureImporterFormat.ARGB32;
#endif
                data.changed = true;

                AssetDatabase.Refresh();
                AssetDatabase.ImportAsset(path);
            }
            return(data);
        }
Пример #3
0
        public static void UnlockTexture(TempTextureData data)
        {
            if (data.empty)
            {
                return;
            }

            if (data.changed)
            {
                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(data.path);

                importer.isReadable = data.isReadable;
#if UNITY_5_5_OR_NEWER
                importer.textureCompression = data.textureCompression;
#else
                importer.textureFormat = data.format;
#endif

                AssetDatabase.Refresh();
                AssetDatabase.ImportAsset(data.path);
            }
        }