创建前目录结构:

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

创建后的目录结构:

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

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();
    }
}

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

相关文章:

  • 2021-10-22
  • 2021-12-08
  • 2021-06-22
  • 2021-11-17
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2022-01-25
  • 2021-07-19
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案