Skip to content

Commit

Permalink
PathUtility 拆分为独立文件
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKyaku committed Sep 20, 2023
1 parent 7577916 commit 33ba410
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ static void CreateBuildFolder()
{
List<string> list = new List<string>()
{
MeguminUtility4Unity.BuildPath_StandaloneOSX,
MeguminUtility4Unity.BuildPath_iOS,
MeguminUtility4Unity.BuildPath_Android_Mono,
MeguminUtility4Unity.BuildPath_Android_IL2CPP,
MeguminUtility4Unity.BuildPath_StandaloneWindows64_Mono,
MeguminUtility4Unity.BuildPath_StandaloneWindows64_IL2CPP,
MeguminUtility4Unity.BuildPath_StandaloneLinux64,
MeguminUtility4Unity.BuildPath_PS4,
MeguminUtility4Unity.BuildPath_PS5,
MeguminUtility4Unity.BuildPath_WebGL,
MeguminUtility4Unity.BuildPath_DedicatedServer,
MeguminUtility4Unity.BuildPath_activeBuildTarget,
PathUtility.BuildPath_StandaloneOSX,
PathUtility.BuildPath_iOS,
PathUtility.BuildPath_Android_Mono,
PathUtility.BuildPath_Android_IL2CPP,
PathUtility.BuildPath_StandaloneWindows64_Mono,
PathUtility.BuildPath_StandaloneWindows64_IL2CPP,
PathUtility.BuildPath_StandaloneLinux64,
PathUtility.BuildPath_PS4,
PathUtility.BuildPath_PS5,
PathUtility.BuildPath_WebGL,
PathUtility.BuildPath_DedicatedServer,
PathUtility.BuildPath_activeBuildTarget,
};

foreach (var dir in list)
Expand All @@ -57,13 +57,13 @@ static void CreateBuildFolder()
}

Debug.Log($"创建打包目录");
System.Diagnostics.Process.Start(MeguminUtility4Unity.BuildPath);
System.Diagnostics.Process.Start(PathUtility.BuildPath);
}

