From 267d496b00db6fa1f56549e673a962dfa9713d82 Mon Sep 17 00:00:00 2001 From: kimura Date: Tue, 26 Jul 2022 09:39:39 +0900 Subject: [PATCH] =?UTF-8?q?=E7=A9=B4=E3=83=95=E3=82=A7=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E9=80=A3=E5=8B=95=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/MiniGame/Scripts/BGManager.cs | 24 ++++++++----------- .../Scenes/MiniGame/Scripts/StageManager.cs | 14 +++++------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/BGManager.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/BGManager.cs index 8013c3a5..2bb01e4e 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/BGManager.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/BGManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine; namespace MyGame.Scenes.MiniGame.Scripts @@ -11,8 +12,7 @@ namespace MyGame.Scenes.MiniGame.Scripts [SerializeField] private float bgOffset = 0f; [SerializeField] private float holeWidth; private int bgIndex = 0; - private float nextFenceXPos; - private bool isFenceDone; + private readonly List fencePosList = new(); public void ResetBg(float targetXPos) { @@ -23,7 +23,7 @@ namespace MyGame.Scenes.MiniGame.Scripts bg.SetPositionX(targetXPos + bgWidth / 2 + bgOffset + (i - 1) * bgWidth); bg.GetComponent()?.ResetFence(); } - isFenceDone = true; + fencePosList.Clear(); } public void UpdatePos(float targetXPos) @@ -37,29 +37,25 @@ namespace MyGame.Scenes.MiniGame.Scripts bg.GetComponent()?.ResetFence(); } // フェンス確認 - if (!isFenceDone && nextFenceXPos - targetXPos <= bgWidth) + if (fencePosList.Count > 0 && fencePosList[0] - targetXPos <= bgWidth) { - isFenceDone = true; - SetFence(); + SetFence(fencePosList[0]); + fencePosList.RemoveAt(0); } } - public void SetFenceXPos(float targetXPos) - { - nextFenceXPos = targetXPos; - isFenceDone = false; - } + public void SetFenceXPos(float targetXPos) => fencePosList.Add(targetXPos); - private void SetFence() + private void SetFence(float xPos) { foreach (var bg in bgArray) { var bgXPos = bg.transform.position.x; - if (nextFenceXPos < bgXPos - bgWidth / 2 || bgXPos + bgWidth / 2 < nextFenceXPos) + if (xPos < bgXPos - bgWidth / 2 || bgXPos + bgWidth / 2 < xPos) { continue; } - bg.GetComponent()?.SetFence(nextFenceXPos); + bg.GetComponent()?.SetFence(xPos); } } diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/StageManager.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/StageManager.cs index 85bbb20e..3fc76284 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/StageManager.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/StageManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UniRx; using UnityEngine; @@ -48,17 +49,16 @@ namespace MyGame.Scenes.MiniGame.Scripts var stage = Instantiate(stagePrefabs[selectIndex], stageTarget.position + Vector3.left * 100f, Quaternion.identity, stageTarget); var minPos = float.MaxValue; var maxPos = float.MinValue; - var holePos = float.MinValue; + var holePosList = new List(); stage.FindAllChildrensComponent(x => { var xPos = x.transform.position.x; minPos = Mathf.Min(minPos, xPos); maxPos = Mathf.Max(maxPos, xPos); - if (x.ItemType != StageItem.Type.Hole) + if (x.ItemType == StageItem.Type.Hole) { - return; + holePosList.Add(xPos); } - holePos = xPos; }); var xPos = stage.position.x; var minDiff = minPos - xPos; @@ -75,10 +75,10 @@ namespace MyGame.Scenes.MiniGame.Scripts Destroy(stage.gameObject); }).AddTo(stage.gameObject); // 落とし穴があった場合通知 - if (holePos > float.MinValue) + holePosList.ToObservable().DelayFrame(1).Subscribe(x => { - Observable.NextFrame().Subscribe(_ => fenceSubject.OnNext(stage.position.x + holePos - xPos)).AddTo(this); - } + fenceSubject.OnNext(stage.position.x + x - xPos); + }).AddTo(this); } }