Esempio n. 1
0
        public static int GetBitsPerPixel(TextureImporterFormat format)
        {
            switch (format)
            {
            case TextureImporterFormat.Alpha8:     //	 Alpha-only texture format.
                return(8);

            case TextureImporterFormat.RGB24:     // A color texture format.
                return(24);

            case TextureImporterFormat.RGBA32:     //Color with an alpha channel texture format.
                return(32);

            case TextureImporterFormat.ARGB32:     //Color with an alpha channel texture format.
                return(32);

            case TextureImporterFormat.DXT1:     // Compressed color texture format.
                return(4);

            case TextureImporterFormat.DXT5:     // Compressed color with alpha channel texture format.
                return(8);

            case TextureImporterFormat.PVRTC_RGB2:     //	 PowerVR (iOS) 2 bits/pixel compressed color texture format.
                return(2);

            case TextureImporterFormat.PVRTC_RGBA2:     //	 PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture format
                return(2);

            case TextureImporterFormat.PVRTC_RGB4:     //	 PowerVR (iOS) 4 bits/pixel compressed color texture format.
                return(4);

            case TextureImporterFormat.PVRTC_RGBA4:     //	 PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture format
                return(4);

            case TextureImporterFormat.ETC_RGB4:     //	 ETC (GLES2.0) 4 bits/pixel compressed RGB texture format.
                return(4);

            case TextureImporterFormat.ETC2_RGB4:
                return(4);

            // case TextureImporterFormat.ETC2_RGBA8:
            //     return 8;
            // case TextureImporterFormat.ETC_RGB4: //	 ATC (ATITC) 4 bits/pixel compressed RGB texture format.
            //     return 4;
            case TextureImporterFormat.ETC2_RGBA8:     //	 ATC (ATITC) 8 bits/pixel compressed RGB texture format.
                return(8);

#pragma warning disable 0618
            case TextureImporterFormat.AutomaticCompressed:
                return(4);

            case TextureImporterFormat.AutomaticTruecolor:
                return(32);

            default:
                return(32);

#pragma warning restore 0618
            }
        }
Esempio n. 2
0
    private void OnGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.HelpBox("设置选中图片或选中路径下的图片属性", MessageType.Info);
        EditorGUILayout.Space();

        textureType            = (TextureImporterType)EditorGUILayout.EnumPopup("类型:", textureType);
        textureFormat          = (TextureImporterFormat)EditorGUILayout.EnumPopup("格式:", textureFormat);
        textureSize            = (MaxSize)EditorGUILayout.EnumPopup("尺寸:", textureSize);
        textureCompression     = (TextureImporterCompression)EditorGUILayout.EnumPopup("压缩:", textureCompression);
        ifAllowsAlphaSplitting = EditorGUILayout.Toggle("是否允许透明分离:", ifAllowsAlphaSplitting);
        ifMipmapEnabled        = EditorGUILayout.Toggle("是否允许Mipmap:", ifMipmapEnabled);
        packingTag             = EditorGUILayout.TextField("PackTag:", packingTag);

        EditorGUILayout.Space();

        if (GUILayout.Button("设置"))
        {
            TextureImporterPlatformSettings t = new TextureImporterPlatformSettings();

            t.allowsAlphaSplitting = ifAllowsAlphaSplitting;
            t.format = textureFormat;

            t.maxTextureSize     = (int)textureSize;
            t.textureCompression = textureCompression;

            SelectedChangeTextureFormatSettings(t, textureType);
        }
    }
 public void Sync()
 {
     if (!this.isDefault && (!this.overridden || this.m_OverriddenIsDifferent))
     {
         TextureImportPlatformSettings textureImportPlatformSettings = this.m_Inspector.m_PlatformSettings[0];
         this.m_PlatformSettings.maxTextureSize       = textureImportPlatformSettings.maxTextureSize;
         this.m_MaxTextureSizeIsDifferent             = textureImportPlatformSettings.m_MaxTextureSizeIsDifferent;
         this.m_PlatformSettings.textureCompression   = textureImportPlatformSettings.textureCompression;
         this.m_TextureCompressionIsDifferent         = textureImportPlatformSettings.m_TextureCompressionIsDifferent;
         this.m_PlatformSettings.format               = textureImportPlatformSettings.format;
         this.m_TextureFormatIsDifferent              = textureImportPlatformSettings.m_TextureFormatIsDifferent;
         this.m_PlatformSettings.compressionQuality   = textureImportPlatformSettings.compressionQuality;
         this.m_CompressionQualityIsDifferent         = textureImportPlatformSettings.m_CompressionQualityIsDifferent;
         this.m_PlatformSettings.crunchedCompression  = textureImportPlatformSettings.crunchedCompression;
         this.m_CrunchedCompressionIsDifferent        = textureImportPlatformSettings.m_CrunchedCompressionIsDifferent;
         this.m_PlatformSettings.allowsAlphaSplitting = textureImportPlatformSettings.allowsAlphaSplitting;
         this.m_AlphaSplitIsDifferent = textureImportPlatformSettings.m_AlphaSplitIsDifferent;
     }
     if ((this.overridden || this.m_OverriddenIsDifferent) && this.m_PlatformSettings.format < (TextureImporterFormat)0)
     {
         this.m_PlatformSettings.format  = TextureImporter.FormatFromTextureParameters(this.GetSettings(this.importers[0]), this.m_PlatformSettings, this.importers[0].DoesSourceTextureHaveAlpha(), this.importers[0].IsSourceTextureHDR(), this.m_Target);
         this.m_TextureFormatIsDifferent = false;
         for (int i = 1; i < this.importers.Length; i++)
         {
             TextureImporter         textureImporter       = this.importers[i];
             TextureImporterSettings settings              = this.GetSettings(textureImporter);
             TextureImporterFormat   textureImporterFormat = TextureImporter.FormatFromTextureParameters(settings, this.m_PlatformSettings, textureImporter.DoesSourceTextureHaveAlpha(), textureImporter.IsSourceTextureHDR(), this.m_Target);
             if (textureImporterFormat != this.m_PlatformSettings.format)
             {
                 this.m_TextureFormatIsDifferent = true;
             }
         }
     }
 }
Esempio n. 4
0
    void setTextureReadable(string texPath, TextureImporterFormat format, TextureImporterCompression compression, bool val, bool importNow = true)
    {
        TextureImporter textureImporter = AssetImporter.GetAtPath(texPath) as TextureImporter;

        textureImporter.isReadable = val;

        //textureImporter.textureFormat = format;
        textureImporter.textureCompression = compression;
        TextureImporterPlatformSettings texSettings = new TextureImporterPlatformSettings();

        texSettings.format               = format;
        texSettings.maxTextureSize       = 4096;
        texSettings.allowsAlphaSplitting = true;
        texSettings.compressionQuality   = 100;
#if UNITY_ANDROID
        texSettings.name = "Android";
        //textureImporter.SetPlatformTextureSettings ("Android", 4096, format, 100, true);
#elif UNITY_IPHONE || UNITY_IOS
        texSettings.name = "iPhone";
        //textureImporter.SetPlatformTextureSettings("iPhone", 4096, format, 100, true);
#else
        texSettings.name = "Standalone";
        //textureImporter.SetPlatformTextureSettings("Standalone", 4096, format, 100, true);
#endif
        textureImporter.SetPlatformTextureSettings(texSettings);
        EditorUtility.SetDirty(textureImporter);
        textureImporter.SaveAndReimport();
        if (importNow)
        {
            AssetDatabase.ImportAsset(texPath);
        }
    }
