140 lines
5.8 KiB
C#
140 lines
5.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using Sirenix.OdinInspector;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni
|
|
{
|
|
public class ProjectLoader
|
|
{
|
|
public float fakeLoadPercent;
|
|
public float realLoadPercent;
|
|
public float displayLoadPercent => Mathf.Min(realLoadPercent, fakeLoadPercent);
|
|
|
|
public static readonly ES3Settings SaveSettings = new ES3Settings
|
|
{
|
|
compressionType = ES3.CompressionType.None,
|
|
encryptionType = ES3.EncryptionType.None,
|
|
format = ES3.Format.JSON,
|
|
location = ES3.Location.Resources
|
|
};
|
|
|
|
private static readonly ES3Settings LoadSettings = new ES3Settings
|
|
{
|
|
compressionType = ES3.CompressionType.Gzip,
|
|
encryptionType = ES3.EncryptionType.AES,
|
|
encryptionPassword = "Soullies515",
|
|
format = ES3.Format.JSON,
|
|
location = ES3.Location.Resources
|
|
};
|
|
|
|
public void TestLoad()
|
|
{
|
|
string beatMapFolderPath = "Beatmaps/" + InformationTransistor.instance.chapter.chapterIndex +
|
|
"/" + InformationTransistor.instance.song.songName +
|
|
"/" + InformationTransistor.instance.difficulty.difficultyName;
|
|
|
|
LoadProjectInfo(beatMapFolderPath);
|
|
LoadSongInfo(beatMapFolderPath);
|
|
LoadCommandScripts(beatMapFolderPath);
|
|
|
|
GameManager.instance.gameLoadingCanvas.MoveParts();
|
|
|
|
ThemeBundleManager.instance.LoadThemeBundles(GameManager.instance.projectInformation.selectedThemeBundleList);
|
|
realLoadPercent = 0f;
|
|
fakeLoadPercent = 0f;
|
|
|
|
Observable.EveryUpdate()
|
|
.Where(_ => ThemeBundleManager.instance.waitingBundleAmount.Value == 0 &&
|
|
GameManager.instance.gameLoadingCanvas.allPartsSet)
|
|
.First()
|
|
.Subscribe(_ =>
|
|
{
|
|
LoadBeatMap(beatMapFolderPath);
|
|
|
|
IDisposable fakeLoadObserver = Observable.EveryUpdate().Subscribe(_ =>
|
|
{
|
|
fakeLoadPercent += Time.deltaTime * 0.2f;
|
|
GameManager.instance.gameLoadingCanvas.SetProgress(displayLoadPercent * 100f);
|
|
});
|
|
|
|
Observable.EveryUpdate()
|
|
.Where(_ => ((BeatmapContainer_BM)GameManager.instance.beatmapContainer.matchedBM).remainingElementAmount.Value == 0 &&
|
|
fakeLoadPercent >= 1f)
|
|
.First()
|
|
.Subscribe(_ =>
|
|
{
|
|
fakeLoadObserver.Dispose();
|
|
|
|
Observable.Timer(TimeSpan.FromSeconds(1f)).First().Subscribe(_ =>
|
|
{
|
|
GameManager.instance.gameLoadingCanvas.FadeOut();
|
|
GameManager.instance.audioManager.isLoading = false;
|
|
|
|
GameManager.instance.beatmapContainer.gameElementList.ForEach(element => element.BeforeStart());
|
|
|
|
GameManager.instance.gameUICanvas.readyText.DOFade(1, 0.5f)
|
|
.SetLoops(4, LoopType.Yoyo).SetEase(Ease.InOutFlash).Play();
|
|
|
|
Observable.Timer(TimeSpan.FromSeconds(2)).First().Subscribe(_ =>
|
|
{
|
|
GameManager.instance.audioManager.isDelaying = true;
|
|
GameManager.instance.audioManager.isStarting = false;
|
|
Observable.NextFrame().Subscribe(_ =>
|
|
{
|
|
GameManager.instance.beatmapContainer.gameElementList.ForEach(element => element.WhenStart());
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
/*Observable.EveryUpdate()
|
|
.Where(_ => !GameManager.instance.audioManager.isStarting)
|
|
.First()
|
|
.Subscribe(_ =>
|
|
{
|
|
|
|
});*/
|
|
}
|
|
|
|
public void Load(string chapterName, string musicName, string difficultyName)
|
|
{
|
|
string beatMapFolderPath = "Beatmaps/" + chapterName + "/" + musicName + "/" + difficultyName;
|
|
|
|
LoadProjectInfo(beatMapFolderPath);
|
|
LoadSongInfo(beatMapFolderPath);
|
|
LoadCommandScripts(beatMapFolderPath);
|
|
LoadBeatMap(beatMapFolderPath);
|
|
}
|
|
|
|
private void LoadProjectInfo(string beatMapFolderPath)
|
|
{
|
|
string projectInfoPath = beatMapFolderPath + "/ProjectInfo.bytes";
|
|
ES3.Load<ProjectInformation_BM>("ProjectInformation", projectInfoPath, LoadSettings).ExecuteBM();
|
|
}
|
|
|
|
private void LoadSongInfo(string beatMapFolderPath)
|
|
{
|
|
string songInfoPath = beatMapFolderPath + "/SongInfo.bytes";
|
|
ES3.Load<SongInformation_BM>("SongInformation",songInfoPath, LoadSettings).ExecuteBM();
|
|
}
|
|
|
|
private void LoadBeatMap(string beatMapFolderPath)
|
|
{
|
|
string beatmapPath = beatMapFolderPath + "/Beatmap.bytes";
|
|
ES3.Load<BeatmapContainer_BM>("Beatmap", beatmapPath, LoadSettings).ExecuteBM();
|
|
}
|
|
|
|
private void LoadCommandScripts(string beatMapFolderPath)
|
|
{
|
|
string commandScriptsPath = beatMapFolderPath + "/CommandScripts.bytes";
|
|
ES3.Load<CommandScripts_BM>("CommandScripts", commandScriptsPath, LoadSettings).ExecuteBM();
|
|
}
|
|
|
|
}
|
|
} |