Example #1
0
 public static void GetTexFormat(bool isAtlas, string userData, out ETextureCompress format, out ETextureSize size)
 {
     format = ETextureCompress.Compress;
     size   = isAtlas ? ETextureSize.Original : ETextureSize.Half;
     if (!string.IsNullOrEmpty(userData))
     {
         string[] str = userData.Split(' ');
         if (str.Length > 0)
         {
             try
             {
                 format = (ETextureCompress)int.Parse(str[0]);
             }
             catch (Exception) { }
         }
         if (str.Length > 1)
         {
             try
             {
                 size = (ETextureSize)int.Parse(str[1]);
             }
             catch (Exception) { }
         }
     }
 }
Example #2
0
        public void OnEnable()
        {
            texImporter = target as TextureImporter;
            texFormat.Clear();
            if (texImporter != null)
            {
                path         = texImporter.assetPath;
                cannotHotfix = path.StartsWith("Assets/Resources/StaticUI");
                isUITex      = (path.StartsWith("Assets/Resources/atlas/UI") || path.StartsWith("Assets/Resources/StaticUI")) && !path.EndsWith("_A.png");
                if (isUITex)
                {
                    GetTexFormat(IsAtlas(path), texImporter.userData, out srcFormat, out alphaSize);
                    for (int i = 0; i < targets.Length; ++i)
                    {
                        TextureImporter ti = targets[i] as TextureImporter;
                        if (ti != null)
                        {
                            needAlpha = ti.DoesSourceTextureHaveAlpha();
                            TexFormat tf = new TexFormat();
                            GetTexFormat(IsAtlas(ti.assetPath), ti.userData, out tf.srcFormat, out tf.alphaSize);
                            texFormat.Add(tf);
                            if (tf.srcFormat != srcFormat)
                            {
                                srcFormat = (ETextureCompress)(-1);
                            }
                            if (tf.alphaSize != alphaSize)
                            {
                                alphaSize = (ETextureSize)(-1);
                            }
                        }
                    }
                }
            }

            SceneView.onSceneGUIDelegate = TargetUpdate;
            Type t = null;

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (type.Name.ToLower().Contains("textureimporterinspector"))
                    {
                        t = type;
                        break;
                    }
                }
            }
            nativeEditor = Editor.CreateEditor(target, t);
        }
        private void OnGUI()
        {
            //GUILayout.BeginHorizontal();

            if (GUILayout.Button("Compress", GUILayout.MaxWidth(150)))
            {
                Compress();
            }

            compressSize = (ETextureSize)EditorGUILayout.EnumPopup("缩放", compressSize);
            compressType = (ETextureCompress)EditorGUILayout.EnumPopup("压缩格式", compressType);
            wrapMode     = (TextureWrapMode)EditorGUILayout.EnumPopup("采样模式", wrapMode);
            genMipmap    = EditorGUILayout.ToggleLeft("GenMipmap", genMipmap);
            genAlpha     = EditorGUILayout.ToggleLeft("GenAlpha", genAlpha);
            if (genAlpha)
            {
                genRAlpha = EditorGUILayout.ToggleLeft("Gen R Channel Alpha", genRAlpha);
                alphaSize = (ETextureSize)EditorGUILayout.EnumPopup("alpha缩放", alphaSize);
            }
        }
Example #4
0
 public override void OnInspectorGUI()
 {
     if (buttonStyle == null)
     {
         buttonStyle           = new GUIStyle(EditorStyles.boldLabel);
         buttonStyle.alignment = TextAnchor.MiddleRight;
     }
     nativeEditor.OnInspectorGUI();
     if (cannotHotfix)
     {
         if (warningStyle == null)
         {
             warningStyle                  = new GUIStyle(GUI.skin.label);
             warningStyle.fontStyle        = FontStyle.Bold;
             warningStyle.normal.textColor = new Color(1, 0, 0);
             warningStyle.fontSize         = 20;
         }
         GUILayout.Label("此图不能热更新!!!", warningStyle);
     }
     if (isUITex && texImporter != null)
     {
         GUILayout.Space(20);
         ETextureCompress newSrcFormat = (ETextureCompress)EditorGUILayout.EnumPopup("压缩", srcFormat);
         ETextureSize     newAlphaSize = (ETextureSize)EditorGUILayout.EnumPopup("Alpha缩放", alphaSize);
         if (newSrcFormat != srcFormat || newAlphaSize != alphaSize)
         {
             if (newSrcFormat != srcFormat)
             {
                 srcFormat = newSrcFormat;
             }
             if (newAlphaSize != alphaSize)
             {
                 alphaSize = newAlphaSize;
             }
         }
         GUILayout.Label(needAlpha ? "有alpha" : "无alpha");
         GUILayout.Space(10);
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Apply", GUILayout.MaxWidth(50)))
         {
             int format = (int)newSrcFormat;
             int size   = (int)newAlphaSize;
             for (int i = 0; i < targets.Length; ++i)
             {
                 TextureImporter ti = targets[i] as TextureImporter;
                 TexFormat       tf = texFormat[i];
                 if (ti != null)
                 {
                     int f = format == -1 ? (int)tf.srcFormat : format;
                     int s = size == -1 ? (int)tf.alphaSize : size;
                     ti.userData = string.Format("{0} {1}", f, s);
                     EditorUtility.DisplayProgressBar(string.Format("Processing-{0}/{1}", i, targets.Length), ti.assetPath, (float)i / targets.Length);
                 }
             }
             EditorUtility.ClearProgressBar();
             EditorUtility.DisplayDialog("Finish", "All textures processed finish", "OK");
         }
         if (GUILayout.Button("Texture Status", GUILayout.MaxWidth(100)))
         {
             TextureStatus window = (TextureStatus)EditorWindow.GetWindow(typeof(TextureStatus), true, "TextureStatus");
             window.Show();
         }
         GUILayout.EndHorizontal();
     }
 }