Replace the asset path attribute with a stable GUID identity
CultInspectorAssetPathAttribute stored an engine asset path, which breaks when the asset moves. CultInspectorAssetGuidAttribute stores the asset's stable identity (in Unity, the .meta GUID) instead. The Studio drawer now resolves the stored GUID to a path only to load the preview object, and writes back AssetPathToGUID on a change. No path form survives for the next field to pick up. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
244154e2f5
commit
95a3c32250
5 changed files with 34 additions and 14 deletions
|
|
@ -167,12 +167,13 @@ namespace GameCult.Unity.Caching.Editor
|
|||
|
||||
private static string DrawString(string label, string value, CultInspectorMetadata metadata)
|
||||
{
|
||||
if (metadata.AssetPath != null)
|
||||
if (metadata.AssetGuid != null)
|
||||
{
|
||||
var assetType = metadata.AssetPath.AssetType != null && typeof(Object).IsAssignableFrom(metadata.AssetPath.AssetType) ? metadata.AssetPath.AssetType : typeof(Object);
|
||||
var asset = string.IsNullOrEmpty(value) ? null : AssetDatabase.LoadAssetAtPath(value, assetType);
|
||||
var assetType = metadata.AssetGuid.AssetType != null && typeof(Object).IsAssignableFrom(metadata.AssetGuid.AssetType) ? metadata.AssetGuid.AssetType : typeof(Object);
|
||||
var path = string.IsNullOrEmpty(value) ? string.Empty : AssetDatabase.GUIDToAssetPath(value);
|
||||
var asset = string.IsNullOrEmpty(path) ? null : AssetDatabase.LoadAssetAtPath(path, assetType);
|
||||
var next = EditorGUILayout.ObjectField(label, asset, assetType, false);
|
||||
return next == asset ? value : next == null ? string.Empty : AssetDatabase.GetAssetPath(next);
|
||||
return next == asset ? value : next == null ? string.Empty : AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(next));
|
||||
}
|
||||
|
||||
var textArea = metadata.TextArea;
|
||||
|
|
|
|||
|
|
@ -150,8 +150,8 @@ public sealed class ItemData
|
|||
public string Notes = string.Empty;
|
||||
|
||||
[Key(3)]
|
||||
[CultInspectorAssetPath]
|
||||
public string IconPath = string.Empty;
|
||||
[CultInspectorAssetGuid]
|
||||
public string IconGuid = string.Empty;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -161,8 +161,9 @@ public sealed class ItemData
|
|||
- `CultInspectorOrder`
|
||||
- `CultInspectorTextArea`
|
||||
- `CultInspectorRange`
|
||||
- `CultInspectorAssetPath` (optional engine asset `Type`, named by the
|
||||
consumer; the Studio uses it when it is a `UnityEngine.Object` type)
|
||||
- `CultInspectorAssetGuid` (a string member holding an engine asset's stable
|
||||
identity, in Unity the `.meta` GUID; optional engine asset `Type`, named by
|
||||
the consumer; the Studio uses it when it is a `UnityEngine.Object` type)
|
||||
- `CultInspectorDrawer` (on drawer classes)
|
||||
|
||||
CultMesh collaboration should feed the same CultCache mutation surface rather
|
||||
|
|
|
|||
Loading…
Reference in a new issue