LocationManagerEditor.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. [CanEditMultipleObjects]
  7. [CustomEditor(typeof(LocationManager))]
  8. public class LocationManagerEditor : Editor
  9. {
  10. public override void OnInspectorGUI()
  11. {
  12. LocationManager myMenusController = target as LocationManager;
  13. base.OnInspectorGUI();
  14. EditorGUILayout.Space();
  15. EditorGUILayout.LabelField("Tools:", EditorStyles.boldLabel);
  16. if (GUILayout.Button("Update All Locations)"))
  17. {
  18. Undo.RecordObject(myMenusController, "Update All Menus");
  19. myMenusController.locations = GettAllMenus();
  20. }
  21. }
  22. string[] GettAllMenus()
  23. {
  24. string[] allNames = Directory.GetFiles("Assets/Prefab/Locations", "*.prefab", SearchOption.AllDirectories);
  25. for (int i = 0; i < allNames.Length; i++)
  26. {
  27. allNames[i] = Path.GetFileName(allNames[i]);
  28. allNames[i] = allNames[i].Remove(allNames[i].Length - 7);
  29. }
  30. return allNames;
  31. }
  32. }