Class MenuDraft
One menu being authored in the Menu Manager wizard: a scratch UnityMenuSettingsDefinition
the author edits through the wizard's inspector GUIs before MenuCreator ever touches a
real asset. Mirrors CreateHudWindow's own scratch-instance pattern for a HUD element, composing
the generic Serenity.Global.Infrastructure.Editor.SerenityWizardScratchDraft<> mechanics for the scratch instance itself
and adding only what a menu draft needs beyond that: the planned asset file name and the guid-seeding
rules a menu's own transition wiring depends on.
Implements
Inherited Members
Namespace: Serenity.Menu.Infrastructure.Editor.Builder
Assembly: Serenity.UnityMenu.Infrastructure.Editor.dll
Syntax
public sealed class MenuDraft : IDisposable
Remarks
UnityEngine.HideFlags.DontSave rather than UnityEngine.HideFlags.HideAndDontSave is deliberate:
CreateHudWindow documents that the latter also carries NotEditable, which greys out every
field in an inspector GUI drawn against the instance — exactly what SerializedObject here
exists for.
Fields
AssetName
File name (without extension) the created or updated asset will use.
Declaration
public string AssetName
Field Value
| Type | Description |
|---|---|
| string |
Properties
BoundSourcePath
Where the menu this draft edits lives, or lived before the author deleted it; empty for a brand-new menu.
Declaration
public string BoundSourcePath { get; }
Property Value
| Type | Description |
|---|---|
| string |
Definition
The scratch definition the wizard edits.
Declaration
public UnityMenuSettingsDefinition Definition { get; }
Property Value
| Type | Description |
|---|---|
| UnityMenuSettingsDefinition |
SerializedObject
A SerializedObject over Definition for the wizard's inspector GUIs, created on first use.
Declaration
public SerializedObject SerializedObject { get; }
Property Value
| Type | Description |
|---|---|
| SerializedObject |
SourceAsset
The real asset this draft was loaded from, or null when the draft describes a brand-new menu. MenuCreator updates this asset in place instead of creating a new one when set.
Declaration
public UnityMenuSettingsDefinition SourceAsset { get; }
Property Value
| Type | Description |
|---|---|
| UnityMenuSettingsDefinition |
SourceAssetWasDeleted
True when the menu this draft was editing has since been deleted: the edits are kept and confirming creates the menu again.
Declaration
public bool SourceAssetWasDeleted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
ApplyTo(UnityMenuSettingsDefinition)
Commits every field on Definition onto target (a brand-new instance
for a create, SourceAsset for an update), preserving target's own
name and hide flags — see Serenity.Global.Infrastructure.Editor.SerenityWizardScratchDraft`1.ApplyTo(`0).
Declaration
public void ApplyTo(UnityMenuSettingsDefinition target)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityMenuSettingsDefinition | target | The real asset to write the draft's fields onto. |
CreateNew(string)
Starts a draft for a brand-new menu, seeded with defaultId.
Declaration
public static MenuDraft CreateNew(string defaultId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | defaultId | The id to seed the scratch definition and the asset name with. |
Returns
| Type | Description |
|---|---|
| MenuDraft |
Remarks
The seeded UnityMenuSettingsDefinition.Guid (via Serenity.Global.Infrastructure.Editor.SerenityWizardScratchDraft`1.EnsureIdentity(`0,`0),
target null so a fresh one is always assigned) is the key a sibling draft's transition option stores
in its Value.Guid, so a target survives the sibling's id being renamed later in the run —
MenuCreator writes that same draft Guid onto the asset, so what the sibling stored is
what lands on disk. Creating the same draft list twice would therefore yield two assets carrying one
guid — the wizard disposes its drafts when a run resets, so it never does.
Dispose()
Destroys the scratch instance. Safe to call more than once.
Declaration
public void Dispose()
FromExisting(UnityMenuSettingsDefinition)
Starts a draft loaded from an existing asset: every serialized field is copied onto the scratch instance, and SourceAsset keeps the reference so MenuCreator updates it in place rather than creating a new one. The asset's own guid is kept via Serenity.Global.Infrastructure.Editor.SerenityWizardScratchDraft`1.EnsureIdentity(`0,`0) — a sibling that already targets this menu on disk keeps resolving it — and only healed with a fresh one when the asset carries none.
Declaration
public static MenuDraft FromExisting(UnityMenuSettingsDefinition asset)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityMenuSettingsDefinition | asset | The existing menu asset to edit. |
Returns
| Type | Description |
|---|---|
| MenuDraft |