Esempio n. 5
0
 private static void ApplyCompressionMode(Texture2D lut2D, TextureImporterFormat format)
 {
     TextureImporter importer = GetTextureImporter(lut2D);
     importer.textureFormat = format;
     AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(lut2D));
     AssetDatabase.Refresh();
 }
Esempio n. 6
0
    private void OnGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.HelpBox("设置UI文件夹路径,Assets/Res/UI/ 为默认值", MessageType.Info);
        this.texturePath = EditorGUILayout.TextField("resources folder:", this.texturePath);
        EditorGUILayout.Space();

        this.platform          = (Platform)EditorGUILayout.EnumPopup("平台:", this.platform);
        textureType            = (TextureImporterType)EditorGUILayout.EnumPopup("类型:", textureType);
        textureFormat          = (TextureImporterFormat)EditorGUILayout.EnumPopup("格式:", textureFormat);
        textureSize            = (MaxSize)EditorGUILayout.EnumPopup("尺寸:", textureSize);
        textureCompression     = (TextureImporterCompression)EditorGUILayout.EnumPopup("压缩:", textureCompression);
        ifAllowsAlphaSplitting = EditorGUILayout.Toggle("是否允许透明分离:", ifAllowsAlphaSplitting);
        ifMipmapEnabled        = EditorGUILayout.Toggle("是否允许Mipmap:", ifMipmapEnabled);
        over_ride = EditorGUILayout.Toggle("是否允许Override:", this.over_ride);

        EditorGUILayout.Space();

        if (GUILayout.Button("设置"))
        {
            TextureImporterPlatformSettings t = new TextureImporterPlatformSettings();

            t.allowsAlphaSplitting = ifAllowsAlphaSplitting;
            t.overridden           = over_ride;
            t.format             = textureFormat;
            t.maxTextureSize     = (int)textureSize;
            t.textureCompression = textureCompression;

            this.ChangeTextureFormatSettings(t);
        }
    }
Esempio n. 7
0
 public TextureFormatInfo(TextureImporterFormat f, string p, TextureImporterFormat pf, bool isNormMap)
 {
     format   = f;
     platform = p;
     platformOverrideFormat = pf;
     isNormalMap            = isNormMap;
 }
Esempio n. 8
0
        public static int CalculateTextureSizeBytes(Texture tTexture, TextureImporterFormat format)
        {
            var tWidth  = tTexture.width;
            var tHeight = tTexture.height;

            if (tTexture is Texture2D)
            {
                var tTex2D       = tTexture as Texture2D;
                var bitsPerPixel = GetBitsPerPixel(format); //TODO: ljm >>> ETC/DXT/BC multiple of 4, PVRTC POT
                var mipMapCount  = tTex2D.mipmapCount;
                var mipLevel     = 1;
                var tSize        = 0.0f;
                while (mipLevel <= mipMapCount)
                {
                    tSize  += tWidth * tHeight * bitsPerPixel / 8;
                    tWidth  = tWidth / 2;
                    tHeight = tHeight / 2;
                    mipLevel++;
                }
                return((int)tSize);
            }

            if (tTexture is Cubemap)
            {
                var bitsPerPixel = GetBitsPerPixel(format);
                return((int)(tWidth * tHeight * 6 * bitsPerPixel / 8));
            }
            return(0);
        }
Esempio n. 9
0
    // ----------------------------------------------------------------------------------
    public static Texture2D CloneAtlasTexture(Texture tex)
    {
        string                   texturePath   = AssetDatabase.GetAssetPath(tex);
        TextureImporter          importer      = (TextureImporter)TextureImporter.GetAtPath(texturePath);
        bool                     bReadable     = importer.isReadable;
        int                      maxTexSize    = importer.maxTextureSize;
        TextureImporterFormat    textureFormat = importer.textureFormat;
        TextureImporterNPOTScale npotScale     = importer.npotScale;

        Texture2D srcTex = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));

        SetSourceTexture(srcTex);
        Texture2D tarTex = new Texture2D(srcTex.width, srcTex.height, TextureFormat.ARGB32, false);

        Color[] colBuf = srcTex.GetPixels(0);
        tarTex.SetPixels(colBuf, 0);
        tarTex.Apply(false);

        // Restore
        importer.isReadable     = bReadable;
        importer.maxTextureSize = maxTexSize;
        importer.textureFormat  = textureFormat;
        importer.npotScale      = npotScale;
        AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceSynchronousImport);

        return(tarTex);
    }
Esempio n. 10
0
    static void RemoveAlphaChanel()
    {
        Texture2D tex = Selection.activeObject as Texture2D;

        if (!tex)
        {
            EditorUtility.DisplayDialog("error", "请选择一张图片", "ok");
            return;
        }
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (!path.EndsWith("png") && !path.EndsWith("PNG"))
        {
            EditorUtility.DisplayDialog("error", "图片不是png或PNG:" + path, "ok");
            return;
        }
        TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;

#if UNITY_5_5_OR_NEWER
        var originFormat = importer.textureCompression;
#else
        TextureImporterFormat originFormat = importer.textureFormat;
#endif
        bool haveAlpha = importer.DoesSourceTextureHaveAlpha();
        if (!haveAlpha)
        {
            Debug.Log("已经没有alpha");
            return;
        }
        bool originIsReadAble = importer.isReadable;
        importer.isReadable = true;
#if UNITY_5_5_OR_NEWER
        importer.textureCompression = TextureImporterCompression.Uncompressed;
#else
        importer.textureFormat = TextureImporterFormat.ARGB32;
#endif
        AssetDatabase.ImportAsset(importer.assetPath);


        Color32[] pix = tex.GetPixels32();
        for (int i = 0; i < pix.Length; i++)
        {
            pix[i].a = 0;
        }

        Texture2D newTex = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, false);
        newTex.SetPixels32(pix);

        var bytes = newTex.EncodeToPNG();
        File.WriteAllBytes(path, bytes);

        AssetDatabase.Refresh();
        importer.isReadable = originIsReadAble;
#if UNITY_5_5_OR_NEWER
        importer.textureCompression = originFormat;
#else
        importer.textureFormat = originFormat;
#endif
        AssetDatabase.ImportAsset(importer.assetPath);
    }
Esempio n. 11
0
	/**
	 * 2x1の縮尺のパノラマ画像をCubemapに展開.
	 */
	private void m_ConvertPanoramaToCubemap() {
		if (m_srcTexture == null) {
			EditorUtility.DisplayDialog("Error", "Please set panorama image!", "OK");
			return;
		}

		// 一時的にテクスチャのGetPixelを有効にする.
		string assetPath = AssetDatabase.GetAssetPath(m_srcTexture);
		TextureImporter ti = TextureImporter.GetAtPath(assetPath) as TextureImporter;
		bool oldIsReadable = ti.isReadable;
		TextureImporterFormat oldImporterFormat = ti.textureFormat;
		ti.isReadable    = true;
		ti.textureFormat = TextureImporterFormat.Automatic;
		AssetDatabase.ImportAsset(assetPath);

		// cubemap画像を出力するディレクトリの作成.
		if (!Directory.Exists(PanoramaToCubemap.outputImageDirectory)) {
			Directory.CreateDirectory(PanoramaToCubemap.outputImageDirectory);
		}

		string filePath = PanoramaToCubemap.outputImageDirectory + "/" + m_srcTexture.name;
		int texSize = m_GetCubemapTextureSize();

		m_dstTextureFront  = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_FRONT,  filePath + "_front.png");
		m_dstTextureBack   = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_BACK,   filePath + "_back.png");
		m_dstTextureLeft   = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_LEFT,   filePath + "_left.png");
		m_dstTextureRight  = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_RIGHT,  filePath + "_right.png");
		m_dstTextureUp     = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_UP,     filePath + "_up.png");
		m_dstTextureDown   = m_CreateCubemapTexture(texSize, PanoramaToCubemap.FACE_DOWN,   filePath + "_down.png");

		ti.isReadable    = oldIsReadable;
		ti.textureFormat = oldImporterFormat;
		AssetDatabase.ImportAsset(assetPath);
		AssetDatabase.Refresh();
	}
