/// <summary> /// 编辑器下使用,给定一个类的对象,在这个类的同级目录下创建文件夹并返回路径 /// </summary> /// <typeparam name="T">类</typeparam> /// <param name="script">对象</param> /// <param name="subPath">指定要创建的文件夹的名称</param> /// <returns>文件夹的相对路径,相对于Assets文件夹</returns> public static string Creat <T>(T script, string subPath) where T : UnityEngine.Object //class { string newPath = ""; #if UNITY_EDITOR string path = ADB.FindAssets("t:Script") .Where(v => Path.GetFileNameWithoutExtension(ADB.GUIDToAssetPath(v)) == script.GetType().Name) .Select(id => ADB.GUIDToAssetPath(id)) .FirstOrDefault() .ToString(); newPath = Path.Combine(Path.GetDirectoryName(path), subPath); if (!ADB.IsValidFolder(newPath)) { newPath = ADB.GUIDToAssetPath(ADB.CreateFolder(path, subPath)); } #else return(newPath); #endif return(newPath); }
public static string CreatAssetPath <T>(this T script, string subPath) where T : UnityEngine.Object //class { if (null == script) { return(string.Empty); } string path = ADB.FindAssets("t:Script") .Where(v => Path.GetFileNameWithoutExtension(ADB.GUIDToAssetPath(v)) == script.GetType().Name) .Select(id => ADB.GUIDToAssetPath(id)) .FirstOrDefault() .ToString(); string newPath = Path.Combine(Path.GetDirectoryName(path), subPath); if (!ADB.IsValidFolder(newPath)) { newPath = ADB.GUIDToAssetPath(ADB.CreateFolder(path, subPath)); } return(newPath); }
private static void CreateScriptAsset(string templatePath, string destName) { if (Path.GetFileName(templatePath).ToLower().Contains("test")) { string str1 = AssetDatabase.GetUniquePathNameAtSelectedPath(destName); if (!str1.ToLower().Contains("/editor/")) { string str2 = str1.Substring(0, str1.Length - destName.Length - 1); string str3 = Path.Combine(str2, "Editor"); if (!Directory.Exists(str3)) { AssetDatabase.CreateFolder(str2, "Editor"); } str1 = Path.Combine(str3, destName).Replace("\\", "/"); } destName = str1; } string extension = Path.GetExtension(destName); Texture2D image; if (extension != null) { // ISSUE: reference to a compiler-generated field if (ProjectWindowUtil.\u003C\u003Ef__switch\u0024map1F == null) { // ISSUE: reference to a compiler-generated field ProjectWindowUtil.\u003C\u003Ef__switch\u0024map1F = new Dictionary <string, int>(4) { { ".js", 0 }, { ".cs", 1 }, { ".boo", 2 }, { ".shader", 3 } }; } int num; // ISSUE: reference to a compiler-generated field if (ProjectWindowUtil.\u003C\u003Ef__switch\u0024map1F.TryGetValue(extension, out num)) { switch (num) { case 0: image = EditorGUIUtility.IconContent("js Script Icon").image as Texture2D; goto label_16; case 1: image = EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D; goto label_16; case 2: image = EditorGUIUtility.IconContent("boo Script Icon").image as Texture2D; goto label_16; case 3: image = EditorGUIUtility.IconContent("Shader Icon").image as Texture2D; goto label_16; } } } image = EditorGUIUtility.IconContent("TextAsset Icon").image as Texture2D; label_16: ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, (EndNameEditAction)ScriptableObject.CreateInstance <DoCreateScriptAsset>(), destName, image, templatePath); }