Пример #1
0
    void CopyOri(List <rectData> _ori, string atlasName)
    {
        if (_ori == null || _ori.Count == 0)
        {
            //Debug.Log("完成");
            return;
        }
        List <Rect> rc = new List <Rect>();

        foreach (var item in _ori)
        {
            rc.Add(item.rect);
        }
        List <rectData> _surplus = new List <rectData>();
        List <rectData> mItemp   = new List <rectData>();

        // 图集组合优化: 一个图集,固定size,源图片中选择最佳组合,最大化利用图集size
        MaxRectsBinPack temp = new MaxRectsBinPack(1024, 1024, false);

        temp.insert2(rc, new List <Rect>(), inputReactDic[InputKey]);

        for (int i = 0; i < _ori.Count; i++)
        {
            Rect     rect = temp.usedRectangles[i];
            rectData data = new rectData();
            data = _ori[i];
            if (rect == new Rect())
            {
                _surplus.Add(data);
            }
            else
            {
                data.rect = rect;
                mItemp.Add(data);
            }
        }
        if (mItemp.Count != 0)
        {
            histDic.Add((atlasName + "_" + (++key)).ToString(), mItemp);
            CopyOri(_surplus, atlasName);
        }
        else
        {
            foreach (var item in _surplus)
            {
                Debug.LogError("图片大于1024相素 : " + item.key);
                //NGUIDebug.Log("图片大于1024相素 : " + item.key);
            }
        }
    }
Пример #2
0
    public JsonData Combine(string atlasPath, Texture2D[] textureArr, string atlasName, List <string> picNameList)
    {
        InputKey = KeyCode.Alpha1;
        refreshRect();

        for (int texIndex = 0; texIndex < textureArr.Length; texIndex++)
        {
            Texture2D tex  = textureArr[texIndex];
            rectData  data = new rectData();
            data.key     = Helper.GetFileName(picNameList[texIndex], true);
            data.texture = tex;
            data.rect    = new Rect(0, 0, tex.width, tex.height);
            if (tex.width > tex.height && tex.width > 1024)
            {
                float sacal = 1f / ((float)tex.width / (float)1024);
                float w     = sacal * tex.width;
                float h     = tex.height * sacal;
                data.rect    = new Rect(0, 0, w, h);
                data.texture = ScaleTextureBilinear(tex, sacal);
            }
            if (tex.width < tex.height && tex.height > 1024)
            {
                float sacal = 1f / ((float)tex.height / (float)1024);
                float w     = sacal * tex.width;
                float h     = tex.height * sacal;
                data.rect    = new Rect(0, 0, w, h);
                data.texture = ScaleTextureBilinear(tex, sacal);
            }
            oriRect.Add(data);
        }
        List <rectData> rects = new List <rectData>();

        for (int j = 0, length = oriRect.Count; j < length; j++)
        {
            rects.Add(oriRect[j]);
        }
        key = 0;
        CopyOri(rects, atlasName);
        DrawCanvas(atlasPath, atlasName);

        return(SaveAtlas(atlasPath, atlasName));;
    }