Skip to content

Game.UI.Editor.SaveAssetPanel

Assembly: Assembly-CSharp (game)
Namespace: Game.UI.Editor

Type: public class SaveAssetPanel

Base: EditorPanelBase

Summary:
A modal/editor panel used to save assets from the in-game editor. It presents an AssetPicker (with favorites), a filename text input and Save/Cancel buttons. The panel uses an AssetPickerAdapter to present and track available asset items, allows an optional initial selection, and invokes a SaveCallback when the user confirms. The Save button is disabled while the filename is empty; its label can be overridden by supplying a LocalizedString. Internally the panel synchronizes the filename field with the selected asset and supports returning an optional overwrite GUID via the callback.


Fields

  • public delegate void SaveCallback(string name, Hash128? overwriteGuid)
    Defines the callback invoked when the user confirms a save. Receives the entered file name and an optional overwrite GUID from the currently selected asset (if any).

  • private SaveCallback m_ConfirmCallback
    Holds the callback supplied by the caller to be invoked on confirmation.

  • private AssetPickerAdapter m_Adapter
    Adapter used by the ItemPicker to show/select existing assets. The panel wires m_Adapter.EventItemSelected to update the filename when the user selects an existing item.

  • private string m_FileName
    The current filename entered/displayed in the StringInputField. Kept in sync with the adapter selection and user input.

Properties

  • None. This class does not expose any public properties; interaction is via constructor parameters and the SaveCallback.

Constructors

  • public SaveAssetPanel(LocalizedString panelTitle, IEnumerable<AssetItem> items, Hash128? initialSelected, SaveCallback onConfirm, Action onCancel, LocalizedString saveButtonLabel = default(LocalizedString))
    Creates and initializes the save panel.

Behavior/details: - Initializes an AssetPickerAdapter with the provided items and subscribes its EventItemSelected to the panel's selection handler. - If initialSelected has a value, selects that item in the adapter. - Initializes m_FileName from the currently selected item (if any) or empty string. - Sets up the panel children/widgets: - ItemPicker (with favorites) bound to m_Adapter. - ItemPickerFooter bound to m_Adapter. - StringInputField for the file name, using a DelegateAccessor that reads m_FileName and writes via OnNameChange. - A ButtonRow with two buttons: - Save: label equals saveButtonLabel if provided, otherwise localized "Editor.SAVE". Disabled when filename is empty. Action: OnConfirm. - Cancel: label "Common.CANCEL". Action: onCancel. - Stores onConfirm in m_ConfirmCallback for later invocation.

Methods

  • private void OnMapSelected(AssetItem item)
    Called when the user selects an item in the picker. If the selected item's fileName differs from the current m_FileName (case-insensitive), updates m_FileName to the selected fileName so the input field reflects the selection.

  • private void OnNameChange(string value)
    Called when the user edits the filename text field. Selects an item in the adapter by name (case-insensitive) if it matches, and updates m_FileName to the new value.

  • private void OnConfirm()
    Invokes the stored m_ConfirmCallback with the current m_FileName and the selected asset's GUID (if any). This is where the caller should perform the actual save/overwrite behavior.

Usage Example

// Example: create and show a SaveAssetPanel
LocalizedString title = (LocalizedString)"Editor.SAVE_ASSET";
IEnumerable<AssetItem> availableAssets = /* obtain list of AssetItem */;
Hash128? initial = null; // or some existing guid
var panel = new SaveAssetPanel(
    title,
    availableAssets,
    initial,
    (name, overwriteGuid) =>
    {
        // Save logic: create or overwrite asset with 'name'
        // If overwriteGuid.HasValue, replace that asset; otherwise create new
    },
    () =>
    {
        // Cancel handler: close panel or restore UI state
    },
    (LocalizedString)"Editor.SAVE" // optional custom save button label
);

// Add panel to UI manager / show it according to the game's UI framework
UIManager.ShowPanel(panel);