Esempio n. 12
0
        public void Sync()
        {
            if ((model.platformTextureSettings.overridden || model.overriddenIsDifferent) && model.platformTextureSettings.format < 0)
            {
                var showSettingsForPreset = ShowPresetSettings();

                model.platformTextureSettings.format = TextureImporter.DefaultFormatFromTextureParameters(
                    GetImporterSettings(0),
                    model.platformTextureSettings,
                    showSettingsForPreset || DoesSourceTextureHaveAlpha(0),
                    showSettingsForPreset || IsSourceTextureHDR(0),
                    model.buildTarget
                    );
                model.textureFormatIsDifferent = false;

                for (int i = 1; i < GetTargetCount(); i++)
                {
                    TextureImporterSettings settings = GetImporterSettings(i);

                    TextureImporterFormat format = TextureImporter.DefaultFormatFromTextureParameters(settings,
                                                                                                      model.platformTextureSettings,
                                                                                                      showSettingsForPreset || DoesSourceTextureHaveAlpha(i),
                                                                                                      showSettingsForPreset || IsSourceTextureHDR(i),
                                                                                                      model.buildTarget
                                                                                                      );
                    if (format != model.platformTextureSettings.format)
                    {
                        model.textureFormatIsDifferent = true;
                    }
                }
            }
        }
Esempio n. 13
0
    /// <summary>
    /// 使用原最大纹理大小来设置平台相关纹理
    /// </summary>
    /// <param name="platform">平台</param>
    /// <param name="oriMaxSize">各平台通用大小</param>
    /// <param name="textureImporter">TextureImporter</param>
    /// 返回值:设置成功返回true


    static bool setPlatformTexture(string platform, int oriMaxSize, TextureImporter textureImporter)
    {
        int maxTextureSize = 0;//平台最大尺寸
        TextureImporterFormat textureFormat;
        int compressionQuality = 0;
        TextureImporterFormat platformtextureFormat = platform == "iPhone" ? TextureImporterFormat.PVRTC_RGB4 : TextureImporterFormat.ETC_RGB4;

        if (textureImporter.GetPlatformTextureSettings(platform, out maxTextureSize, out textureFormat, out compressionQuality))
        {
            if ((platformtextureFormat != textureFormat) || (compressionQuality != 100))
            {
                textureImporter.SetPlatformTextureSettings(platform, maxTextureSize, platformtextureFormat, 100, true);
                return(true);
            }
            else
            {
                Debug.Log(platformtextureFormat.ToString() + " " + textureFormat.ToString());
                Debug.Log(compressionQuality);
            }
        }
        else
        {
            textureImporter.SetPlatformTextureSettings(platform, oriMaxSize, platformtextureFormat, 100, true);
            return(true);
        }
        return(false);
    }
        // Token: 0x060003D3 RID: 979 RVA: 0x00033F70 File Offset: 0x00032170
        private static void Add(int formatNum, int uncompressedFormatNum, int runtimeFormatNum, float bitsPerPixel, bool hasAlphaChannel, bool mustBeSquare, bool mustBePot, bool mustBePotForMipMaps, int minimumSize, int multipleOf, int blockSize, bool canUseCompressionQuality, bool canUseCrunchCompression, bool canBeReadable, string prettyName)
        {
            TextureImporterFormat format             = (TextureImporterFormat)formatNum;
            TextureImporterFormat uncompressedFormat = (TextureImporterFormat)uncompressedFormatNum;
            TextureFormat         runtimeFormat      = (TextureFormat)runtimeFormatNum;

            TextureImporterFormatDatabase.Entry entry = new TextureImporterFormatDatabase.Entry();
            entry.Name                     = format.ToString();
            entry.LongName                 = prettyName;
            entry.BitsPerPixel             = bitsPerPixel;
            entry.HasAlphaChannel          = hasAlphaChannel;
            entry.Format                   = format;
            entry.UncompressedFormat       = uncompressedFormat;
            entry.MinimumSize              = minimumSize;
            entry.MustBeMultipleOf         = multipleOf;
            entry.BlockSize                = blockSize;
            entry.MustBePot                = mustBePot;
            entry.MustBePotForMipMaps      = mustBePotForMipMaps;
            entry.MustBeSquare             = mustBeSquare;
            entry.CanUseCompressionQuality = canUseCompressionQuality;
            entry.CanUseCrunchCompression  = canUseCrunchCompression;
            entry.CanBeReadable            = canBeReadable;
            entry.RuntimeFormat            = runtimeFormat;
            TextureImporterFormatDatabase._List[(int)format] = entry;
        }
Esempio n. 15
0
    Texture2D JoinTextures(RHOTextureTable table, RHOTextureJoin join, TextureImporterFormat format)
    {
        var t      = new Texture2D(table.roughness[0].width, table.roughness[0].height, TextureFormat.ARGB32, true);
        var pixels = t.GetPixels32();

        var r  = table.roughness[join.roughnessIndex];
        var h  = table.height[join.heightIndex];
        var ao = table.height[join.aoIndex];

        var rPixels  = r.GetPixels32();
        var hPixels  = h.GetPixels32();
        var aoPixels = ao.GetPixels32();

        var numPixels = pixels.Length;

        for (int i = 0; i < numPixels; ++i)
        {
            var p = new Color32(rPixels[i].a, aoPixels[i].a, 0, hPixels[i].a);
            pixels[i] = p;
        }

        t.SetPixels32(pixels);
        t.Apply();

        if ((format == TextureImporterFormat.DXT1) || (format == TextureImporterFormat.DXT5))
        {
            EditorUtility.CompressTexture(t, (TextureFormat)format, TextureCompressionQuality.Best);
            t.Apply();
        }

        return(t);
    }
 public void SetTextureFormatForAll(TextureImporterFormat format)
 {
     Debug.Assert(allAreOverridden, "Attempting to set texture format for all platforms even though settings are not overridden for all platforms.");
     m_PlatformSettings.format  = format;
     m_TextureFormatIsDifferent = false;
     SetChanged();
 }
Esempio n. 17
0
    void loadVersion(int version, ref BinaryReader readBinary)
    {
        switch (version)
        {
        default:
            break;

        case 4:
            _atlasTextureFormat = (TextureImporterFormat)readBinary.ReadInt32();
            break;

        case 3:
            _isFont = readBinary.ReadBoolean();
            break;

        case 2:
            _atlasPadding = readBinary.ReadInt32();
            break;

        case 1:
            _atlasName       = readBinary.ReadString();
            _atlasFilterMode = (FilterMode)readBinary.ReadInt32();
            break;
        }
    }
