CubismUnityEditorUtility.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using System.IO;
  2. using UnityEditor;
  3. namespace Live2D.Cubism.Editor
  4. {
  5. public class CubismUnityEditorUtility
  6. {
  7. /// <summary>
  8. /// Projectウィンドウで現在選択しているディレクトリのパスを取得。
  9. /// Projectウィンドウ以外が選択されていたり、何も選択されていない場合、返す値はAssets直下。
  10. /// </summary>
  11. /// <returns>Projectウィンドウで現在のディレクトリのパス</returns>
  12. public static string GetCurrentDirectoryPath()
  13. {
  14. var activeObject = Selection.activeObject;
  15. var currentDirectoryPath = ((activeObject == null)
  16. ? "Assets"
  17. : AssetDatabase.GetAssetPath(activeObject.GetInstanceID()));
  18. if (string.IsNullOrEmpty(currentDirectoryPath))
  19. {
  20. currentDirectoryPath = "Assets";
  21. }
  22. else if (!Directory.Exists(currentDirectoryPath))
  23. {
  24. currentDirectoryPath = currentDirectoryPath.Replace("/" + Path.GetFileName(currentDirectoryPath), "");
  25. }
  26. return currentDirectoryPath;
  27. }
  28. }
  29. }