using System; namespace HotUpdate.UI { /// 编辑器生成与运行时加载共用的目录约定。 public static class UiAtlasPaths { public const string TextureRoot = "Assets/Bundles/UI/Texture"; public const string AtlasRoot = "Assets/Bundles/UI/Atlas"; public const string AtlasNamePrefix = "UI_"; public static bool IsTexturePath(string path) { return path != null && path.Replace('\\', '/').StartsWith(TextureRoot + "/", StringComparison.Ordinal); } public static string GetAtlasName(string relativeFolder) { if (relativeFolder == null) throw new ArgumentNullException(nameof(relativeFolder)); relativeFolder = relativeFolder.Replace('\\', '/').Trim('/'); if (relativeFolder.Length == 0) return AtlasNamePrefix + "__RootAtlas"; foreach (string segment in relativeFolder.Split('/')) if (segment.Length == 0 || segment == "." || segment == "..") throw new ArgumentException("Invalid UI texture folder: " + relativeFolder); // 转义下划线与路径分隔符,避免 A/B 与 A_B 生成同名图集。 return AtlasNamePrefix + relativeFolder.Replace("_", "_u").Replace("/", "_s") + "Atlas"; } public static string GetAtlasPath(string relativeFolder) { return AtlasRoot + "/" + GetAtlasName(relativeFolder) + ".spriteatlas"; } public static string GetAtlasPathForTexture(string texturePath) { texturePath = texturePath?.Replace('\\', '/'); if (!IsTexturePath(texturePath)) throw new ArgumentException("Not a UI texture: " + texturePath); int lastSlash = texturePath.LastIndexOf('/'); string folder = lastSlash == TextureRoot.Length ? "" : texturePath.Substring(TextureRoot.Length + 1, lastSlash - TextureRoot.Length - 1); return GetAtlasPath(folder); } } }