Exemplo n.º 1
0
 static int PackByPath(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UIResMgr obj = (UIResMgr)ToLua.CheckObject(L, 1, typeof(UIResMgr));
         System.Collections.Generic.List <string> arg0 = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <string>));
         obj.PackByPath(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 2
0
    void Set()
    {
        int i = 0;

        foreach (TextureImporter tex in m_texs)
        {
            CheckRename(tex, m_prefix);
            if (string.IsNullOrEmpty(m_atlasName))
            {
                tex.textureType = TextureImporterType.Sprite;
            }
            else
            {
                tex.textureType = TextureImporterType.Default;
            }
            tex.npotScale                 = TextureImporterNPOTScale.None;
            tex.lightmap                  = false;
            tex.normalmap                 = false;
            tex.spriteImportMode          = SpriteImportMode.Single;
            tex.spritePackingTag          = m_atlasName;
            tex.borderMipmap              = false;
            tex.linearTexture             = false;
            tex.alphaIsTransparency       = true;
            tex.grayscaleToAlpha          = false;
            tex.isReadable                = false;
            tex.mipmapEnabled             = false;
            tex.generateMipsInLinearSpace = false;
            tex.wrapMode                  = TextureWrapMode.Clamp;
            tex.filterMode                = FilterMode.Bilinear;
            tex.anisoLevel                = 1;

            //if (string.IsNullOrEmpty(m_atlasName) && IsNpot(tex))
            //{//单张图而且不是2的n次方的话,自动压缩
            //    SetFormat(tex, "Standalone", TextureImporterFormat.AutomaticCompressed);
            //    SetFormat(tex, "Android", TextureImporterFormat.AutomaticCompressed);
            //    SetFormat(tex, "iPhone", TextureImporterFormat.AutomaticCompressed);
            //}
            //else
            //{
            //SetFormat(tex, "", TextureImporterFormat.ARGB32);
            //tex.textureFormat = TextureImporterFormat.ARGB32;
            //SetFormat(tex,  "Standalone", TextureImporterFormat.ARGB32);
            tex.ClearPlatformTextureSettings("Standalone");

            SetFormat(tex, "Android", TextureImporterFormat.ETC2_RGBA8);
            SetFormat(tex, "iPhone", TextureImporterFormat.PVRTC_RGBA4);
            EditorUtil.SetDirty(tex);
            //}
            ++i;
            EditorUtility.DisplayProgressBar("Loading", string.Format("正在修改格式和重命名,{0}/{1}", i, m_texs.Count), ((float)i / m_texs.Count) * 0.9f);
        }

        //根据格式重新导入下资源
        foreach (TextureImporter t in m_texs)
        {
            AssetDatabase.WriteImportSettingsIfDirty(t.assetPath);
        }
        try
        {
            AssetDatabase.StartAssetEditing();
            i = 0;
            foreach (TextureImporter t in m_texs)
            {
                EditorUtility.DisplayProgressBar("Loading", string.Format("正在重新导出资源:第{0}个,共{1}个", i, m_texs.Count), 0.1f + (0.9f * i) / m_texs.Count);
                AssetDatabase.WriteImportSettingsIfDirty(t.assetPath);
                ++i;
            }
        }
        finally
        {
            AssetDatabase.StopAssetEditing();
            EditorUtility.ClearProgressBar();
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        //检查是不是要重新打包
        EditorUtility.DisplayProgressBar("Loading", string.Format("检查打包中"), 0.9f);
        EditorUtility.ClearProgressBar();
        UnityEditor.Sprites.Packer.kDefaultPolicy = "DefaultPackerPolicy";//TightPackerPolicy DefaultPackerPolicy
#if UNITY_ANDROID
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.Android, true);
#endif

#if UNITY_IPHONE
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.iOS, true);
#endif

#if UNITY_STANDALONE_WIN
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.StandaloneWindows, true);
#endif

        //打包进UI资源管理器中
        List <string> path = new List <string>();
        foreach (TextureImporter tex in m_texs)
        {
            //Debuger.Log("资源路径"+tex.assetPath);
            path.Add(tex.assetPath);
        }
        UIResMgr.PackByPath(path);
    }
Exemplo n.º 3
0
    void Set()
    {
        int i = 0;

        foreach (TextureImporter tex in m_texs)
        {
            CheckRename(tex, m_atlasName);
            //if (string.IsNullOrEmpty(m_atlasName))
            //    tex.textureType = TextureImporterType.Sprite;
            //else
            //    tex.textureType = TextureImporterType.Default;
            tex.textureType         = TextureImporterType.Sprite;
            tex.npotScale           = TextureImporterNPOTScale.None;
            tex.spriteImportMode    = SpriteImportMode.Single;
            tex.spritePackingTag    = m_atlasName;
            tex.borderMipmap        = false;
            tex.sRGBTexture         = true;
            tex.alphaIsTransparency = true;
            tex.isReadable          = false;
            tex.mipmapEnabled       = false;
            tex.wrapMode            = TextureWrapMode.Clamp;
            tex.filterMode          = FilterMode.Bilinear;
            tex.anisoLevel          = 1;

            //if (string.IsNullOrEmpty(m_atlasName) && IsNpot(tex))
            //{//单张图而且不是2的n次方的话,自动压缩
            //    SetFormat(tex, "Standalone", TextureImporterFormat.AutomaticCompressed);
            //    SetFormat(tex, "Android", TextureImporterFormat.AutomaticCompressed);
            //    SetFormat(tex, "iPhone", TextureImporterFormat.AutomaticCompressed);
            //}
            //else
            //{
            //SetFormat(tex, "", TextureImporterFormat.ARGB32);
            //tex.textureFormat = TextureImporterFormat.ARGB32;
            //SetFormat(tex,  "Standalone", TextureImporterFormat.ARGB32);
            tex.ClearPlatformTextureSettings("Standalone");

            //SetFormat(tex, "Android", TextureImporterFormat.ETC2_RGBA8);
            //SetFormat(tex, "iPhone", TextureImporterFormat.PVRTC_RGBA4);
            EditorUtil.SetDirty(tex);
            //}
            ++i;
            EditorUtility.DisplayProgressBar("Loading", string.Format("正在修改格式和重命名,{0}/{1}", i, m_texs.Count), ((float)i / m_texs.Count) * 0.9f);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        //检查是不是要重新打包
        EditorUtility.DisplayProgressBar("Loading", string.Format("检查打包中"), 0.9f);
        EditorUtility.ClearProgressBar();
        UnityEditor.Sprites.Packer.kDefaultPolicy = "DefaultPackerPolicy";//TightPackerPolicy DefaultPackerPolicy
#if UNITY_ANDROID
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.Android, true);
#endif

#if UNITY_IPHONE
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.iOS, true);
#endif

#if UNITY_STANDALONE_WIN
        UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.StandaloneWindows, true);
#endif

        //打包进UI资源管理器中
        List <string> path = new List <string>();
        foreach (TextureImporter tex in m_texs)
        {
            //Debuger.Log("资源路径"+tex.assetPath);
            path.Add(tex.assetPath);
        }

        string modName = "";

        string   pathStr = path[0];
        string[] pList   = pathStr.Split('/');
        for (int n = 0; n < pList.Length; n++)
        {
            if (pList[n] == "Atlas")
            {
                modName = pList[n + 1];
            }
        }

        UIResMgr uiRes = UIResTool.Get(modName);
        if (Application.isPlaying)
        {
            Debug.LogError("运行中不能设置图片");
            return;
        }
        uiRes.PackByPath(path);
    }