DeleteUtilityWindow.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. namespace deleteUtility
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using UnityEditor;
  10. using UnityEngine;
  11. public class DeleteUtilityWindow : EditorWindow
  12. {
  13. #region Config
  14. protected DeleteUtility Instance;
  15. protected SerializedProperty Folder;
  16. protected SerializedObject SerializedObject;
  17. #endregion
  18. [MenuItem("DashGame/DeleteUtility")]
  19. protected static void ShowWindow()
  20. {
  21. Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
  22. DeleteUtilityWindow window = GetWindow<DeleteUtilityWindow>(inspectorType);
  23. window.titleContent = new GUIContent("DeleteUtility");
  24. window.Show();
  25. }
  26. private void OnEnable()
  27. {
  28. Instance = InstanceManager.SearchInstance<DeleteUtility>();
  29. SerializedObject = new SerializedObject(Instance);
  30. Folder = SerializedObject.FindProperty("Folder");
  31. }
  32. private void OnGUI()
  33. {
  34. SerializedObject.Update();
  35. EditorGUILayout.BeginHorizontal();
  36. EditorGUILayout.PropertyField(Folder, new GUIContent("Folder"));
  37. if (GUILayout.Button("UseSelectedPath", GUILayout.MaxWidth(120)))
  38. {
  39. GetSelectedPath(ref Instance.Folder);
  40. }
  41. EditorGUILayout.EndHorizontal();
  42. SerializedObject.ApplyModifiedProperties();
  43. }
  44. protected void GetSelectedPath(ref string value)
  45. {
  46. if (Selection.assetGUIDs.Length > 0)
  47. {
  48. string path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
  49. path = Path.GetDirectoryName(path);
  50. if (string.IsNullOrEmpty(path))
  51. {
  52. value = "Assets";
  53. }
  54. else
  55. {
  56. value = path;
  57. }
  58. }
  59. }
  60. }
  61. }