[MenuItem("Tools/Path/Open ConsoleLog Folder")]
static void OpenLogFolder()
{
var dir = MeguminUtility4Unity.ConsoleLogPath;
var dir = PathUtility.ConsoleLogPath;
Debug.Log($"打开 {dir}");
System.Diagnostics.Process.Start(dir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void ExportIconList()
generator.Push("");

//var path = @"W:\Git\Megumin.Explosion\Megumin.UnityPackage\Packages\megumin.explosion4unity\Editor\Scripts\EditorIcon\EditorIconList.cs";
var path = Path.Combine(MeguminUtility4Unity.PackagesPath,
var path = Path.Combine(PathUtility.PackagesPath,
@"megumin.explosion4unity\Editor\Scripts\EditorIcon\EditorIconList.cs");
path = Path.GetFullPath(path);
EditorUtility.DisplayProgressBar("Export", "WirteCodeToPath", 0.75f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void Move2LibraryFolder_clicked()
{
DirectoryInfo info = new DirectoryInfo(current.resolvedPath);
var foldername = info.Name;
var desPath = Path.Combine(MeguminUtility4Unity.LibraryPackageCachePath, foldername);
var desPath = Path.Combine(PathUtility.LibraryPackageCachePath, foldername);
Debug.Log(desPath);

if (Directory.Exists(desPath))
Expand All @@ -109,7 +109,7 @@ private void Move2PackagesFolder_clicked()
{
DirectoryInfo info = new DirectoryInfo(current.resolvedPath);
var foldername = info.Name;
var desPath = Path.Combine(MeguminUtility4Unity.PackagesPath, foldername);
var desPath = Path.Combine(PathUtility.PackagesPath, foldername);
Debug.Log(desPath);

if (Directory.Exists(desPath))
Expand Down Expand Up @@ -169,9 +169,9 @@ public void OnPackageSelectionChange(UnityEditor.PackageManager.PackageInfo pack
current = packageInfo;
//button.SetEnabled(false);
bool isGit = current?.source == UnityEditor.PackageManager.PackageSource.Git;
bool? isInLocal = current?.resolvedPath.StartsWith(MeguminUtility4Unity.PackagesPath);
bool? isInLocal = current?.resolvedPath.StartsWith(PathUtility.PackagesPath);
bool canMove2Local = !isInLocal ?? false;
bool? isInLibrary = current?.resolvedPath.StartsWith(MeguminUtility4Unity.LibraryPackageCachePath);
bool? isInLibrary = current?.resolvedPath.StartsWith(PathUtility.LibraryPackageCachePath);
bool canMove2Cache = !isInLibrary ?? false;

detail.text = $"[Git : {isGit}] [InLocalPackage : {isInLocal ?? false}] [InLiraryCache : {isInLibrary ?? false}]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void OnGUI()
NameExtension.OnGUI($"com.{Company.ToLower()}");
FolderName.OnGUI($"{NameExtension.ToString()?.ToLower()}.{InputPackageName.ToLower()}");

var path = Path.GetFullPath($"{MeguminUtility4Unity.PackagesPath}/{FolderName}");
var path = Path.GetFullPath($"{PathUtility.PackagesPath}/{FolderName}");

using (new EditorGUI.DisabledScope(!CreateRuntimeAsmdef))
{
Expand Down Expand Up @@ -221,7 +221,7 @@ void OnGUI()

private static void RefreshAsset()
{
var process = System.Diagnostics.Process.Start(MeguminUtility4Unity.PackagesPath);
var process = System.Diagnostics.Process.Start(PathUtility.PackagesPath);
}

private void CreatePackage(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ protected void DrawPPtrType(SerializedProperty property, GUIContent label, Rect
instance = ScriptableObject.CreateInstance(TName);
}

if (instancePath.StartsWith(MeguminUtility4Unity.ProjectPath))
if (instancePath.StartsWith(PathUtility.ProjectPath))
{
instancePath = instancePath.Replace(MeguminUtility4Unity.ProjectPath, "");
instancePath = instancePath.Replace(PathUtility.ProjectPath, "");
}

AssetDatabase.CreateAsset(instance, instancePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections;
#if !MEGUMIN_Common

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Megumin;
Expand Down Expand Up @@ -87,7 +89,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
{
//转换为相对路径。
var p1 = new System.Uri(pathResult);
var p2 = new System.Uri(MeguminUtility4Unity.ProjectPath);
var p2 = new System.Uri(PathUtility.ProjectPath);
var r = p2.MakeRelativeUri(p1);
pathResult = r.ToString();
}
Expand Down Expand Up @@ -123,4 +125,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

#endif

#endif


Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace Megumin
{
public static class PathUtility
{
public static string ProjectPath { get; } = GetProjectFolderPath("");
public static string PackagesPath { get; } = GetProjectFolderPath("Packages");
public static string LibraryPath { get; } = GetProjectFolderPath("Library");
public static string LibraryPackageCachePath { get; } = GetProjectFolderPath("Library/PackageCache");
public static string LogsPath { get; } = GetProjectFolderPath("Logs");
public static string TempPath { get; } = GetProjectFolderPath("Temp");
public static string UserSettingsPath { get; } = GetProjectFolderPath("UserSettings");

//BuildPath
public static string BuildPath { get; } = GetProjectFolderPath("Build");

public static string BuildPath_StandaloneOSX { get; } = GetProjectFolderPath("Build/StandaloneOSX");
public static string BuildPath_iOS { get; } = GetProjectFolderPath("Build/iOS");

public static string BuildPath_Android_Mono { get; } = GetProjectFolderPath("Build/Android_Mono");
public static string BuildPath_Android_IL2CPP { get; } = GetProjectFolderPath("Build/Android_IL2CPP");

public static string BuildPath_StandaloneWindows64_Mono { get; } = GetProjectFolderPath("Build/StandaloneWindows64_Mono");
public static string BuildPath_StandaloneWindows64_IL2CPP { get; } = GetProjectFolderPath("Build/StandaloneWindows64_IL2CPP");

public static string BuildPath_StandaloneLinux64 { get; } = GetProjectFolderPath("Build/StandaloneLinux64");

public static string BuildPath_PS4 { get; } = GetProjectFolderPath("Build/PS4");
public static string BuildPath_PS5 { get; } = GetProjectFolderPath("Build/PS5");

public static string BuildPath_WebGL { get; } = GetProjectFolderPath("Build/WebGL");

public static string BuildPath_DedicatedServer { get; } = GetProjectFolderPath("Build/DedicatedServer");

public static string BuildPath_activeBuildTarget { get; } = GetProjectFolderPath("Build/activeBuildTarget");

public static string ProjectSettingsPath { get; } = GetProjectFolderPath("ProjectSettings");
public static string ConsoleLogPath { get; } = Path.GetDirectoryName(Application.consoleLogPath);

public static string GetProjectFolderPath(string folder)
{
var path = Path.Combine(Application.dataPath, $"..\\{folder}");
return Path.GetFullPath(path);
}

/// <summary>
/// 转换为项目相对路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[Obsolete("use GetRelativePathWithProject")]
public static string MakeUnityProjectRelativePath(this string path)
{
var p1 = new System.Uri(path);
var p2 = new System.Uri(ProjectPath);
var r = p2.MakeRelativeUri(p1);
return r.ToString();
}

/// <summary>
/// 转换为项目相对路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string GetRelativePathWithProject(this string path)
{
var p1 = new System.Uri(path);
var p2 = new System.Uri(ProjectPath);
var r = p2.MakeRelativeUri(p1);
return r.ToString();
}

/// <summary>
/// 转换为项目绝对路径
/// </summary>
/// <param name="dir"></param>
/// <returns></returns>
public static string GetFullPathWithProject(this string path)
{
return Path.GetFullPath(Path.Combine(ProjectPath, path));
}
}

}




Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void CopyFile(string outputFolder, UnityEngine.Object file)
{
var path = file.GetAbsoluteFilePath();
path = Path.GetFullPath(path);
var des = Path.Combine(MeguminUtility4Unity.ProjectPath, outputFolder);
var des = Path.Combine(PathUtility.ProjectPath, outputFolder);
var fileName = Path.GetFileName(path);
des = Path.Combine(des, fileName);
des = Path.GetFullPath(des);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using Megumin;

/// <summary>
/// 为什么要包装一次,因为在PropertyDrawer里,有一些等同于异步的API没办法使用。
Expand All @@ -26,7 +27,7 @@ public static bool SelectPath(string selectkey, string orignalPath, bool display
{
if (display)
{
string dir = Path.Combine(MeguminUtility4Unity.ProjectPath, orignalPath);
string dir = Path.Combine(PathUtility.ProjectPath, orignalPath);
dir = Path.GetDirectoryName(dir);
dir = Path.GetFullPath(dir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public static string GetAbsoluteFilePath(this UnityEngine.Object @object)
//Debug.Log(mfp);
var fp = AssetDatabase.GetAssetPathFromTextMetaFilePath(mfp);
//Debug.Log(fp);
var gp = Path.Combine(MeguminUtility4Unity.ProjectPath, fp);
var gp = Path.Combine(PathUtility.ProjectPath, fp);
gp = Path.GetFullPath(gp);
//Debug.Log(gp);
return gp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Megumin;

#if UNITY_EDITOR
using UnityEditor;
Expand All @@ -14,57 +15,6 @@ namespace UnityEngine
{
public static class MeguminUtility4Unity
{
public static string ProjectPath { get; } = GetProjectFolderPath("");
public static string PackagesPath { get; } = GetProjectFolderPath("Packages");
public static string LibraryPath { get; } = GetProjectFolderPath("Library");
public static string LibraryPackageCachePath { get; } = GetProjectFolderPath("Library/PackageCache");
public static string LogsPath { get; } = GetProjectFolderPath("Logs");
public static string TempPath { get; } = GetProjectFolderPath("Temp");
public static string UserSettingsPath { get; } = GetProjectFolderPath("UserSettings");

//BuildPath
public static string BuildPath { get; } = GetProjectFolderPath("Build");

public static string BuildPath_StandaloneOSX { get; } = GetProjectFolderPath("Build/StandaloneOSX");
public static string BuildPath_iOS { get; } = GetProjectFolderPath("Build/iOS");

public static string BuildPath_Android_Mono { get; } = GetProjectFolderPath("Build/Android_Mono");
public static string BuildPath_Android_IL2CPP { get; } = GetProjectFolderPath("Build/Android_IL2CPP");

public static string BuildPath_StandaloneWindows64_Mono { get; } = GetProjectFolderPath("Build/StandaloneWindows64_Mono");
public static string BuildPath_StandaloneWindows64_IL2CPP { get; } = GetProjectFolderPath("Build/StandaloneWindows64_IL2CPP");

public static string BuildPath_StandaloneLinux64 { get; } = GetProjectFolderPath("Build/StandaloneLinux64");

public static string BuildPath_PS4 { get; } = GetProjectFolderPath("Build/PS4");
public static string BuildPath_PS5 { get; } = GetProjectFolderPath("Build/PS5");

public static string BuildPath_WebGL { get; } = GetProjectFolderPath("Build/WebGL");

public static string BuildPath_DedicatedServer { get; } = GetProjectFolderPath("Build/DedicatedServer");

public static string BuildPath_activeBuildTarget { get; } = GetProjectFolderPath("Build/activeBuildTarget");

public static string ProjectSettingsPath { get; } = GetProjectFolderPath("ProjectSettings");
public static string ConsoleLogPath { get; } = Path.GetDirectoryName(Application.consoleLogPath);

public static string GetProjectFolderPath(string folder)
{
var path = Path.Combine(Application.dataPath, $"..\\{folder}");
return Path.GetFullPath(path);
}

public static string MakeUnityProjectRelativePath(this string path)
{
//转换为相对路径。
var p1 = new System.Uri(path);
var p2 = new System.Uri(MeguminUtility4Unity.ProjectPath);
var r = p2.MakeRelativeUri(p1);
return r.ToString();
}

//=====================================

/// <summary>
/// 打印为实现代替抛出异常
/// </summary>
Expand Down Expand Up @@ -194,7 +144,7 @@ public static string GetUnityProjectLink(this Type type)
foreach (var item in se)
{
var link = item.Value.Document.Url;
var rpath = link.MakeUnityProjectRelativePath();
var rpath = link.GetRelativePathWithProject();
return (rpath, item.Value.StartLine);
}
}
Expand Down

0 comments on commit 33ba410

Please sign in to comment.