Beispiel #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (target == null || !(target is Cubemap))
        {
            return;
        }
        Cubemap cubemap = target as Cubemap;

        string assetPath = AssetDatabase.GetAssetPath(target);

        TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(assetPath);

        importer.wrapMode       = TextureWrapMode.Clamp;
        importer.textureType    = TextureImporterType.Advanced;
        importer.mipmapEnabled  = false;
        importer.maxTextureSize = 2048;
        importer.textureFormat  = TextureImporterFormat.PVRTC_RGB4;

        AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);

        exportType = (CubeMappingType)EditorGUILayout.EnumPopup("Export Type", exportType);
        if (GUILayout.Button("Export"))
        {
            string path = EditorUtility.SaveFilePanel("Save Cubemap as PNG", "", cubemap.name + ".png", "png");
            cubemap.SaveToPNG(path, exportType);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        }
    }
        public static void SaveToPNG(this Cubemap cubemap, string path, CubeMappingType mapping = CubeMappingType.Faces4x3)
        {
            switch (mapping)
            {
            case CubeMappingType.Cylindrical:
                cubemap.SaveToCylindricalPNG(path);
                break;

            case CubeMappingType.Spherical:
                cubemap.SaveToSphericalPNG(path);
                break;

            case CubeMappingType.Faces4x3:
                cubemap.SaveTo4x3PNG(path);
                break;

            case CubeMappingType.Faces3x4:
                cubemap.SaveTo3x4PNG(path);
                break;

            case CubeMappingType.Faces6x1:
                cubemap.SaveTo6x1PNG(path);
                break;

            case CubeMappingType.Faces1x6:
                cubemap.SaveTo1x6PNG(path);
                break;
            }
        }
Beispiel #3
0
    static void ExportCubemap(CubeMappingType exportType)
    {
        Cubemap[] cubemaps = GetCubemaps();
        string    folder   = "";
        string    filename = null;

        if (cubemaps.Length == 0)
        {
            return;
        }
        else if (cubemaps.Length == 1)
        {
            string path = EditorUtility.SaveFilePanel("Save Cubemap as PNG", "", cubemaps[0].name + ".png", "png");
            folder   = Path.GetDirectoryName(path);
            filename = Path.GetFileName(path);
        }
        else
        {
            folder = EditorUtility.SaveFolderPanel("Save Cubemaps to Folder", "", "");
        }
        foreach (Cubemap cubemap in cubemaps)
        {
            string assetPath = AssetDatabase.GetAssetPath(cubemap);

            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(assetPath);
            importer.maxTextureSize = 2048;
            importer.isReadable     = true;
            importer.textureFormat  = TextureImporterFormat.AutomaticTruecolor;

            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);

            string path = null;
            if (string.IsNullOrEmpty(filename))
            {
                path = Path.Combine(folder, cubemap.name + ".png");
            }
            else
            {
                path = Path.Combine(folder, filename);
            }
            cubemap.SaveToPNG(path, exportType);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        }
    }