ステージ切り替え処理修正
This commit is contained in:
parent
7098490966
commit
92ca3c5e8f
|
|
@ -27,19 +27,14 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
public IReadOnlyReactiveProperty<ScrollGameDifficulty> Difficulty => difficulty;
|
||||
private readonly ReactiveProperty<ScrollGameDifficulty> difficulty = new();
|
||||
private ScrollGameDifficulty generateStageDifficulty;
|
||||
private IDisposable timerDisposable;
|
||||
private readonly CompositeDisposable changeDifficultyDisposable = new();
|
||||
private readonly Dictionary<ScrollGameDifficulty, ScrollGameStageData> stageDataDict = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
fenceSubject.AddTo(this);
|
||||
difficulty.AddTo(this);
|
||||
difficulty.SkipLatestValueOnSubscribe().Subscribe(_ =>
|
||||
{
|
||||
// 難易度変更時にリソース開放
|
||||
Resources.UnloadUnusedAssets();
|
||||
Debug.Log($"change difficulty ({difficulty.Value}) and unload resources");
|
||||
}).AddTo(this);
|
||||
changeDifficultyDisposable.AddTo(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -66,11 +61,20 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
lengthIndex = 0;
|
||||
beginIndex = 0;
|
||||
generateStageDifficulty = difficulty.Value;
|
||||
changeDifficultyDisposable.Clear();
|
||||
GenerateStage();
|
||||
}
|
||||
|
||||
private void GenerateStage()
|
||||
{
|
||||
/*
|
||||
* 生成はLength基準でまず
|
||||
* 拡張するならLenghtIndexをつくって更に小さい単位GenerateCountに対応できるようにする
|
||||
* 一気に読み込むのはしんどい
|
||||
* prefabも1つづつ読み込んだほうがいいっぽい
|
||||
* 次の難易度のリソースを1つづつ読み込むなどする
|
||||
* 読み込みリソースのオブジェクト数を減らす
|
||||
*/
|
||||
// リソース読み込み
|
||||
stageBeginPrefabList = stageDataDict[generateStageDifficulty].GetBeginStagePrefabs();
|
||||
stageRandomPrefabList = stageDataDict[generateStageDifficulty].GetRandomStagePrefabs();
|
||||
|
|
@ -89,6 +93,8 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
stagePrefabs = stageBeginPrefabList[beginIndex..rangeEnd];
|
||||
beginIndex += stagePrefabs.Length;
|
||||
}
|
||||
|
||||
Debug.Log($"stage {generateStageDifficulty} use begin {stagePrefabs.Length}");
|
||||
var randomStageCount = stageCount - stagePrefabs.Length;
|
||||
if (randomStageCount > 0)
|
||||
{
|
||||
|
|
@ -100,6 +106,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
randomStageCount -= count;
|
||||
}
|
||||
}
|
||||
Debug.Log($"stage {generateStageDifficulty} use begin + random {stagePrefabs.Length}");
|
||||
|
||||
lengthIndex += stagePrefabs.Length;
|
||||
|
||||
|
|
@ -122,7 +129,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
// 落とし穴があった場合通知
|
||||
stage.transform.FindAllChildrensComponent<StageItem>(x =>
|
||||
{
|
||||
if (x.ItemType != StageItem.Type.Hole)
|
||||
if (!x.gameObject.activeInHierarchy || x.ItemType != StageItem.Type.Hole)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -145,7 +152,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
.Subscribe(_ => { }, () =>
|
||||
{
|
||||
difficulty.Value = NextDifficulty(difficulty.Value);
|
||||
}).AddTo(this);
|
||||
}).AddTo(changeDifficultyDisposable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue