Пример #1
0
    private static string GetFormatArgs(string inputFolder, string sheetName, string dataFileName, bool multiPack, ATLAS_TEXTUREFORMAT texFormat,
                                        ATLAS_FORMAT format, bool trimSpritesName,
                                        int maxSize, bool forceSq, bool forcePublish,
                                        ATLAS_PIXEL_OPT opt, float scale, ATLAS_SIZE_CONSTRAINTS sizeConstraints,
                                        bool disableAutoAlias, ATLAS_PACK_MODE packMode)
    {
        string args = string.Format(TEXTUREPACKER_ARGS, inputFolder, sheetName, texFormat, format, dataFileName,
                                    trimSpritesName ? "--trim-sprite-names" : "",
                                    maxSize,
                                    forceSq ? "--force-squared" : "",
                                    multiPack ? "--multipack" : "",
                                    forcePublish ? "--force-publish" : "",
                                    opt,
                                    scale,
                                    sizeConstraints,
                                    disableAutoAlias ? "--disable-auto-alias" : "",
                                    packMode
                                    );

        return(args);
    }
Пример #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="inputFolder">images in the folder need to be packed</param>
    /// <param name="sheetName"></param>
    /// <param name="dataFileName"></param>
    /// <param name="texFormat"></param>
    /// <param name="format"></param>
    /// <param name="trimSpritesName"></param>
    /// <param name="maxSize"></param>
    /// <param name="forceSq"></param>
    /// <param name="multiPack"></param>
    /// <param name="forcePublish">force republish even there no changes</param>
    /// <param name="opt"></param>
    /// <param name="scale"></param>
    /// <param name="sizeConstraints"></param>
    /// <param name="disableAutoAlias"></param>
    /// <param name="packMode"></param>
    private static void PackOneFolder(string inputFolder, string sheetName, string dataFileName, bool multiPack, string postFix, ATLAS_TEXTUREFORMAT texFormat,
                                      ATLAS_FORMAT format, bool trimSpritesName,
                                      int maxSize, bool forceSq, bool forcePublish,
                                      ATLAS_PIXEL_OPT opt, float scale, ATLAS_SIZE_CONSTRAINTS sizeConstraints,
                                      bool disableAutoAlias, ATLAS_PACK_MODE packMode)
    {
        if (!Directory.Exists(inputFolder))
        {
            Debug.LogError(string.Format("[TexturePacker]: {0} do not exist!", inputFolder));
            return;
        }

        if (!inputFolder.Contains("Assets"))
        {
            Debug.LogError(string.Format("[TextuePacker]: {0} images can not pack to atlas!", inputFolder));
            return;
        }

        string args;

        string[] returnResultAtlas;
        if (multiPack)
        {
            string assetPath = inputFolder.Substring(inputFolder.IndexOf("Assets"));
            CheckAllTextureSize(assetPath, maxSize);
            string folderPath = Path.GetFileName(sheetName);
            sheetName    += "/" + folderPath + "_{n}" + postFix + ".png";
            dataFileName += "/" + folderPath + "_{n}" + postFix + "_cfg.json";
            //format all args
            args = GetFormatArgs(inputFolder, sheetName, dataFileName, multiPack, texFormat, format,
                                 trimSpritesName,
                                 maxSize,
                                 forceSq,
                                 forcePublish,
                                 opt,
                                 scale,
                                 sizeConstraints,
                                 disableAutoAlias,
                                 packMode
                                 );
            returnResultAtlas = CallPackerProcess(args);
            AssetDatabase.Refresh();

            ProcessToSprite(returnResultAtlas, assetPath, false);
        }
        else
        {
            inputFolder = inputFolder.Substring(inputFolder.IndexOf("Assets"));
            string[] folder = { inputFolder };
            string[] guids  = AssetDatabase.FindAssets("t:texture2D", folder);
            foreach (string g in guids)
            {
                string p = AssetDatabase.GUIDToAssetPath(g);

                AssertTextureSize(p, maxSize);

                p = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + p;

                string newSheetName    = sheetName + "/" + System.IO.Path.GetFileNameWithoutExtension(p) + postFix + ".png";
                string newDataFileName = dataFileName + "/" + System.IO.Path.GetFileNameWithoutExtension(p) + postFix + "_cfg.json";

                args = GetFormatArgs(p, newSheetName, newDataFileName, multiPack, texFormat, format,
                                     trimSpritesName,
                                     maxSize,
                                     forceSq,
                                     forcePublish,
                                     opt,
                                     scale,
                                     sizeConstraints,
                                     disableAutoAlias,
                                     packMode
                                     );

                returnResultAtlas = CallPackerProcess(args);
                AssetDatabase.Refresh();

                ProcessToSprite(returnResultAtlas, Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(g)), true);
            }
        }
    }