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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue