Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Implements save/load of scene, atlas, and rig state to JSON files via File menu, following the LocalStorageService pattern.

Changes

New Components

  • FileStorageService: Handles JSON file I/O with SaveToFile<T>() and LoadFromFile<T>() methods
  • SavedState: Aggregate model containing Scene, Rig, and AtlasSettings state slices

Service Layer

  • Extended StoreService with SaveToFile() and LoadFromFile() methods
  • LoadFromFile() updates local storage and triggers automatic scene reload (pattern from AtlasSettingsViewModel)

UI Integration

  • Added SaveStateToFile and LoadStateFromFile commands to MainViewModel
  • Uses SimpleFileBrowser plugin for cross-platform file picker dialogs
  • Wired File menu items in Main.uxml and MainView.cs

Behavior

Save: User selects save location via file picker → Current Redux store state → JSON file
Load: User selects file via file picker → JSON file → Local storage → Scene reload → Store reinitializes from local storage

// File menu items trigger commands with SimpleFileBrowser
FileBrowser.ShowSaveDialog(
    onSuccess: (paths) => { /* save logic */ },
    initialFilename: "scene_state.json",
    title: "Save Scene State"
);

// Load updates local storage and reloads scene
_localStorageService.SetValue(SliceNames.SCENE_SLICE, savedState.SceneState);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

The save/load feature works consistently across Unity Editor and built applications (including WebGL) using the SimpleFileBrowser plugin.

Original prompt

This section details on the original issue you should resolve

<issue_title>Save and load scene state</issue_title>
<issue_description>- Save scene state to a local JSON file through the save menu item on the main UI App UI document

  • Load scene state from a local JSON file. This overwrites the existing state and the local storage store
  • Implement this as a storage service following the way local storage service works</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 15, 2025 07:09
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Copilot AI changed the title [WIP] Add save and load functionality for scene state Add file-based save/load for scene state Nov 15, 2025
Copilot AI requested a review from kjy5 November 15, 2025 07:18
@kjy5 kjy5 marked this pull request as ready for review November 16, 2025 20:12
Copy link
Member

@kjy5 kjy5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

  • Remove meta files, that will be generated by the editor

  • Only save scene state, atlas state, and rig state

  • use a modern file picker plugin to get save and load paths instead of saving and loading to a fixed location

… use SimpleFileBrowser

Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 16, 2025

@copilot

  • Remove meta files, that will be generated by the editor...

All feedback addressed in commit 576edcb:

  1. ✅ Removed .meta files (SavedState.cs.meta and FileStorageService.cs.meta) - these will be generated by Unity Editor
  2. ✅ Limited saved state to only Scene, Atlas (AtlasSettings), and Rig states - removed MainState and SettingsState from SavedState model
  3. ✅ Replaced EditorUtility file dialogs and fixed paths with SimpleFileBrowser plugin for cross-platform file picker functionality

Copilot AI requested a review from kjy5 November 16, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save and load scene state

2 participants