Example #1
0
 static void SetAssetsTextureImporterFormatDefault()
 {
     Object[] selectObjs = Selection.objects;
     foreach (var item in selectObjs)
     {
         List <string> itemLabels = AssetDatabase.GetLabels(item).ToList();
         itemLabels.Remove("TextureImporterFormat_PVRTC_RGBA4");
         AssetDatabase.SetLabels(item, itemLabels.ToArray());
     }
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
     EditorAssetBundleEditorTool.ResetAndAutoRenameAssetBundle();
 }
    /// <summary>
    /// 自动出来资源导入
    /// </summary>
    public static bool ProcessAssetImport(string name)
    {
        if (name.EndsWith(".dds"))
        {
            if (EditorUtility.DisplayDialog("出现了dds格式的纹理,这是不允许的!不要问为什么。", name, "删除"))
            {
                AssetDatabase.DeleteAsset(name);
            }
            else
            {
                AssetDatabase.DeleteAsset(name);
            }

            return(false);
        }

        if (!name.Contains("/Custom") && (name.EndsWith(".png") || name.EndsWith(".jpg")))
        {
            TextureImporter textureImporter = AssetImporter.GetAtPath(name) as TextureImporter;
            bool            customSetting   = false;
            AssetDatabase.GetLabels(textureImporter).ForEach((x) =>
            {
                if (x == "TextureImporterFormatCustomSetting")
                {
                    customSetting = true;
                }
            });

            if (!customSetting)
            {
                textureImporter.spriteImportMode    = SpriteImportMode.Single;
                textureImporter.alphaIsTransparency = true;
                if (textureImporter != null)
                {
                    textureImporter.mipmapEnabled = false;
                    textureImporter.wrapMode      = TextureWrapMode.Clamp;
                    if (name.StartsWith("Assets/Game/PackagingResources/") && (name.Contains("/Module/") || name.Contains("/Effect")) && name.Contains("/Image/"))
                    {
                        bool needSaveAndReimport = false;

                        if (textureImporter.textureType != TextureImporterType.Sprite)
                        {
                            textureImporter.textureType = TextureImporterType.Sprite;
//                            if (name.EndsWith(".jpg"))
//                            {
//                                textureImporter.alphaSource = TextureImporterAlphaSource.None;
//                            }
                            needSaveAndReimport = true;
                        }

                        needSaveAndReimport |= ProcessIosAssetSpriteImport(textureImporter);
                        needSaveAndReimport |= ProcessAndroidAssetSpriteImport(textureImporter);
                        if (needSaveAndReimport)
                        {
                            textureImporter.SaveAndReimport();
                        }
                    }
                    else if (name.Contains("/ModuleEffectPicture/"))
                    {
                        if (name.EndsWith(".jpg"))
                        {
                            textureImporter.alphaSource = TextureImporterAlphaSource.FromInput;
                        }

                        if (textureImporter.textureType != TextureImporterType.Sprite)
                        {
                            textureImporter.textureType = TextureImporterType.Sprite;
                            textureImporter.SaveAndReimport();
                        }
                    }
                }
            }
        }

        return(EditorAssetBundleEditorTool.AutoProcessAsset(name));
    }