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
|
|
@ -64,12 +64,13 @@ namespace GameCult.Caching
|
|||
public float Max { get; }
|
||||
}
|
||||
|
||||
// A string member holding an engine asset path. AssetType is the engine's asset type, named by the consumer
|
||||
// (typeof(UnityEngine.Texture2D) in a Unity assembly); a lowering that does not know the type ignores it.
|
||||
// A string member holding an engine asset's stable identity; in Unity, the `.meta` GUID. AssetType is the
|
||||
// engine's asset type, named by the consumer (typeof(UnityEngine.Texture2D) in a Unity assembly); a lowering
|
||||
// that does not know the type ignores it.
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
|
||||
public sealed class CultInspectorAssetPathAttribute : Attribute
|
||||
public sealed class CultInspectorAssetGuidAttribute : Attribute
|
||||
{
|
||||
public CultInspectorAssetPathAttribute(Type? assetType = null)
|
||||
public CultInspectorAssetGuidAttribute(Type? assetType = null)
|
||||
{
|
||||
AssetType = assetType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace GameCult.Caching
|
|||
Order = Find<CultInspectorOrderAttribute>()?.Order;
|
||||
Range = Find<CultInspectorRangeAttribute>();
|
||||
TextArea = Find<CultInspectorTextAreaAttribute>();
|
||||
AssetPath = Find<CultInspectorAssetPathAttribute>();
|
||||
AssetGuid = Find<CultInspectorAssetGuidAttribute>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<Attribute> Attributes { get; }
|
||||
|
|
@ -53,7 +53,7 @@ namespace GameCult.Caching
|
|||
public int? Order { get; }
|
||||
public CultInspectorRangeAttribute? Range { get; }
|
||||
public CultInspectorTextAreaAttribute? TextArea { get; }
|
||||
public CultInspectorAssetPathAttribute? AssetPath { get; }
|
||||
public CultInspectorAssetGuidAttribute? AssetGuid { get; }
|
||||
|
||||
public T? Find<T>() where T : Attribute => Attributes.OfType<T>().FirstOrDefault();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue