Ejemplo n.º 1
0
    List <SelectSpriteInfo> GetSelectedInfo()
    {
        List <SelectSpriteInfo> aSelect = new List <SelectSpriteInfo>();

        List <Texture> aTexList = AtlasMng_Editor.GetSelectedTextures();

        foreach (Texture o in aTexList)
        {
            string szName = AtlasMng_Editor.GetAssetPathByTexture(o);
            if (!string.IsNullOrEmpty(szName))
            {
                if (szName.IndexOf("Assets/Atlas/") == 0)
                {
                    continue;
                }
                SelectSpriteInfo info = new SelectSpriteInfo();
                info.m_szAssetsName = szName;
                info.m_szSpriteName = AtlasMng_Editor.GetSpriteNameByAssetsName(szName);
                info.m_szAtlasName  = CAtlasMng.instance.GetAtlasNameBySpriteName(info.m_szSpriteName);
                if (string.IsNullOrEmpty(info.m_szAtlasName))
                {
                    info.m_szAtlasName = NGUISettings.atlasName.Trim();
                    if (string.IsNullOrEmpty(info.m_szAtlasName))
                    {
                        info.m_szAtlasName = "default";
                    }
                }
                UITexAtlas atlas = CAtlasMng.instance.GetAltas(info.m_szSpriteName);
                if (atlas != null)
                {
                    continue;
                }

                info.m_sprite    = CAtlasMng.instance.GetSprite(info.m_szSpriteName);
                info.m_selectTex = o;
                aSelect.Add(info);
            }
        }
        return(aSelect);
    }
