OpenFolder.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using System.Diagnostics;
  9. using UnityEditor;
  10. using UnityEngine;
  11. namespace UnityGameFramework.Editor
  12. {
  13. /// <summary>
  14. /// 打开文件夹相关的实用函数。
  15. /// </summary>
  16. public static class OpenFolder
  17. {
  18. /// <summary>
  19. /// 打开 Data Path 文件夹。
  20. /// </summary>
  21. [MenuItem("Game Framework/Open Folder/Data Path", false, 10)]
  22. public static void OpenFolderDataPath()
  23. {
  24. Execute(Application.dataPath);
  25. }
  26. /// <summary>
  27. /// 打开 Persistent Data Path 文件夹。
  28. /// </summary>
  29. [MenuItem("Game Framework/Open Folder/Persistent Data Path", false, 11)]
  30. public static void OpenFolderPersistentDataPath()
  31. {
  32. Execute(Application.persistentDataPath);
  33. }
  34. /// <summary>
  35. /// 打开 Streaming Assets Path 文件夹。
  36. /// </summary>
  37. [MenuItem("Game Framework/Open Folder/Streaming Assets Path", false, 12)]
  38. public static void OpenFolderStreamingAssetsPath()
  39. {
  40. Execute(Application.streamingAssetsPath);
  41. }
  42. /// <summary>
  43. /// 打开 Temporary Cache Path 文件夹。
  44. /// </summary>
  45. [MenuItem("Game Framework/Open Folder/Temporary Cache Path", false, 13)]
  46. public static void OpenFolderTemporaryCachePath()
  47. {
  48. Execute(Application.temporaryCachePath);
  49. }
  50. #if UNITY_2018_3_OR_NEWER
  51. /// <summary>
  52. /// 打开 Console Log Path 文件夹。
  53. /// </summary>
  54. [MenuItem("Game Framework/Open Folder/Console Log Path", false, 14)]
  55. public static void OpenFolderConsoleLogPath()
  56. {
  57. Execute(System.IO.Path.GetDirectoryName(Application.consoleLogPath));
  58. }
  59. #endif
  60. /// <summary>
  61. /// 打开指定路径的文件夹。
  62. /// </summary>
  63. /// <param name="folder">要打开的文件夹的路径。</param>
  64. public static void Execute(string folder)
  65. {
  66. folder = Utility.Text.Format("\"{0}\"", folder);
  67. switch (Application.platform)
  68. {
  69. case RuntimePlatform.WindowsEditor:
  70. Process.Start("Explorer.exe", folder.Replace('/', '\\'));
  71. break;
  72. case RuntimePlatform.OSXEditor:
  73. Process.Start("open", folder);
  74. break;
  75. default:
  76. throw new GameFrameworkException(Utility.Text.Format("Not support open folder on '{0}' platform.", Application.platform.ToString()));
  77. }
  78. }
  79. }
  80. }