Unity 合图插件 ==》【支持原图集更新】

前言:

项目需要,1.需提供给美术合图集工具,2.图集更新功能,使得新图集内的子图不必重新拖拽定位

解决思路:

1.unity调用外部TexturePacker命令行工具执行合图,unity根据TP生成的数据对图集切割出多个sprite

2.图集内的子图拖拽定位时,资源内产生对应的GUID及FileID。因此新图集更新对应的GUID与FileID即可,但是API没找到相应的接口,因此从资源本身下手通过txt方式打开,强制替换相应的ID

参考文档:

https://blog.csdn.net/pdw_jsp/article/details/83623150?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159900871219725264608797%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=159900871219725264608797&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v2~rank_blog_v1-4-83623150.pc_v2_rank_blog_v1&utm_term=TexturePacker+%E4%B8%80%E9%94%AE%E6%89%93%E5%8C%85&spm=1018.2118.3001.4187
 

https://www.xuanyusong.com/archives/4207

 

效果:

 

 

 

源码:

下面三个文件,放置于工程Assets\Editor即可

using System;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
using System.Text;
using System.Diagnostics;
using System.Linq;
using System.Xml;
using System.Collections;
using LuaFramework;

public class TexturePackerBuild : Editor
{
    private const string BuildDir = "Assets/TexturePacker/打包该图集";

    /// <summary>
    /// TexturePacker.exe ###https://www.codeandweb.com/texturepacker/documentation/texture-settings
    /// </summary>
    private const string Paramet = " --sheet {0}.png --data {1}.xml --format sparrow --trim-mode CropKeepPos --pack-mode Best --algorithm MaxRects --max-size 4096 --size-constraints POT --disable-rotation {2}";
    /// <summary>
    /// 输出目录
    /// </summary>
    private const string OutPutDirRoot = "Assets/TPSpriteBuild/";

    private static string tpDir = "";
    private static string argument = "";

    [MenuItem(BuildDir, false)]
    public static void BuildOneTP()
    {

        if (Directory.Exists(OutPutDirRoot) == false)
        {
            Directory.CreateDirectory(OutPutDirRoot);
        }

        var assetPaths = Selection.assetGUIDs.Select(AssetDatabase.GUIDToAssetPath).ToList();

        List<string> filePathList = new List<string>();
        foreach (var assetPath in assetPaths)
        {
            if (AssetDatabase.IsValidFolder(assetPath))
            {
                string[] filesPath = Directory.GetFiles(assetPath);
                foreach (var filePath in filesPath)
                {
                    if (filePathList.Contains(filePath) == false)
                    {
                        filePathList.Add(filePath);
                    }
                    else
                    {
                        UnityEngine.Debug.LogErrorFormat("检测到相同文件 {0}", assetPath);
                    }
                }
            }
            else
            {
                filePathList.Add(assetPath);
            }
        }

        Dictionary<string, FileData> fileDic = new Dictionary<string, FileData>();
        f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值