ステージ切り替え処理修正

This commit is contained in:
kimura 2022-07-29 11:53:05 +09:00
parent 7098490966
commit 92ca3c5e8f
1 changed files with 16 additions and 9 deletions

View File

@ -27,19 +27,14 @@ namespace MyGame.Scenes.MiniGame.Scripts
public IReadOnlyReactiveProperty<ScrollGameDifficulty> Difficulty => difficulty; public IReadOnlyReactiveProperty<ScrollGameDifficulty> Difficulty => difficulty;
private readonly ReactiveProperty<ScrollGameDifficulty> difficulty = new(); private readonly ReactiveProperty<ScrollGameDifficulty> difficulty = new();
private ScrollGameDifficulty generateStageDifficulty; private ScrollGameDifficulty generateStageDifficulty;
private IDisposable timerDisposable; private readonly CompositeDisposable changeDifficultyDisposable = new();
private readonly Dictionary<ScrollGameDifficulty, ScrollGameStageData> stageDataDict = new(); private readonly Dictionary<ScrollGameDifficulty, ScrollGameStageData> stageDataDict = new();
private void Start() private void Start()
{ {
fenceSubject.AddTo(this); fenceSubject.AddTo(this);
difficulty.AddTo(this); difficulty.AddTo(this);
difficulty.SkipLatestValueOnSubscribe().Subscribe(_ => changeDifficultyDisposable.AddTo(this);
{
// 難易度変更時にリソース開放
Resources.UnloadUnusedAssets();
Debug.Log($"change difficulty ({difficulty.Value}) and unload resources");
}).AddTo(this);
} }
@ -66,11 +61,20 @@ namespace MyGame.Scenes.MiniGame.Scripts
lengthIndex = 0; lengthIndex = 0;
beginIndex = 0; beginIndex = 0;
generateStageDifficulty = difficulty.Value; generateStageDifficulty = difficulty.Value;
changeDifficultyDisposable.Clear();
GenerateStage(); GenerateStage();
} }
private void GenerateStage() private void GenerateStage()
{ {
/*
* Length基準でまず
* LenghtIndexをつくって更に小さい単位GenerateCountに対応できるようにする
*
* prefabもつづつ読み込んだほうがいいっぽい
*
*
*/
// リソース読み込み // リソース読み込み
stageBeginPrefabList = stageDataDict[generateStageDifficulty].GetBeginStagePrefabs(); stageBeginPrefabList = stageDataDict[generateStageDifficulty].GetBeginStagePrefabs();
stageRandomPrefabList = stageDataDict[generateStageDifficulty].GetRandomStagePrefabs(); stageRandomPrefabList = stageDataDict[generateStageDifficulty].GetRandomStagePrefabs();
@ -89,6 +93,8 @@ namespace MyGame.Scenes.MiniGame.Scripts
stagePrefabs = stageBeginPrefabList[beginIndex..rangeEnd]; stagePrefabs = stageBeginPrefabList[beginIndex..rangeEnd];
beginIndex += stagePrefabs.Length; beginIndex += stagePrefabs.Length;
} }
Debug.Log($"stage {generateStageDifficulty} use begin {stagePrefabs.Length}");
var randomStageCount = stageCount - stagePrefabs.Length; var randomStageCount = stageCount - stagePrefabs.Length;
if (randomStageCount > 0) if (randomStageCount > 0)
{ {
@ -100,6 +106,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
randomStageCount -= count; randomStageCount -= count;
} }
} }
Debug.Log($"stage {generateStageDifficulty} use begin + random {stagePrefabs.Length}");
lengthIndex += stagePrefabs.Length; lengthIndex += stagePrefabs.Length;
@ -122,7 +129,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
// 落とし穴があった場合通知 // 落とし穴があった場合通知
stage.transform.FindAllChildrensComponent<StageItem>(x => stage.transform.FindAllChildrensComponent<StageItem>(x =>
{ {
if (x.ItemType != StageItem.Type.Hole) if (!x.gameObject.activeInHierarchy || x.ItemType != StageItem.Type.Hole)
{ {
return; return;
} }
@ -145,7 +152,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
.Subscribe(_ => { }, () => .Subscribe(_ => { }, () =>
{ {
difficulty.Value = NextDifficulty(difficulty.Value); difficulty.Value = NextDifficulty(difficulty.Value);
}).AddTo(this); }).AddTo(changeDifficultyDisposable);
} }
} }