自动保存Beatmap

This commit is contained in:
SoulliesOfficial
2025-03-01 21:26:16 -05:00
parent 6aba331079
commit 860d7393fb
12 changed files with 1640 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@@ -109,6 +109,8 @@ namespace Ichni.RhythmGame
noteVisual.effectSubmodule.effectCollection["Miss"].ForEach(e => e.UpdateEffect(exactJudgeTime)); noteVisual.effectSubmodule.effectCollection["Miss"].ForEach(e => e.UpdateEffect(exactJudgeTime));
break; break;
} }
noteScreenPosition = EditorManager.instance.cameraManager.gameCamera.camera.WorldToScreenPoint(noteVisual.transform.position);
} }
} }
@@ -146,6 +148,8 @@ namespace Ichni.RhythmGame
inspector.GenerateInputField(this, container, "exactJudgeTime", nameof(exactJudgeTime)); inspector.GenerateInputField(this, container, "exactJudgeTime", nameof(exactJudgeTime));
exactJudgeTimeInputField.AddListenerFunction(_ => UpdateNoteInTrack()); exactJudgeTimeInputField.AddListenerFunction(_ => UpdateNoteInTrack());
var noteScreenPositionText = inspector.GenerateHintText(this, container, () => "Note Screen Position: " + noteScreenPosition);
foreach (var submodule in submoduleList) foreach (var submodule in submoduleList)
{ {
submodule.SetUpInspector(); submodule.SetUpInspector();

View File

@@ -15,6 +15,8 @@ namespace Ichni
{ {
public static EditorManager instance; public static EditorManager instance;
public bool isLoaded;
public ProjectManager projectManager; public ProjectManager projectManager;
public MusicPlayer musicPlayer; public MusicPlayer musicPlayer;
public EditorUIManager uiManager; public EditorUIManager uiManager;
@@ -37,12 +39,13 @@ namespace Ichni
private void Awake() private void Awake()
{ {
instance = this; instance = this;
isLoaded = false;
projectManager = new ProjectManager(); projectManager = new ProjectManager();
operationManager = new OperationManager(); operationManager = new OperationManager();
if (!ES3.FileExists(Application.streamingAssetsPath + "/EditorSettings.es3")) if (!ES3.FileExists(Application.streamingAssetsPath + "/EditorSettings.es3"))
{ {
editorSettings = new EditorSettings(300, 100, 100); editorSettings = new EditorSettings(300, 3, 100, 100);
EditorSettings.SaveSettings(editorSettings); EditorSettings.SaveSettings(editorSettings);
} }
else else
@@ -57,22 +60,25 @@ namespace Ichni
this.elementGuid = Guid.Empty; this.elementGuid = Guid.Empty;
uiManager.hierarchy.GenerateTab(this, null); uiManager.hierarchy.GenerateTab(this, null);
StartCoroutine(DelayLoading()); StartCoroutine(DelayLoading());
} }
private void Update()
{
if(isLoaded) projectManager.autoSaveManager.UpdateAutoSave();
}
public IEnumerator DelayLoading() public IEnumerator DelayLoading()
{ {
StartCoroutine(projectManager.loadManager.Load("TestProject")); StartCoroutine(projectManager.loadManager.Load("TestProject"));
musicPlayer.audioSource.clip = songInformation.song; musicPlayer.audioSource.clip = songInformation.song;
yield return new WaitForSeconds(2);//什么时候能加个loading界面 yield return new WaitForSeconds(1);//什么时候能加个loading界面
beatmapContainer.gameElementList.ForEach(gameElement => beatmapContainer.gameElementList.ForEach(gameElement =>
{ {
gameElement.AfterInitialize(); gameElement.AfterInitialize();
gameElement.Refresh(); gameElement.Refresh();
}); });
isLoaded = true;
} }
public override void SetUpInspector() public override void SetUpInspector()
{ {

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO;
using Ichni.Editor; using Ichni.Editor;
using Ichni.RhythmGame; using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap; using Ichni.RhythmGame.Beatmap;
@@ -30,6 +31,7 @@ namespace Ichni
public LoadManager loadManager; public LoadManager loadManager;
public ExportManager exportManager; public ExportManager exportManager;
public BeatmapClipManager beatmapClipManager; public BeatmapClipManager beatmapClipManager;
public AutoSaveManager autoSaveManager;
public ProjectManager() public ProjectManager()
{ {
@@ -37,6 +39,7 @@ namespace Ichni
loadManager = new LoadManager(); loadManager = new LoadManager();
exportManager = new ExportManager(); exportManager = new ExportManager();
beatmapClipManager = new BeatmapClipManager(); beatmapClipManager = new BeatmapClipManager();
autoSaveManager = new AutoSaveManager();
} }
public void GenerateProject(string projectName) public void GenerateProject(string projectName)
@@ -286,4 +289,77 @@ namespace Ichni
clip.ForEach(e => e.ExecuteBM()); clip.ForEach(e => e.ExecuteBM());
} }
} }
public class AutoSaveManager
{
private string autoSavePath => Application.streamingAssetsPath + "/AutoSave/" +
EditorManager.instance.projectInformation.projectName;
private string GetAutoSavePath(string autoSaveName) => autoSavePath + "/" + autoSaveName + ".json";
private float autoSaveInterval => EditorManager.instance.editorSettings.autoSaveInterval;
private int maximumAutoSaveCount => EditorManager.instance.editorSettings.maximumAutoSaveCount;
public float autoSaveTimer;
public AutoSaveManager()
{
autoSaveTimer = 0;
}
public void UpdateAutoSave()
{
autoSaveTimer += Time.deltaTime;
if (autoSaveTimer >= autoSaveInterval)
{
AutoSave();
autoSaveTimer = 0;
}
}
private void AutoSave()
{
List<string> saveFiles = GetSortedSaveFiles();
if (saveFiles.Count > 0)
{
// 删除最旧的存档(如果超过数量)
if (saveFiles.Count >= maximumAutoSaveCount)
{
string oldestSave = saveFiles[saveFiles.Count - 1];
File.Delete(oldestSave);
saveFiles.RemoveAt(saveFiles.Count - 1);
}
// 依次重命名存档
for (int i = saveFiles.Count - 1; i >= 0; i--)
{
string oldPath = saveFiles[i];
string newPath = GetAutoSavePath($"AutoSave_{i + 1}");
File.Move(oldPath, newPath);
}
}
// 保存最新存档
string newestSavePath = GetAutoSavePath("AutoSave_0");
SaveBeatMap(newestSavePath);
}
private void SaveBeatMap(string autoSavePath)
{
EditorManager.instance.beatmapContainer.SaveBM();
ES3.Save("BeatMap", EditorManager.instance.beatmapContainer.matchedBM as BeatmapContainer_BM,
autoSavePath, ProjectManager.SaveSettings);
}
private List<string> GetSortedSaveFiles()
{
if(!ES3.DirectoryExists(autoSavePath))
{
Directory.CreateDirectory(autoSavePath);
}
List<string> saveFiles = new List<string>(Directory.GetFiles(autoSavePath, "AutoSave_*.es3"));
saveFiles.Sort(string.Compare);
return saveFiles;
}
}
} }

View File

@@ -9,12 +9,14 @@ namespace Ichni.Editor
public class EditorSettings public class EditorSettings
{ {
public int autoSaveInterval = 300; public int autoSaveInterval = 300;
public int maximumAutoSaveCount = 3;
public int musicVolume = 100; public int musicVolume = 100;
public int soundFXVolume = 100; public int soundFXVolume = 100;
public EditorSettings(int autoSaveInterval, int musicVolume, int soundFXVolume) public EditorSettings(int autoSaveInterval, int maximumAutoSaveCount, int musicVolume, int soundFXVolume)
{ {
this.autoSaveInterval = autoSaveInterval; this.autoSaveInterval = autoSaveInterval;
this.maximumAutoSaveCount = maximumAutoSaveCount;
this.musicVolume = musicVolume; this.musicVolume = musicVolume;
this.soundFXVolume = soundFXVolume; this.soundFXVolume = soundFXVolume;
} }

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a67c799c4f674b288fab2d57759b4fb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8403371c2481d4e37a563d372f2be857
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 07260670e384a482488fa056cb714307
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.