Unity动态创建FBX模型配置文件的存放路径

本文介绍了一个Unity编辑器脚本工具,该工具可以为选定的游戏模型自动创建或更新配置文件夹,并确保其遵循预设的目录结构。此工具通过获取模型路径及名称,创建对应的配置文件夹。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建前目录结构:

创建后的目录结构:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;

public class BuildTool
{
    [MenuItem("BuildTool/RefreshCloth/RefreshSelectClothConfig")]
    static void RefreshSelectCloth()
    {
        string configRootPath = "Assets/AssetData/ClothConfig";
        foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(GameObject), SelectionMode.DeepAssets))
        {
            //Assets/FBX/Character/Models/g_Cloth_50133/g_Cloth_50133.FBX
            string clothPath = AssetDatabase.GetAssetPath(o);

            //获得模型配置的名字,例子中即: g_Cloth_50133
            int subStart = clothPath.LastIndexOf('/') + 1;
            int subLenth = clothPath.LastIndexOf('.') - subStart;
            string clothConfigName = clothPath.Substring(subStart, subLenth);

            //获得模型配置的存放路径,例子中即: Assets/ZLgsTest/ClothConfig/g_Cloth_50133
            //注意是存放路径,而不是文件
            string clothConfigPath = configRootPath + "/" + clothConfigName;

            //如果以上路径不存在,则去创建一个
            if (!Directory.Exists(clothConfigPath))
                Directory.CreateDirectory(clothConfigPath);
        }

        AssetDatabase.Refresh();
    }
}

需要注意的是,在创建之前一定要先选中一个 模型资源!!!

转载于:https://www.cnblogs.com/luguoshuai/p/9148153.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值