当前位置:   article > 正文

Unity Editor在多个不同文件夹下创建相同的子文件夹_unity怎么创建子文件夹

unity怎么创建子文件夹

如题,批量操作减少重复的操作。

  1. public class MyTools : EditorWindow
  2. {
  3. static Object[] objs;
  4. static MyTools window;
  5. static bool isCreateFolder = false;
  6. static string folderName;
  7. [MenuItem("Assets/批量创建子文件夹")]
  8. public static void CreateFolder()
  9. {
  10. window = (MyTools)GetWindow(typeof(MyTools));
  11. window.titleContent.text = "批量创建子文件夹";
  12. window.position = new Rect(PlayerSettings.defaultScreenWidth / 2, PlayerSettings.defaultScreenHeight / 2, 400, 120);
  13. window.Show();
  14. isCreateFolder = true;
  15. }
  16. private void OnGUI()
  17. {
  18. if (isCreateFolder)
  19. {
  20. GUILayout.BeginVertical();
  21. GUILayout.BeginHorizontal();
  22. GUILayout.Label("文件夹名称:", GUILayout.MinWidth(15));
  23. folderName = EditorGUILayout.TextField(folderName, GUILayout.ExpandWidth(true));
  24. GUILayout.EndHorizontal();
  25. GUILayout.BeginHorizontal();
  26. if (GUILayout.Button("确认"))
  27. {
  28. if (!string.IsNullOrEmpty(folderName))
  29. CreateAssignFolder();
  30. else
  31. Debug.LogError("请输入文件夹名称!");
  32. }
  33. GUILayout.Space(20);
  34. if (GUILayout.Button("取消"))
  35. {
  36. isCreateFolder = false;
  37. window.Close();
  38. }
  39. GUILayout.EndHorizontal();
  40. GUILayout.EndVertical();
  41. }
  42. }
  43. private void CreateAssignFolder()
  44. {
  45. Object[] arr = Selection.GetFiltered(typeof(Object), SelectionMode.TopLevel);
  46. string rootPath = "";
  47. StringBuilder subPath;
  48. for (int i = 0; i < arr.Length; i++)
  49. {
  50. subPath = new StringBuilder();
  51. rootPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')) + "/" + AssetDatabase.GetAssetPath(arr[i]);
  52. subPath.Append(rootPath).Append("/").Append(folderName).Append("/");
  53. if (!Directory.Exists(subPath.ToString()))
  54. {
  55. Directory.CreateDirectory(subPath.ToString());
  56. }
  57. else
  58. {
  59. Debug.LogError(subPath.ToString() + " exist!");
  60. }
  61. }
  62. AssetDatabase.Refresh();
  63. isCreateFolder = false;
  64. window.Close();
  65. }
  66. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/82012
推荐阅读
相关标签
  

闽ICP备14008679号