Esempio n. 18
0
 public TextureAssetSettings(XmlTextReader reader)
 {
     if (reader.MoveToAttribute("path"))
     {
         path = reader.Value;
     }
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "TextureAsset")
         {
             reader.ReadEndElement();
             break;
         }
         if (reader.NodeType == XmlNodeType.Element && reader.Name == "maxSize")
         {
             maxSize = int.Parse(reader.ReadInnerXml());
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "format")
         {
             format = (TextureImporterFormat)System.Enum.Parse(typeof(TextureImporterFormat), reader.ReadInnerXml());
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "mipmaps")
         {
             mipmaps = bool.Parse(reader.ReadInnerXml());
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "npotScale")
         {
             npotScale = (TextureImporterNPOTScale)System.Enum.Parse(typeof(TextureImporterNPOTScale), reader.ReadInnerXml());
         }
     }
 }
        void OnPostprocessTexture(Texture2D texture)
        {
            if (!IsDitherAsset(assetPath))
            {
                return;
            }
            var importer = (assetImporter as TextureImporter);

            Type t = ReflectionHelper.GetType(String.Format("{0}.{1}", this.GetType().Namespace, TextureDitherSetting.Instance.ditheringAlgorithmSetting.type));

            if (t == null)
            {
                Debug.LogError(this.GetType().Name + "::OnPostprocessTexture No dithering found " + TextureDitherSetting.Instance.ditheringAlgorithmSetting.type);
                return;
            }
            DitheringBase method = (DitheringBase)Activator.CreateInstance(t, GetFindColorFuncFromColorSpace(TextureDitherSetting.Instance.ditheringAlgorithmSetting.targetColorSpace));

            if (texture.format != TextureFormat.RGBA32)
            {
                Debug.LogError("DitherTextureImporter::OnPostprocessTexture wrong texture format " + texture.format);
            }
            texture.SetPixels(method.DoDithering(texture.GetPixels(), texture.width, texture.height));

            TextureFormat         textureFormat         = TextureFormat.RGBA4444;
            TextureImporterFormat textureImporterFormat = TextureImporterFormat.Automatic16bit;

            if (TextureDitherSetting.Instance.ditheringAlgorithmSetting.targetColorSpace == DitheringAlgorithmSetting.ColorSpace.TrueColor)
            {
                textureFormat         = TextureFormat.RGBA32;
                textureImporterFormat = TextureImporterFormat.AutomaticTruecolor;
            }
            EditorUtility.CompressTexture(texture, textureFormat, TextureCompressionQuality.Best);
            importer.textureFormat = textureImporterFormat;
        }
Esempio n. 20
0
        public static TextureImporterPlatformSettings Create_Setting(LsyTextureInfo info, string plat, int quality)
        {
            var oldSettings = info.GetPlatformSetting(plat);
            TextureImporterFormat format = GetFormat(info, quality);

            TextureImporterPlatformSettings s = new TextureImporterPlatformSettings();

            s.name       = plat;
            s.overridden = true;

            s.maxTextureSize     = oldSettings.maxTextureSize;
            s.resizeAlgorithm    = TextureResizeAlgorithm.Mitchell;
            s.format             = format;
            s.compressionQuality = (int)TextureCompressionQuality.Best;

            if (info.type == LsyTextureType.shadowmask)
            {
                s.compressionQuality = (int)TextureCompressionQuality.Normal;
            }

            s.androidETC2FallbackOverride = AndroidETC2FallbackOverride.UseBuildSettings;

            //s.allowsAlphaSplitting = true;
            //s.textureCompression = TextureImporterCompression.Uncompressed;
            //s.crunchedCompression = true;

            if (info.type == LsyTextureType.impostor)
            {
                info.importer.mipmapEnabled = false;
            }
            return(s);
        }
Esempio n. 21
0
        static void FormatPathRecursively(string path, List <string> ignoreList, FormatPathPair fpp, TFormatterPlatform platform, bool origin = false)
        {
            string        platformName = TextureFormat.GetPlatformName(platform);
            TextureFormat tf           = fpp.GetFormatByPlatform((int)platform);

            path = path.Replace('\\', '/');
            for (int k = 0; k < ignoreList.Count; k++)
            {
                if (ignoreList[k] == path && !origin)
                {
                    return;
                }
            }
            TextureImporterFormat tif = tf.format;
            bool      advanced        = tif > 0;
            ApplyData ad = new ApplyData(path, ignoreList, fpp);

            ad.tf           = tf;
            ad.advanced     = advanced;
            ad.platformName = platformName;
            ApplyImporter importerHandler = null;

            switch (fpp.iType)
            {
            case ImporterType.Texture:
                importerHandler = ApplyTextureImporter;
                break;

            case ImporterType.Model:
                importerHandler = ApplyModelImporter;
                break;

            case ImporterType.Audio:
                importerHandler = ApplyAudioImporter;
                break;
            }
            if (Directory.Exists(path))
            {
                ad.needToCheck = true;
                DirectoryInfo   di    = new DirectoryInfo(path);
                FileInfo[]      files = di.GetFiles();
                DirectoryInfo[] dis   = di.GetDirectories();
                foreach (FileInfo fi in files)
                {
                    int    index     = fi.FullName.IndexOf("Assets");
                    string assetPath = fi.FullName.Substring(index);
                    assetPath    = assetPath.Replace('\\', '/');
                    ad.assetPath = assetPath;
                    importerHandler(ad);
                }
                foreach (DirectoryInfo idi in dis)
                {
                    FormatPathRecursively(idi.FullName.Substring(idi.FullName.IndexOf("Assets")), ignoreList, fpp, platform);
                }
            }
            else if (File.Exists(path))
            {
                importerHandler(ad);
            }
        }
 public TextureImporterFormat GetFormatByAlphaMode(TextureImporterFormat format, TextureImporter tImporter)
 {
     if (AlphaMode == TextureAlphaMode.None ||
         tImporter.alphaSource == TextureImporterAlphaSource.None ||
         !tImporter.DoesSourceTextureHaveAlpha())
     {
         return(format);
     }
     else
     {
         if (format == TextureImporterFormat.ETC_RGB4 || format == TextureImporterFormat.ETC2_RGB4)
         {
             return(TextureImporterFormat.ETC2_RGBA8);
         }
         if (format == TextureImporterFormat.PVRTC_RGB4)
         {
             return(TextureImporterFormat.PVRTC_RGBA4);
         }
         if (format == TextureImporterFormat.RGB24)
         {
             return(TextureImporterFormat.RGBA32);
         }
         return(format);
     }
 }
Esempio n. 23
0
        /// <summary>
        /// 计算图片字节大小
        /// </summary>
        /// <param name="_tex"></param>
        /// <param name="_format"></param>
        /// <returns></returns>
        public static int CalculateTextureSizeBytes(Texture _tex, TextureImporterFormat _format)
        {
            var texWidth  = _tex.width;
            var texHeight = _tex.height;

            if (_tex is Texture2D)
            {
                var tex2D        = _tex as Texture2D;
                var bitsPerPixel = GetBitsPerPixel(_format);
                var mipmapCount  = tex2D.mipmapCount;
                var mipLevel     = 1;
                var texSize      = 0;

                while (mipLevel <= mipmapCount)
                {
                    texSize  += texWidth * texHeight * bitsPerPixel / 8;
                    texWidth  = texWidth / 2;
                    texHeight = texHeight / 2;
                    mipLevel++;
                }
                return(texSize);
            }

            if (_tex is Cubemap)
            {
                var bitsPerPixel = GetBitsPerPixel(_format);
                return(texWidth * texHeight * 6 * bitsPerPixel / 8);
            }

            return(0);
        }
