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(); } }
需要注意的是,在创建之前一定要先选中一个 模型资源!!!