using System; using Editor.Inspectors; namespace Editor; public interface IResourceEditor { /// /// The asset we're editing /// Asset Asset { get; } /// /// The resource contained within the asset /// Resource Resource { get; } /// /// The containing this editor. /// AssetInspector AssetInspector { get; } event Action Changed; void Initialize( Asset asset, Resource resource, AssetInspector parent ); void SavedToDisk(); void SelectMember( string memberName ); } /// /// Implement this with your target type to create a special inspector for the resource type /// public abstract class BaseResourceEditor : Widget, IResourceEditor where T : Resource { /// public Asset Asset { get; private set; } /// public T Resource { get; private set; } /// public AssetInspector AssetInspector { get; private set; } public event Action Changed; Resource IResourceEditor.Resource => Resource; /// /// Default constructor does nothing /// public BaseResourceEditor() : base( null ) { } void IResourceEditor.Initialize( Asset asset, Resource resource, AssetInspector parent ) { Asset = asset; Resource = (T)resource; AssetInspector = parent; Initialize( Asset, Resource ); } /// /// Override this to build your UI or whatever for this. Default behaviour is to /// create a property sheet and add it to y /// protected abstract void Initialize( Asset asset, T resource ); void IResourceEditor.SavedToDisk() => SavedToDisk(); protected virtual void SavedToDisk() { } protected void NoteChanged( SerializedProperty property = null ) { Changed?.Invoke( property ); } public virtual void SelectMember( string name ) { } }