赞
踩
如题,批量操作减少重复的操作。
- public class MyTools : EditorWindow
- {
- static Object[] objs;
- static MyTools window;
- static bool isCreateFolder = false;
- static string folderName;
-
- [MenuItem("Assets/批量创建子文件夹")]
- public static void CreateFolder()
- {
- window = (MyTools)GetWindow(typeof(MyTools));
- window.titleContent.text = "批量创建子文件夹";
- window.position = new Rect(PlayerSettings.defaultScreenWidth / 2, PlayerSettings.defaultScreenHeight / 2, 400, 120);
- window.Show();
- isCreateFolder = true;
- }
-
- private void OnGUI()
- {
- if (isCreateFolder)
- {
- GUILayout.BeginVertical();
- GUILayout.BeginHorizontal();
- GUILayout.Label("文件夹名称:", GUILayout.MinWidth(15));
- folderName = EditorGUILayout.TextField(folderName, GUILayout.ExpandWidth(true));
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("确认"))
- {
- if (!string.IsNullOrEmpty(folderName))
- CreateAssignFolder();
- else
- Debug.LogError("请输入文件夹名称!");
- }
- GUILayout.Space(20);
- if (GUILayout.Button("取消"))
- {
- isCreateFolder = false;
- window.Close();
- }
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- }
- }
-
- private void CreateAssignFolder()
- {
- Object[] arr = Selection.GetFiltered(typeof(Object), SelectionMode.TopLevel);
- string rootPath = "";
- StringBuilder subPath;
- for (int i = 0; i < arr.Length; i++)
- {
- subPath = new StringBuilder();
- rootPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')) + "/" + AssetDatabase.GetAssetPath(arr[i]);
- subPath.Append(rootPath).Append("/").Append(folderName).Append("/");
- if (!Directory.Exists(subPath.ToString()))
- {
- Directory.CreateDirectory(subPath.ToString());
- }
- else
- {
- Debug.LogError(subPath.ToString() + " exist!");
- }
- }
- AssetDatabase.Refresh();
- isCreateFolder = false;
- window.Close();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。