Vixen
feb85697
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 two ways: by a scan of the assembly that declared it, for a plugin or a project script — see CustomInspectorAttribute for why that is bounded rather than the assembly scanning ADR-002 refuses — and, in-tree, by the Declared.Register that Vixen.Editor.Plugin.Generator writes.

The line's words are a declaration when there is a catalogue (#1284), named the way EditorMenuAttribute.Title names one: Title = nameof(MyStrings.CreateTable), resolved in Strings or in the one *Strings class of the declaring assembly that declares it. A name that resolves to nothing is a compile error from the generator (VXP0003) and a refused plugin from the scan — never a silent literal. Without a Title the line says Text, which is right for a script with no catalogue.

Fields and properties (8)

  • public string Text

    What the menu line says when Title names no declaration.

  • public string Title

    The line's words, as the name of a StringId in a declaration class, or empty.

  • public Type? Strings

    The declaration class Title is in, when it is not this assembly's.

  • 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 Text.

  • public bool Opens

    Whether to open it after creating it.

  • public string Id

    The command id, or empty to derive one from Text.

  • public int Order

    Where among the lines, low first.

Methods (1)

  • public CreateAssetMenuAttribute(string text, string extension)

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

Used by (3)

  • DeclaredVixen.Editor.Terrain
  • DeclaredContributionsVixen.Editor.App
  • TerrainAssetKindsVixen.Editor.Terrain