using System; using System.IO; using UnityEngine; public static class AppRuntimesStreamingAssets { public static string GetPath(string relativePath) { if (string.IsNullOrWhiteSpace(relativePath)) throw new ArgumentException("A package-relative file path is required.", nameof(relativePath)); relativePath = relativePath.Replace('\\', '/'); if (relativePath.StartsWith("/", StringComparison.Ordinal) || relativePath.Contains(":") || Array.Exists(relativePath.Split('/'), part => part == ".." || part == "." || part.Length == 0)) throw new ArgumentException("Use a relative file path without parent directory segments.", nameof(relativePath)); #if UNITY_EDITOR var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(AppSettings).Assembly); if (package == null) throw new InvalidOperationException("AppRuntimes must be installed through Package Manager."); return Path.Combine(package.resolvedPath, "StreamingAssets~", relativePath).Replace('\\', '/'); #else return Application.streamingAssetsPath.TrimEnd('/') + "/" + relativePath; #endif } }