Esempio n. 24
0
//		[MenuItem("Assets/SetTexToDither4444")]//not good
        private static void _SetTexToDither4444()
        {
            Texture2D tex = Selection.activeObject as Texture2D;

            if (!tex)
            {
                EditorUtility.DisplayDialog("error", "请选择一张图片", "ok");
                return;
            }
            string                path         = AssetDatabase.GetAssetPath(Selection.activeObject);
            TextureImporter       importer     = AssetImporter.GetAtPath(path) as TextureImporter;
            TextureImporterFormat originFormat = importer.textureFormat;
            bool originIsReadAble = importer.isReadable;

            importer.isReadable    = true;
            importer.textureFormat = TextureImporterFormat.ARGB32;
            AssetDatabase.ImportAsset(importer.assetPath);



            Texture2D newTex = ToDither4444(tex);

            var bytes = newTex.EncodeToPNG();

            path += "-dither.png";
            File.WriteAllBytes(path, bytes);

            AssetDatabase.Refresh();
            importer.isReadable    = originIsReadAble;
            importer.textureFormat = originFormat;
            AssetDatabase.ImportAsset(importer.assetPath);
        }
Esempio n. 25
0
        /// <summary>
        /// Sets the asset texture format.
        /// </summary>
        /// <returns><c>true</c>, if set format was set, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        /// <param name="format">Format.</param>
        public static bool AssetSetFormat(string path, TextureImporterFormat format)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
            {
                return(false);
            }

            TextureImporterPlatformSettings tips = ti.GetDefaultPlatformTextureSettings();

            tips.format     = format;
            tips.overridden = true;

            ti.SetPlatformTextureSettings(tips);

            SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);

            return(true);
        }
Esempio n. 26
0
    private bool hasCorrectImportSettings(TextureImporter _Importer)
    {
        if (isAvailable)
        {
            bool correctReadble = true;
            TextureImporterFormat correctFormat = TextureImporterFormat.ARGB32;
            if (!m_Asset.hasMasks)
            {
                correctReadble = false;
#if UNITY_EDITOR_OSX
                correctFormat = TextureImporterFormat.PVRTC_RGBA4;
#else
                correctFormat = TextureImporterFormat.ARGB32;
#endif // UNITY_EDITOR_OSX
            }

            return(_Importer.textureType == TextureImporterType.Advanced &&
                   _Importer.npotScale == TextureImporterNPOTScale.None &&
                   _Importer.mipmapEnabled == false &&
                   _Importer.isReadable == correctReadble &&
                   _Importer.maxTextureSize == 2048 &&
                   _Importer.alphaIsTransparency == true &&
                   _Importer.textureFormat == correctFormat);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 27
0
        public bool IsAutoPVRTC(TextureImporterFormat platformFormat, TextureImporterFormat platformDefaultFormat)
        {
            if ((
#if UNITY_2017_1_OR_NEWER
                    platformFormat == TextureImporterFormat.Automatic
#elif UNITY_5_5_OR_NEWER
                    platformFormat == TextureImporterFormat.Automatic ||
                    platformFormat == TextureImporterFormat.Automatic16bit ||
                    platformFormat == TextureImporterFormat.AutomaticCompressed ||
                    platformFormat == TextureImporterFormat.AutomaticCompressedHDR ||
                    platformFormat == TextureImporterFormat.AutomaticCrunched ||
                    platformFormat == TextureImporterFormat.AutomaticHDR
#else
                    platformFormat == TextureImporterFormat.Automatic16bit ||
                    platformFormat == TextureImporterFormat.AutomaticCompressed ||
                    platformFormat == TextureImporterFormat.AutomaticCrunched
#endif
                    ) && (
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGB2 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGB4 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGBA2 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGBA4
                    ))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 28
0
        public static void FindRGBA()
        {
            TextureImporterFormat[] formatConfig = new TextureImporterFormat[]
            {
                TextureImporterFormat.RGBA32,
                TextureImporterFormat.RGB24,
                TextureImporterFormat.ARGB32,
            };

            HashSet <TextureImporterFormat> filter = new HashSet <TextureImporterFormat>(formatConfig);

            foreach (string atlasFile in EditorResourcePaths.GetAllAtlasFiles())
            {
                if (atlasFile.EndsWith(LOW_ATLAS_SUFFIX))
                {
                    continue;
                }

                SpriteAtlas spriteAtlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasFile);
                for (int i = 2; i < PLATFORMS.Length; i++)
                {
                    TextureImporterPlatformSettings patformSettings = SpriteAtlasExtensions.GetPlatformSettings(spriteAtlas, PLATFORMS[i]);
                    if (patformSettings.overridden && filter.Contains(patformSettings.format))
                    {
                        DebugUtil.LogWarning("高清图集 : " + atlasFile);
                        break;
                    }
                }
            }

            DebugUtil.Log("FindRGBA Done!");
        }
Esempio n. 29
0
        /// <summary>
        /// Sets the asset texture format.
        /// </summary>
        /// <returns><c>true</c>, if set format was set, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        /// <param name="format">Format.</param>
        public static bool AssetSetFormat(string path, TextureImporterFormat format)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
            {
                return(false);
            }

#if UNITY_5_5_OR_NEWER
            TextureImporterPlatformSettings platformSettings = ti.GetDefaultPlatformTextureSettings();
            platformSettings.format = format;
            ti.SetPlatformTextureSettings(platformSettings);
#else
            TextureImporterSettings settings = new TextureImporterSettings();
            ti.ReadTextureSettings(settings);
            settings.textureFormat = format;
            ti.SetTextureSettings(settings);
#endif
            SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);

            return(true);
        }
    private static void WriteAndImportAlphaTexture(Texture2D tex, string a_path, TextureImporterFormat format)
    {
        string path = GenTextureName(a_path);

        WriteTextureToFile(tex, path);
        ImportTexture(path, format);
    }
Esempio n. 31
0
    public static int CalculateTextureSizeBytes(Texture tTexture, TextureImporterFormat format)
    {
        var tWidth  = tTexture.width;
        var tHeight = tTexture.height;

        if (tTexture is Texture2D)
        {
            var tTex2D       = tTexture as Texture2D;
            var bitsPerPixel = GetBitsPerPixel(format);
            var mipMapCount  = tTex2D.mipmapCount;
            var mipLevel     = 1;
            var tSize        = 0;
            while (mipLevel <= mipMapCount)
            {
                tSize  += tWidth * tHeight * bitsPerPixel / 8;
                tWidth  = tWidth / 2;
                tHeight = tHeight / 2;
                mipLevel++;
            }
            return(tSize);
        }

        if (tTexture is Cubemap)
        {
            var bitsPerPixel = GetBitsPerPixel(format);
            return(tWidth * tHeight * 6 * bitsPerPixel / 8);
        }
        return(0);
    }
	public static void SetFormat(this Texture2D texture,TextureImporterFormat format){
		TextureImporter tempImporter = (TextureImporter)AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture));
		if (tempImporter != null) {
			tempImporter.textureType=TextureImporterType.Advanced;
			tempImporter.textureFormat = format;
			AssetDatabase.ImportAsset (AssetDatabase.GetAssetPath(texture));
			AssetDatabase.Refresh();
		}
	}
Esempio n. 33
0
    public TextureImporterFormat FormatSetup()
    {
        TextureImporterFormat t = new TextureImporterFormat();

        if(TextureImporterSetting.formIndex == 0) t = TextureImporterFormat.ARGB32;
        if(TextureImporterSetting.formIndex == 1) t = TextureImporterFormat.RGB24;

        return t;
    }