Ejemplo n.º 2
0
    void RenderAtlasInfo(ref int nX, ref int nY)
    {
        nY += 5;
        float fLineGap = 3.0f;

        float fBtH  = 20.0f;
        float fBtW  = 80.0f;
        float fTexH = 15.0f;

        float fx       = (float)nX;
        float fy       = (float)nY;
        float fButtonX = fx;

        fButtonX += fBtW + 5.0f;
        NGUISettings.atlasName = GUI.TextField(new Rect(fButtonX, fy, 100.0f, fBtH), NGUISettings.atlasName, 25);
        fButtonX += 100.0f + 5.0f;
        bool bModifyAtlas = false;

        if (GUI.Button(new Rect(fButtonX, fy, fBtW, fBtH), "修改"))
        {
            bModifyAtlas = true;
        }
        fButtonX += fBtW;
        bool bRepareAtlas = false;

        if (GUI.Button(new Rect(fButtonX, fy, fBtW, fBtH), "整理"))
        {
            bRepareAtlas = true;
        }
        fButtonX += fBtW;
        bool bExportIcon = false;

        if (GUI.Button(new Rect(fButtonX, fy, fBtW, fBtH), "导出"))
        {
            bExportIcon = true;
        }
        //fy += fBtH + fLineGap;

        fButtonX += fBtW;
        bool bExportID = false;

        if (GUI.Button(new Rect(fButtonX, fy, fBtW, fBtH), "导出ID表"))
        {
            bExportID = true;
        }
        fButtonX += fBtW;
        fy       += fBtH + fLineGap;


        // 渲染一个数字吧
        float x = fx + fBtW;

        GUI.Label(new Rect(fx, fy, fBtW, fBtH), "Padding");
        NGUISettings.atlasPadding = RenderEditorNumb(x, fy, 20, fTexH + 2, NGUISettings.atlasPadding);
        GUI.Label(new Rect(x + 25, fy, 150, fBtH), "Pixel in-between of sprites");
        fy += fTexH + fLineGap;

        //
        GUI.Label(new Rect(fx, fy, fBtW, fBtH), "Trim Alpha");
        NGUISettings.atlasTrimming = RenderCheckBox(x, fy, 200, fBtH, NGUISettings.atlasTrimming, "Remove empty space");
        bool  bAdjustAtlas = false;
        float fLeft        = x + 25 + 150 + fBtW;

        if (GUI.Button(new Rect(x + 25 + 150 + fBtW, fy, fBtW, fBtH), "纠正数据"))
        {
            bAdjustAtlas = true;
        }

        bool bBinToTxt = false;

        if (GUI.Button(new Rect(fLeft + fBtW + 5, fy, fBtW * 2, fBtH), "二进制转换文本"))
        {
            bBinToTxt = true;
        }
        fLeft += fBtW * 2 + 5;

        bool bTxtToBin = false;

        if (GUI.Button(new Rect(fLeft + fBtW + 5, fy, fBtW * 2, fBtH), "文本转二进制"))
        {
            bTxtToBin = true;
        }
        fy += fTexH + fLineGap;

        GUI.Label(new Rect(fx, fy, fBtW, fBtH), "PMA Shader");
        NGUISettings.atlasPMA = RenderCheckBox(x, fy, 200, fBtH, NGUISettings.atlasPMA, "Pre-multiply color by alpha");
        if (NGUISettings.atlasPMA)
        {
            NGUISettings.atlasPMA = false;
            EditorUtility.DisplayDialog("警告", "这个已经不支持了,只能选择false", "确定");
        }
        fy += fTexH + fLineGap;

        GUI.Label(new Rect(fx, fy, fBtW, fBtH), "4096x4096");
        NGUISettings.allow4096 = RenderCheckBox(x, fy, 200, fBtH, NGUISettings.allow4096, "if off, limit atlases to 2048x2048");
        fy += fTexH + fLineGap;

        nY = (int)fy;
        // 渲染材质属性

        if (bModifyAtlas)
        {
            AtlasMng_Editor.instance.m_lpImportPackTextureFunc = ImportPackTextureFunc;
            UITexAtlas atlas = AtlasMng_Editor.instance.GetAltas(NGUISettings.atlasName);
            if (atlas != null)
            {
                atlas.pixelSize = NGUISettings.atlasPadding;
                AtlasMng_Editor.instance.SaveAltasCfg();
            }
        }
        if (bRepareAtlas)
        {
            bool bTrimAlpha = NGUISettings.atlasTrimming;
            AtlasMng_Editor.instance.m_lpImportPackTextureFunc = ImportPackTextureFunc;
            if (AtlasMng_Editor.instance.RepareAtlas(NGUISettings.atlasName, bTrimAlpha))
            {
                EditorUtility.DisplayDialog("提示", "整理完毕", "OK");
            }
            else
            {
                EditorUtility.DisplayDialog("提示", "整理失败", "OK");
            }
        }
        if (bExportIcon)
        {
            // 导出选选择的图片
            string szDefPath = Application.dataPath + "/";
            string szPath    = EditorUtility.OpenFolderPanel("打开要导出的目录", szDefPath, "");
            if (!string.IsNullOrEmpty(szPath))
            {
                szPath = szPath + '/';
                AtlasMng_Editor.instance.m_lpImportPackTextureFunc = ImportPackTextureFunc;
                if (AtlasMng_Editor.instance.ExportSpriteIcon(NGUISettings.atlasName, szPath, ExportTGA))
                {
                    EditorUtility.DisplayDialog("提示", "导出完毕", "OK");
                }
                else
                {
                    EditorUtility.DisplayDialog("提示", "导出失败", "OK");
                }
            }
        }
        if (bExportID)
        {
            string   szDefPath = Application.dataPath + "/";
            string[] filters   = { ".txt", ".*" };
            string   szPath    = EditorUtility.OpenFolderPanel("打开要导出的目录", szDefPath, "");
            //string szPathName = EditorUtility.SaveFilePanel("导出ID文件", szDefPath, "gif_id.txt", "txt");
            if (!string.IsNullOrEmpty(szPath))
            {
                szPath = szPath + '/';
                string szPathName = szPath + "gif_id.txt";
                ExportSelectID(szPathName);
            }
        }
        if (bAdjustAtlas)
        {
            if (AtlasMng_Editor.instance.AdjustAtlasData())
            {
                EditorUtility.DisplayDialog("提示", "纠正完毕,已保存", "OK");
            }
            else
            {
                EditorUtility.DisplayDialog("提示", "没有需要纠正的数据", "OK");
            }
        }
        if (bBinToTxt)
        {
            AtlasMng_Editor atlasMng = new AtlasMng_Editor();
            atlasMng.LoadAndSaveAtlas(false);
        }
        if (bTxtToBin)
        {
            AtlasMng_Editor atlasMng = new AtlasMng_Editor();
            atlasMng.LoadAndSaveAtlas(true);
        }
    }