Studio: read and write sub-asset Addressables keys, warn on stale values
Ruling S (2026-09-17): a stored [CultInspectorAssetGuid] value is the Addressables key form itself, the bare GUID for a main asset or "guid[subAssetName]" for a picked sub-asset (one sprite of a sheet, say) - the same shape AssetReference keeps and Addressables.LoadAssetAsync<T> accepts. CultAssetGuidKey (engine-free, GameCult.Caching) pins the parse/format rule with unit tests (bare guid, guid[name], names with brackets/spaces, malformed input), so headless checks can share it without touching Unity. The Studio drawer's AssetGuid branch now: resolves either key form on read; refuses to store a built-in resource's GUID (it has no Addressables entry) and logs why instead of silently writing nothing; shows a warning next to a stored value that fails to parse or resolve instead of drawing it as an ordinary empty field, and never rewrites that stale value on its own. Rebuilt GameCult.Caching/GameCult.Caching.MessagePack plugin DLLs (scripts/build-unity-package.ps1 -UpdateTemplate) since the new type ships in GameCult.Caching. Compiled CultCacheStudioDrawers.cs and CultCacheStudioWindow.cs against Unity 6000.3.24f1's editor reference set plus these plugins in a scratch csproj (removed after): 0 errors. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
0155ba8cca
commit
1e398e0116
9 changed files with 177 additions and 10 deletions
74
tests/GameCult.Caching.Tests/CultAssetGuidKeyTests.cs
Normal file
74
tests/GameCult.Caching.Tests/CultAssetGuidKeyTests.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#nullable enable
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GameCult.Caching.Tests
|
||||
{
|
||||
public class CultAssetGuidKeyTests
|
||||
{
|
||||
[Test]
|
||||
public void BareGuidParsesWithNoSubAsset()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.TryParse("0123456789abcdef0123456789abcdef", out var guid, out var sub), Is.True);
|
||||
Assert.That(guid, Is.EqualTo("0123456789abcdef0123456789abcdef"));
|
||||
Assert.That(sub, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GuidWithSubAssetNameParses()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.TryParse("abc123[Icon_Small]", out var guid, out var sub), Is.True);
|
||||
Assert.That(guid, Is.EqualTo("abc123"));
|
||||
Assert.That(sub, Is.EqualTo("Icon_Small"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SubAssetNameMayContainSpaces()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.TryParse("abc123[Icon Small Two]", out var guid, out var sub), Is.True);
|
||||
Assert.That(guid, Is.EqualTo("abc123"));
|
||||
Assert.That(sub, Is.EqualTo("Icon Small Two"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SubAssetNameMayContainBrackets()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.TryParse("abc123[Icon[2]]", out var guid, out var sub), Is.True);
|
||||
Assert.That(guid, Is.EqualTo("abc123"));
|
||||
Assert.That(sub, Is.EqualTo("Icon[2]"));
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
[TestCase("[name]")]
|
||||
[TestCase("abc123[")]
|
||||
[TestCase("abc123[name")]
|
||||
[TestCase("abc123]")]
|
||||
[TestCase("abc123[]")]
|
||||
public void MalformedInputDoesNotParse(string key)
|
||||
{
|
||||
var ok = CultAssetGuidKey.TryParse(key, out var guid, out var sub);
|
||||
if (key == "abc123]")
|
||||
{
|
||||
// No '[' at all: treated as a literal bare key, not a bracket form.
|
||||
Assert.That(ok, Is.True);
|
||||
Assert.That(guid, Is.EqualTo("abc123]"));
|
||||
Assert.That(sub, Is.Null);
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.That(ok, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormatRoundTripsBareGuid()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.Format("abc123", null), Is.EqualTo("abc123"));
|
||||
Assert.That(CultAssetGuidKey.Format("abc123", string.Empty), Is.EqualTo("abc123"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormatRoundTripsSubAsset()
|
||||
{
|
||||
Assert.That(CultAssetGuidKey.Format("abc123", "Icon_Small"), Is.EqualTo("abc123[Icon_Small]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue