Vixen
02b45cc4
csharp
public sealed class CreateAssetMenuAttribute

Marks a static method as a line in Create ▸ and the starter file it writes.

Read the guide page for this →

As a annotation

Valid on
Method

Remarks

Doc 36 § D3, and F3's literal array read from the other end. The method takes nothing and returns the file's contents; the attribute names the line and the extension. Together they are a NewAssetKind, which is what the Create menu is built from.

[CreateAssetMenu("Dialogue Table", ".dialogue")] public static string NewTable() => "entries: []\n";

⚠ A method returning the contents, unlike Unity's attribute on a ScriptableObject class. Unity can put it on a type because a new asset there is a default instance serialised by a serializer that already knows the type. Ours is a file with an extension that an importer claims, and Contents's own remark is about the trap: an empty file is right for a kind whose editor opens one as a blank document, and wrong for a kind read by an importer, which deserialises it and puts a warning beside it instead of an asset. Making the author write the return value is what stops that being a default they never saw.

An author who wants the empty file writes return "";, and one who wants a serialised default calls the serializer in the body — which is a line of their code rather than a mechanism in ours.

⚠ Read by a scan of the assembly that declared it, and only for a plugin or a project script — see CustomInspectorAttribute for why that is bounded rather than the assembly scanning ADR-002 refuses. In-tree code registers a NewAssetKind directly, which is what the application's own kinds do.

Fields and properties (6)

  • public string Title

    What the menu line says.

  • public string Extension

    What the new file is called after the dot, including it.

  • public string DefaultName

    What it is called before the dot, or empty to use Title.

  • public bool Opens

    Whether to open it after creating it.

  • public string Id

    The command id, or empty to derive one from the title.

  • public int Order

    Where among the lines, low first.

Methods (1)

  • public CreateAssetMenuAttribute(string title, string extension)

    Marks a static method as a line in Create ▸ and the starter file it writes.

Used by (1)

  • DeclaredContributionsVixen.Editor.App