using System; using System.Diagnostics; using System.IO; using UnityEngine; namespace AibisDream.UI { internal static class DeveloperPathUtility { public static bool CanReveal { get { #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX return true; #else return false; #endif } } public static bool TryReveal(string path, bool createDirectory, out string error) { error = null; if (string.IsNullOrWhiteSpace(path)) { error = "路径为空。"; return false; } try { var fullPath = Path.GetFullPath(path); if (createDirectory && !File.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } if (!File.Exists(fullPath) && !Directory.Exists(fullPath)) { error = $"路径不存在:{fullPath}"; return false; } #if UNITY_EDITOR UnityEditor.EditorUtility.RevealInFinder(fullPath); return true; #elif UNITY_STANDALONE_WIN var isFile = File.Exists(fullPath); var startInfo = isFile ? new ProcessStartInfo("explorer.exe", $"/select,\"{fullPath}\"") : new ProcessStartInfo { FileName = fullPath, UseShellExecute = true }; Process.Start(startInfo); return true; #elif UNITY_STANDALONE_OSX Process.Start(File.Exists(fullPath) ? "open" : "open", File.Exists(fullPath) ? $"-R \"{fullPath}\"" : $"\"{fullPath}\""); return true; #elif UNITY_STANDALONE_LINUX var target = File.Exists(fullPath) ? Path.GetDirectoryName(fullPath) : fullPath; Process.Start("xdg-open", $"\"{target}\""); return true; #else error = "当前平台不支持直接打开文件管理器,请复制路径。"; return false; #endif } catch (Exception ex) { error = ex.Message; return false; } } } }