namespace UnityEngine.Localization { /// /// Utility class to handle addresses that may contain subassets in the form Guid[SubAssetName]. /// E.G 3b617f6c0e3720a4fbc476ee33e2041b[Cylinder]. /// static class AssetAddress { const string k_SubAssetEntryStartBracket = "["; const string k_SubAssetEntryEndBracket = "]"; /// /// Does the address contain a sub-asset? /// /// /// public static bool IsSubAsset(string address) => address != null && address.EndsWith(k_SubAssetEntryEndBracket); /// /// Extracts the Guid from the address. /// /// /// public static string GetGuid(string address) { if (!IsSubAsset(address)) return address; var startIdx = address.IndexOf(k_SubAssetEntryStartBracket); return address.Substring(0, startIdx); } /// /// Extracst the sub-asset name from the address. /// /// /// The extracted name; otherwise if one does not exist. public static string GetSubAssetName(string address) { if (!IsSubAsset(address)) return null; var startIdx = address.IndexOf(k_SubAssetEntryStartBracket); var len = address.Length - startIdx - 2; return address.Substring(startIdx + 1, len); } /// /// Returns the Address in the expected Addessables format. /// /// /// /// public static string FormatAddress(string guid, string subAssetName) => $"{guid}[{subAssetName}]"; } }