Пример #1
0
 public static void SetCdnServer(string cdnServer)
 {
     if (cdnServer.IsEmpty())
     {
         return;
     }
     rootPath = GetPath(cdnServer, string.Empty, Platform.platform, TexFormatGroup.GetBest());
 }
Пример #2
0
 public static void ConvertDependencies(this TexFormatGroup newFormat, string[] assetPaths)
 {
     foreach (string depPath in AssetDatabase.GetDependencies(assetPaths))
     {
         if (depPath.Is(FileType.Image))
         {
             Texture2D tex = AssetDatabase.LoadAssetAtPath <Texture2D>(depPath);
             newFormat.Convert(tex);
         }
     }
 }
Пример #3
0
 public static TextureImporterFormat GetFormatFromLabel(Texture2D tex, TexFormatGroup group, bool alpha)
 {
     string[] labels = AssetDatabase.GetLabels(tex);
     if (!labels.IsEmpty())
     {
         foreach (string l in labels)
         {
             if (group.IsGroupOf(l))
             {
                 return(EnumUtil.Parse <TextureImporterFormat>(l));
             }
         }
     }
     return(alpha? group.rgba(): group.rgb());
 }
Пример #4
0
        public static void GetResourceVersion(Action <string> callback)
        {
            string verUrl = string.Format("{0}/version_{1}.txt", Path, TexFormatGroup.GetBest().GetAbCategory(Platform.platform));

            Web.noCache.GetBytes(verUrl, bytes =>
            {
                if (bytes != null)
                {
                    string ver = Encoding.ASCII.GetString(bytes);
                    callback(ver);
                }
                else
                {
                    AssetCache.log.Error("Can't get cdn version from {0}", verUrl);
                    callback(null);
                }
            });
        }
Пример #5
0
        public static void Convert(this TexFormatGroup format, string folder)
        {
            log.Debug("Converting texture format to '{0}'", format);
            Regex ignore = new Regex("/Editor/|Assets/Plugins/");

            foreach (string p in EditorAssetUtil.ListAssetPaths(folder, FileType.Image))
            {
                if (ignore.IsMatch(p))
                {
                    continue;
                }
                log.Debug(p);
                Texture2D t = AssetDatabase.LoadAssetAtPath <Texture2D>(p);
                if (t != null)
                {
                    format.Convert(t);
                }
            }
        }
Пример #6
0
 public static string GetPath(string root, string zone, RuntimePlatform platform, TexFormatGroup texFormat)
 {
     return(PathUtil.Combine(root, BuildConfig.BUILD_ID, zone, texFormat.GetAbCategory(platform), BuildConfig.RES_VERSION));
 }
Пример #7
0
 public static bool IsMemberOf(this TextureImporterFormat format, TexFormatGroup group)
 {
     return(group.IsGroupOf(format));
 }
Пример #8
0
        public static void Convert(this TexFormatGroup newFormat, Texture2D tex)
        {
            string          path = AssetDatabase.GetAssetPath(tex);
            TextureImporter im   = AssetImporter.GetAtPath(path) as TextureImporter;

            if (im == null || tex.format == TextureFormat.Alpha8)
            {
                return;
            }
            bool changed = false;

            if (newFormat == TexFormatGroup.ASTC && !tex.format.IsASTC())
            {
                im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                changed = true;
            }
            else if (newFormat == TexFormatGroup.ETC2 && !tex.format.IsETC2())
            {
                im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                changed = true;
            }
            else if (newFormat == TexFormatGroup.PVRTC && !tex.format.IsPVRTC())
            {
                if (EditorUserBuildSettings.activeBuildTarget.ToRuntimePlatform().IsIos() &&
#pragma warning disable 0618
                    (im.GetFormat() == TextureImporterFormat.AutomaticCompressed || im.GetFormat() == TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
                {
                    // automatic is the same as PVRTC
                }
                else if (tex.format.HasAlpha())
                {
                    // PVRTC with alpha downgrades the image quality
//					im.textureFormat = TextureImporterFormat.PVRTC_RGB4;
//					changed = true;
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
            }
            else if (newFormat == TexFormatGroup.ETC && !tex.format.IsETC())
            {
                if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android &&
#pragma warning disable 0618
                    (im.GetFormat() == TextureImporterFormat.AutomaticCompressed || im.GetFormat() == TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
                {
                    // automatic is the same as ETC
                }
                else if (tex.format.HasAlpha())
                {
                    // alpha is not supported in ETC format
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
#pragma warning disable 0618
            }
            else if (newFormat == TexFormatGroup.AUTO && (im.GetFormat() != TextureImporterFormat.AutomaticCompressed && im.GetFormat() != TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
            {
                if (tex.format.HasAlpha())
                {
                    // compressing alpha
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
            }
            if (!AssetConfig.TEX_NPOT && im.npotScale == TextureImporterNPOTScale.None && !tex.IsPOT())
            {
                im.npotScale = TextureImporterNPOTScale.ToNearest;
                changed      = true;
            }
            if (changed)
            {
                im.textureType = TextureImporterType.Default;
                im.isReadable  = false;
                AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
            }
        }
Пример #9
0
 public static TextureImporterFormat rgb(this TexFormatGroup group)
 {
     return(group.ToData().rgb);
 }
Пример #10
0
 public static bool IsGroupOf(this TexFormatGroup group, string format)
 {
     return(group.ToData().IsGroupOf(format));
 }
Пример #11
0
 public static bool IsGroupOf(this TexFormatGroup group, TextureImporterFormat format)
 {
     return(group.ToData().IsGroupOf(format));
 }
Пример #12
0
 public static TexFormatGroupData ToData(this TexFormatGroup format)
 {
     return(TexFormatGroupData.ParseIgnoreCase(format.ToString()));
 }