Esempio n. 34
0
    void OnPreprocessTexture()
    {
        TextureImporter importer = assetImporter as TextureImporter;

        formatBackup = importer.textureFormat;

        if(importer.userData != Tag){
            return;
        }
        importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
    }
 TextureImporterSettings ChangeTextureSettings(Texture2D image, bool readable, TextureImporterFormat textureFormat)
 {
     var imagePath = AssetDatabase.GetAssetPath(image);
     var imageImporter = (TextureImporter)TextureImporter.GetAtPath(imagePath);
     var prevsetting = new TextureImporterSettings();
     imageImporter.ReadTextureSettings(prevsetting);
     imageImporter.isReadable = readable;
     imageImporter.textureFormat = textureFormat;
     AssetDatabase.WriteImportSettingsIfDirty(imagePath);
     AssetDatabase.ImportAsset(imagePath, ImportAssetOptions.ForceSynchronousImport);
     AssetDatabase.Refresh();
     return prevsetting;
 }
Esempio n. 36
0
    public static void ChangeTextureFormatAll(TextureImporterFormat newFormat)
    {
        Object[] textures = GetAllTextures();

        foreach (var texture in textures)
        {
            string path = AssetDatabase.GetAssetPath(texture);

            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;

            if (textureImporter.textureFormat != newFormat)
            {
                textureImporter.textureFormat = newFormat;
                AssetDatabase.ImportAsset(path);
                Debug.Log("ChangeTextureFormat: " + path);
            }
        }
        AssetDatabase.Refresh();
    }
Esempio n. 37
0
        /// <summary>
        /// Sets the asset texture format.
        /// </summary>
        /// <returns><c>true</c>, if set format was set, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        /// <param name="format">Format.</param>
        public static bool AssetSetFormat(string path, TextureImporterFormat format)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
                return false;

            TextureImporterSettings settings = new TextureImporterSettings();
            ti.ReadTextureSettings(settings);

            settings.textureFormat = format;
            ti.SetTextureSettings(settings);
            SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);

            return true;
        }
 public TextureAssetSettings(XmlTextReader reader)
 {
     if(reader.MoveToAttribute("path"))
         path = reader.Value;
     while(reader.Read()) {
         if(reader.NodeType == XmlNodeType.EndElement && reader.Name == "TextureAsset") {
             reader.ReadEndElement();
             break;
         }
         if(reader.NodeType == XmlNodeType.Element && reader.Name == "maxSize") {
             maxSize = int.Parse(reader.ReadInnerXml());
         } else if(reader.NodeType == XmlNodeType.Element && reader.Name == "format") {
             format = (TextureImporterFormat) System.Enum.Parse(typeof(TextureImporterFormat), reader.ReadInnerXml());
         } else if(reader.NodeType == XmlNodeType.Element && reader.Name == "mipmaps") {
             mipmaps = bool.Parse(reader.ReadInnerXml());
         } else if(reader.NodeType == XmlNodeType.Element && reader.Name == "npotScale") {
             npotScale = (TextureImporterNPOTScale) System.Enum.Parse(typeof(TextureImporterNPOTScale), reader.ReadInnerXml());
         }
     }
 }
    void OnGUI()
    {
        textureFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup( "Texture Format", textureFormat );
        filterMode = (FilterMode)EditorGUILayout.EnumPopup( "Filter Mode", filterMode );
        maxTextureSize = EditorGUILayout.IntField( "Max Texture Size", maxTextureSize );
        textureType = (TextureImporterType)EditorGUILayout.EnumPopup( "Texture Type", textureType );

        GUILayout.Space( 25 );

        if( GUILayout.Button( "Reset to Defaults" ) )
        {
            EditorPrefs.DeleteKey( _filterModeKey );
            EditorPrefs.DeleteKey( _textureFormatKey );
            EditorPrefs.DeleteKey( _textureTypeKey );
            EditorPrefs.DeleteKey( _maxTextureSizeKey );

            textureFormat = getTextureImportFormat();
            filterMode = getFilterMode();
            maxTextureSize = getMaxTextureSize();
            textureType = getTextureImportType();
        }

        GUILayout.Space( 15 );

        if( GUILayout.Button( "Save" ) )
        {
            if( !Mathf.IsPowerOfTwo( maxTextureSize ) )
            {
                EditorUtility.DisplayDialog( "SpriteKit Max Texture Size Error", "Max texture size should be a power of 2", "OK" );
                return;
            }

            EditorPrefs.SetInt( _textureFormatKey, (int)textureFormat );
            EditorPrefs.SetInt( _filterModeKey, (int)filterMode );
            EditorPrefs.SetInt( _maxTextureSizeKey, maxTextureSize );
            EditorPrefs.SetInt( _textureTypeKey, (int)textureType );
            Close();
        }
    }
Esempio n. 40
0
	// Property -------------------------------------------------------------------------
	// Control Function -----------------------------------------------------------------
	void ReimportTextures(string assetPath, bool bRecursively, TextureWrapMode wrapMode, FilterMode filterMode, int anisoLevel, int maxTextureSize, TextureImporterFormat textureFormat)
	{
		int nOutFindFile;

		NgAsset.ObjectNode[]	objNodes = NgAsset.GetTexturePathList("Assets/" + assetPath, bRecursively, 0, out nOutFindFile);
		for (int n = 0; n < objNodes.Length; n++)
		{
			ReimportTexture(objNodes[n].m_AssetPath, wrapMode, filterMode, anisoLevel, maxTextureSize, textureFormat);
		}
	}
 public static bool IsCompressedDXTTextureFormat(TextureImporterFormat format)
 {
     return ((format == TextureImporterFormat.DXT1) || (format == TextureImporterFormat.DXT5));
 }
			public TextureFormatInfo(TextureImporterFormat f, string p, TextureImporterFormat pf, bool isNormMap){
				format = f;
				platform = p;
				platformOverrideFormat = pf;
				isNormalMap = isNormMap;
			}
	void ConvertTextureToFormat(Texture2D texture, TextureImporterFormat format)
	{
		string assetPath = AssetDatabase.GetAssetPath(texture);
		if (assetPath != "")
		{
			// make sure the source texture is npot and readable, and uncompressed
        	TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(assetPath);
			if (importer.textureFormat != format)
				importer.textureFormat = format;
			
			AssetDatabase.ImportAsset(assetPath);
		}
	}
Esempio n. 44
0
 public void SetPlatformTextureSettings(string platform, int maxTextureSize, TextureImporterFormat textureFormat)
 {
     bool allowsAlphaSplit = false;
     this.SetPlatformTextureSettings(platform, maxTextureSize, textureFormat, allowsAlphaSplit);
 }
Esempio n. 45
0
 public extern void SetPlatformTextureSettings(string platform, int maxTextureSize, TextureImporterFormat textureFormat, int compressionQuality, bool allowsAlphaSplit);
Esempio n. 46
0
	void ReimportTexture(string assetPath, TextureWrapMode wrapMode, FilterMode filterMode, int anisoLevel, int maxTextureSize, TextureImporterFormat textureFormat)
	{
// 		Debug.Log("ChangeImportTextureToGUI - " + assetPath);
		TextureImporter	texImporter = TextureImporter.GetAtPath(assetPath) as TextureImporter;

		TextureImporterSettings settings = new TextureImporterSettings();
		texImporter.ReadTextureSettings(settings);
// 		settings.ApplyTextureType(TextureImporterType.GUI, false);
// 		texImporter.SetTextureSettings(settings);

		if (m_bSetGUI)
		{
			if (m_bGUI)
		 		 texImporter.textureType	= TextureImporterType.GUI;
			else texImporter.textureType	= TextureImporterType.Image;
		}

		if (m_bSetWrapMode)
			texImporter.wrapMode			= wrapMode;

		if (m_bSetGUI)
		{
			if (!m_bGUI)
			{
				if (m_bSetFilterMode)
					texImporter.filterMode	= filterMode;
				if (m_bSetAnisoLevel)
					texImporter.anisoLevel	= anisoLevel;
			}
		} else {
				if (m_bSetFilterMode)
					texImporter.filterMode	= filterMode;
				if (m_bSetAnisoLevel)
					texImporter.anisoLevel	= anisoLevel;
		}

		if (m_bSetMaxTextureSizeIdx)
			texImporter.maxTextureSize		= maxTextureSize;
		if (m_bSetTextureFormatIdx)
 			texImporter.textureFormat		= textureFormat;
//  	texImporter.npotScale = TextureImporterNPOTScale.None;
		AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport);
	}
