穴フェンス連動を改善
This commit is contained in:
parent
78854bc299
commit
267d496b00
|
|
@ -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<float> 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<BackGround>()?.ResetFence();
|
||||
}
|
||||
isFenceDone = true;
|
||||
fencePosList.Clear();
|
||||
}
|
||||
|
||||
public void UpdatePos(float targetXPos)
|
||||
|
|
@ -37,29 +37,25 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
|||
bg.GetComponent<BackGround>()?.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<BackGround>()?.SetFence(nextFenceXPos);
|
||||
bg.GetComponent<BackGround>()?.SetFence(xPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<float>();
|
||||
stage.FindAllChildrensComponent<StageItem>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue