private void SaveFile(bool otherName = false) { if (!OnFileSaving()) { return; } Debug.Assert(_currentAsset != null); if (_currentFileName == null || otherName) { var nameInput = new StringInputModalWindow(name => { if (!name.Contains(".")) { name += ".xml"; } _currentFileName = name; _currentAsset.Name = name; _currentAsset.Save(); _unsavedChanges = false; }, "File Path"); _toolsRoot.AddChild(nameInput); return; } // Unload the preset in the asset loader cache if loaded. This allows for changes to be observed on re-get. // This won't break anything as XMLAsset doesn't perform any cleanup. if (Engine.AssetLoader.Loaded(_currentFileName)) { Engine.AssetLoader.Destroy(_currentFileName); } _currentAsset.Save(); _unsavedChanges = false; }
public void AssetStorage() { var save = Engine.AssetLoader.Get <XMLAsset <TestStorage> >("saveFile.save"); Assert.True(save == null); var saveFilePath = "Player/saveFile.save"; XMLAsset <TestStorage> saveFile = XMLAsset <TestStorage> .LoadSaveOrCreate(saveFilePath); Assert.True(File.Exists(Path.Join(".", "Player", "savefile.save"))); Assert.True(Engine.AssetLoader.Exists(saveFilePath)); saveFile.Content.Text = "Wassaa"; saveFile.Save(); // It will now exist! save = Engine.AssetLoader.Get <XMLAsset <TestStorage> >("Player/saveFile.save"); Assert.Equal(save.Content.Text, saveFile.Content.Text); Engine.AssetLoader.Destroy(saveFilePath); saveFile.Save(); Assert.True(File.Exists(Path.Join("./Player", "savefile.save.backup"))); }