Esempio n. 47
0
 public bool GetPlatformTextureSettings(string platform, out int maxTextureSize, out TextureImporterFormat textureFormat)
 {
     int compressionQuality = 0;
     return this.GetPlatformTextureSettings(platform, out maxTextureSize, out textureFormat, out compressionQuality);
 }
        private static TextureImporterFormat MakeTextureFormatHaveAlpha(TextureImporterFormat format)
        {
            switch (format)
            {
                case TextureImporterFormat.RGB16:
                    return TextureImporterFormat.ARGB16;

                case TextureImporterFormat.DXT1:
                    return TextureImporterFormat.DXT5;

                case TextureImporterFormat.PVRTC_RGB2:
                    return TextureImporterFormat.PVRTC_RGBA2;

                case TextureImporterFormat.PVRTC_RGB4:
                    return TextureImporterFormat.PVRTC_RGBA4;

                case TextureImporterFormat.RGB24:
                    return TextureImporterFormat.ARGB32;
            }
            return format;
        }
	public TextureImportSettings()
	{
		textureFormat = TextureImporterFormat.AutomaticTruecolor;
		maxTextureSize = (int)TextureSize.Unlimited;
		grayscaleToAlpha = false;
		generateCubemap = TextureImporterGenerateCubemap.None;
		isReadable = false;
		mipmapEnabled = true;
		borderMipmap = false;
		mipmapFilter = TextureImporterMipFilter.BoxFilter;
		fadeout = false;
		mipmapFadeDistanceStart = 1;
		mipmapFadeDistanceEnd = 1;
		generateMipsInLinearSpace = false;
		normalmapFilter = TextureImporterNormalFilter.Standard;
		heightmapScale = 0.25f;
		anisoLevel = 1;
		filterMode = FilterMode.Bilinear;
		wrapMode = TextureWrapMode.Repeat;
		textureType = TextureImporterType.Image;
	}
    /// <summary>
    /// 设置图片格式
    /// </summary>
    /// <param name="path"></param>
    /// <param name="mTextureImporterType"></param>
    /// <param name="mTextureImporterFormat"></param>
    /// <param name="readEnable"></param>
    static void TextureSetting(string path, TextureImporterType mTextureImporterType = TextureImporterType.Default, TextureImporterFormat mTextureImporterFormat = TextureImporterFormat.RGBA32, bool readEnable = false)
    {
        TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
        if (textureImporter == null) return;
        textureImporter.textureType = mTextureImporterType;
        if (textureImporter.textureType == TextureImporterType.Default)
        {
            textureImporter.spriteImportMode = SpriteImportMode.None;
            textureImporter.mipmapEnabled = false;
            textureImporter.isReadable = readEnable;
            textureImporter.alphaIsTransparency = false;
        }
        else if (textureImporter.textureType == TextureImporterType.Sprite)
        {
            textureImporter.mipmapEnabled = false;
        }
        textureImporter.SetPlatformTextureSettings("Android", 2048, mTextureImporterFormat);
        textureImporter.SetPlatformTextureSettings("Windows", 2048, mTextureImporterFormat);
        textureImporter.SetPlatformTextureSettings("iPhone", 2048, TextureImporterFormat.PVRTC_RGB4);
        textureImporter.SetAllowsAlphaSplitting(false);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Esempio n. 51
0
		public bool GetPlatformTextureSettings(string platform, out int maxTextureSize, out TextureImporterFormat textureFormat)
		{
			int num = 0;
			return this.GetPlatformTextureSettings(platform, out maxTextureSize, out textureFormat, out num);
		}
Esempio n. 52
0
		public void SetPlatformTextureSettings(string platform, int maxTextureSize, TextureImporterFormat textureFormat)
		{
			this.SetPlatformTextureSettings(platform, maxTextureSize, textureFormat, 50);
		}
Esempio n. 53
0
 internal static extern TextureImporterFormat FullToSimpleTextureFormat(TextureImporterFormat format);
Esempio n. 54
0
    void OnGUI()
    {
        EditorGUILayout.Space();
        Texture2D tempTexture;
        tempTexture = EditorGUILayout.ObjectField("Texture to be edited", textureToEdit, typeof(Texture2D), false) as Texture2D;

        if(tempTexture == null)
        {
            tempTexture = new Texture2D(1,1);
        }

        //If new texture get color array
        if(textureToEdit != null && tempTexture != textureToEdit)
        {
            NewTexture(tempTexture);

        }

        //Check the format of texture
        CheckFormat();

        if(goodFormat)
        {
            if(textureToEdit != null)
            {
                textureWidth = textureToEdit.width;
                textureHeight = textureToEdit.height;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            autoAdjust = EditorGUILayout.ToggleLeft("Auto Adjust Import Settings", autoAdjust);

            if(GUILayout.Button("Revert to Original"))
            {
                textureToEdit.SetPixels(color3);
                textureToEdit.Apply();
                MatchColors();
                GetColors();
            }
            EditorGUILayout.EndHorizontal();

            float tempVariance;
            tempVariance = EditorGUILayout.Slider("Color Variance %", colorVariance,0.01f,0.2f);
            EditorGUILayout.Space();

            if(tempVariance != colorVariance )
            {
                colorVariance = tempVariance;
                MatchColors();
                GetColors();
            }

            //resize color list
            if(ColorList.Count != rows * columns)
            {
                if(ColorList.Count > rows * columns)
                {
                ColorList.RemoveAt(ColorList.Count - 1);
                }
                else
                {
                    for(int i = 0; i < rows*columns; i++)
                    {
                        ColorList.Add(new Color());
                    }
                }
            }

            //Create Color Array
            for(int i = 0; i < columns; i++)
            {
                EditorGUILayout.BeginHorizontal();

                for(int j = 0; j < rows; j++)
                {
                    Color tempColor;
                    tempColor = EditorGUILayout.ColorField(ColorList[i*rows + j]);

                    if(tempColor != ColorList[i*rows + j])
                    {
                        ReplaceColors(ColorList[i*rows + j], tempColor);
                        ColorList[i*rows + j] = tempColor;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        else
        {
            EditorGUILayout.Space();
            EditorGUILayout.TextField("The Texture needs to be tweaked...");
            EditorGUILayout.Space();
            EditorGUILayout.TextField("Texture needs have 'Read/Write' enabled and");
            EditorGUILayout.TextField("The format must be set to ARGB32, RGBA32, RGB24 or Alpha8");

            if(GUILayout.Button("Click Here to Make Changes"))
            {
                string path;
                path = AssetDatabase.GetAssetPath(textureToEdit);

                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
                //Save setting to reset after disable or unload of texture
                txReadable = importer.isReadable;
                txFormat = importer.textureFormat;
                Debug.Log(txReadable);
                //Change settings to allow editing
                importer.isReadable = true;
                importer.textureFormat = TextureImporterFormat.RGBA32;
                AssetDatabase.ImportAsset(path);
                goodFormat = true;
                MatchColors();
                GetColors();
            }
        }

        EditorGUILayout.Space();

        //Code to create new texture - Needs work
        //		string texName;
        //
        //		if(!createNew && goodFormat)
        //		{
        //			if(GUILayout.Button("Create New Palette"))
        //			{
        //				createNew = true;
        //			}
        //		}
        //		else
        //		{
        //			EditorGUILayout.Space();
        //			EditorGUILayout.LabelField("New Texture");
        //			EditorGUILayout.Space();
        //			newWidth = Mathf.ClosestPowerOfTwo(EditorGUILayout.IntSlider("Size", newWidth,32,2048));
        //			EditorGUILayout.Space();
        //			EditorGUILayout.LabelField("New Color Array");
        //			newRows = EditorGUILayout.IntSlider("# Rows", newRows,1,4);
        //			newColumns = EditorGUILayout.IntSlider("# Columns", newColumns,1,4);
        //			EditorGUILayout.Space();
        //			EditorGUILayout.BeginHorizontal();
        //			EditorGUILayout.LabelField("Filename : ");
        //			texName = EditorGUILayout.TextField("Color_Palette_" + Random.Range(1,1000));
        //			EditorGUILayout.EndHorizontal();
        //
        //			EditorGUILayout.Space();
        //			EditorGUILayout.BeginHorizontal();
        //			if(GUILayout.Button("Save Palette"))
        //			{
        //
        //				rows = newRows;
        //				columns = newColumns;
        //
        //				CreateNewTexture(newWidth, texName, newRows, newColumns);
        //
        //				createNew = false;
        //			}
        //			if(GUILayout.Button("Cancel New Palette"))
        //			{
        //				createNew = false;
        //			}
        //			EditorGUILayout.EndHorizontal();
        //		}

        EditorGUILayout.BeginHorizontal();
        if(GUILayout.Button("Save 1"))
        {
            Tex1 = new Texture2D(textureWidth,textureWidth);
            Tex1.SetPixels(colors);
            Tex1.Apply();
            color1 = Tex1.GetPixels();
        }
        if(GUILayout.Button("Save 2"))
        {
            Tex2 = new Texture2D(textureWidth,textureWidth);
            Tex2.SetPixels(colors);
            Tex2.Apply();
            color2 = Tex2.GetPixels();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUI.DrawPreviewTexture(new Rect(winWidth * 0.2f,230,75,75),Tex1);
        EditorGUI.DrawPreviewTexture(new Rect(winWidth * 0.65f,230,75,75),Tex2);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if(GUILayout.Button("Load 1"))
        {
            textureToEdit.SetPixels(color1);
            textureToEdit.Apply();
            MatchColors();
        }
        if(GUILayout.Button("Load 2"))
        {
            textureToEdit.SetPixels(color2);
            textureToEdit.Apply();
            MatchColors();
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 55
0
 public extern bool GetPlatformTextureSettings(string platform, out int maxTextureSize, out TextureImporterFormat textureFormat, out int compressionQuality);
Esempio n. 56
0
	// ===========================================================================================================================
	public static void ReimportTexture(string texturePath, bool bGUITexture, TextureWrapMode wrapMode, FilterMode filterMode, int anisoLevel, int maxTextureSize, TextureImporterFormat textureFormat)
	{
// 		Debug.Log("ChangeImportTextureToGUI - " + assetPath);
		TextureImporter	texImporter = TextureImporter.GetAtPath(texturePath) as TextureImporter;

		TextureImporterSettings settings = new TextureImporterSettings();
		texImporter.ReadTextureSettings(settings);
// 		settings.ApplyTextureType(TextureImporterType.GUI, false);
// 		texImporter.SetTextureSettings(settings);

		texImporter.wrapMode			= wrapMode;
		texImporter.filterMode			= filterMode;
		texImporter.anisoLevel			= anisoLevel;

		if (bGUITexture)
	 		 texImporter.textureType	= TextureImporterType.GUI;
		else texImporter.textureType	= TextureImporterType.Image;

		texImporter.maxTextureSize		= maxTextureSize;
		texImporter.textureFormat		= textureFormat;
//  	texImporter.npotScale			= TextureImporterNPOTScale.None;
		AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceSynchronousImport);
	}
Esempio n. 57
0
 public void SetPlatformTextureSettings(string platform, int maxTextureSize, TextureImporterFormat textureFormat, [DefaultValue("false")] bool allowsAlphaSplit)
 {
     this.SetPlatformTextureSettings(platform, maxTextureSize, textureFormat, 50, allowsAlphaSplit);
 }
Esempio n. 58
0
		private bool SaveTexture(ref Texture2D tex, ref string save_path, string default_name, int buttonwidth, TextureImporterFormat textureFormat, bool mipmapEnabled, bool button_triggered=true, bool sRGB_flag=false) {
			//		if (tex==null) return;			
			//		if (AssetDatabase.GetAssetPath(tex)!="") return;
			EditorGUI.BeginDisabledGroup( tex==null || AssetDatabase.GetAssetPath(tex)!="");
			bool saved=false;
			bool cond;
			if (button_triggered) {
				cond=GUILayout.Button("Save to file", GUILayout.MaxWidth(buttonwidth));
			} else {
				cond=true;
			}
			if (cond) {
				string directory;
				string file;
				if (save_path=="") {
					directory=Application.dataPath;
					file=default_name;
				} else {
					directory=Path.GetDirectoryName(save_path);
					file=Path.GetFileNameWithoutExtension(save_path)+".png";
				}
				string path = EditorUtility.SaveFilePanel("Save texture", directory, file, "png");
				if (path!="") {
					path=path.Substring(Application.dataPath.Length-6);
					save_path=path;
					// kopia, bo mozemy miec skompresowana texture
					Texture2D ntex=new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true);
					for(int mip=0; mip<tex.mipmapCount; mip++) {
						Color32[] cols=tex.GetPixels32(mip);
						ntex.SetPixels32(cols, mip);
						ntex.Apply(false,false);
					}					
					byte[] bytes = ntex.EncodeToPNG();
					ntex=null;
					System.IO.File.WriteAllBytes(path, bytes);
					AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
					TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
					textureImporter.textureFormat = textureFormat; 
					textureImporter.mipmapEnabled = mipmapEnabled; 
					textureImporter.linearTexture=sRGB_flag;					
					AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
					if (tex!=null) {
						if (AssetDatabase.GetAssetPath(tex)=="") {
							DestroyImmediate (tex);
							tex=null;
						}
					}
					tex = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
					saved=true;
					EditorUtility.UnloadUnusedAssetsImmediate();
				}		
			}
			EditorGUI.EndDisabledGroup();
			return saved;
		}
Esempio n. 59
0
 internal static extern TextureImporterFormat SimpleToFullTextureFormat2(TextureImporterFormat simpleFormat, TextureImporterType tType, TextureImporterSettings settings, bool doesTextureContainAlpha, bool sourceWasHDR, BuildTarget destinationPlatform);
	static void SelectedChangeTextureFormatSettings(TextureImporterFormat newFormat) {
		
		Object[] textures = GetSelectedTextures();
		Selection.objects = new Object[0];
		foreach (Texture2D texture in textures)  {
			string path = AssetDatabase.GetAssetPath(texture);
			//Debug.Log("path: " + path);
			TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
			textureImporter.textureFormat = newFormat; 
			AssetDatabase.ImportAsset(path);
		}
	}