穴フェンス連動を改善
This commit is contained in:
parent
78854bc299
commit
267d496b00
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MyGame.Scenes.MiniGame.Scripts
|
namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
|
|
@ -11,8 +12,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
[SerializeField] private float bgOffset = 0f;
|
[SerializeField] private float bgOffset = 0f;
|
||||||
[SerializeField] private float holeWidth;
|
[SerializeField] private float holeWidth;
|
||||||
private int bgIndex = 0;
|
private int bgIndex = 0;
|
||||||
private float nextFenceXPos;
|
private readonly List<float> fencePosList = new();
|
||||||
private bool isFenceDone;
|
|
||||||
|
|
||||||
public void ResetBg(float targetXPos)
|
public void ResetBg(float targetXPos)
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +23,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
bg.SetPositionX(targetXPos + bgWidth / 2 + bgOffset + (i - 1) * bgWidth);
|
bg.SetPositionX(targetXPos + bgWidth / 2 + bgOffset + (i - 1) * bgWidth);
|
||||||
bg.GetComponent<BackGround>()?.ResetFence();
|
bg.GetComponent<BackGround>()?.ResetFence();
|
||||||
}
|
}
|
||||||
isFenceDone = true;
|
fencePosList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePos(float targetXPos)
|
public void UpdatePos(float targetXPos)
|
||||||
|
|
@ -37,29 +37,25 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
bg.GetComponent<BackGround>()?.ResetFence();
|
bg.GetComponent<BackGround>()?.ResetFence();
|
||||||
}
|
}
|
||||||
// フェンス確認
|
// フェンス確認
|
||||||
if (!isFenceDone && nextFenceXPos - targetXPos <= bgWidth)
|
if (fencePosList.Count > 0 && fencePosList[0] - targetXPos <= bgWidth)
|
||||||
{
|
{
|
||||||
isFenceDone = true;
|
SetFence(fencePosList[0]);
|
||||||
SetFence();
|
fencePosList.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFenceXPos(float targetXPos)
|
public void SetFenceXPos(float targetXPos) => fencePosList.Add(targetXPos);
|
||||||
{
|
|
||||||
nextFenceXPos = targetXPos;
|
|
||||||
isFenceDone = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetFence()
|
private void SetFence(float xPos)
|
||||||
{
|
{
|
||||||
foreach (var bg in bgArray)
|
foreach (var bg in bgArray)
|
||||||
{
|
{
|
||||||
var bgXPos = bg.transform.position.x;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
bg.GetComponent<BackGround>()?.SetFence(nextFenceXPos);
|
bg.GetComponent<BackGround>()?.SetFence(xPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UnityEngine;
|
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 stage = Instantiate(stagePrefabs[selectIndex], stageTarget.position + Vector3.left * 100f, Quaternion.identity, stageTarget);
|
||||||
var minPos = float.MaxValue;
|
var minPos = float.MaxValue;
|
||||||
var maxPos = float.MinValue;
|
var maxPos = float.MinValue;
|
||||||
var holePos = float.MinValue;
|
var holePosList = new List<float>();
|
||||||
stage.FindAllChildrensComponent<StageItem>(x =>
|
stage.FindAllChildrensComponent<StageItem>(x =>
|
||||||
{
|
{
|
||||||
var xPos = x.transform.position.x;
|
var xPos = x.transform.position.x;
|
||||||
minPos = Mathf.Min(minPos, xPos);
|
minPos = Mathf.Min(minPos, xPos);
|
||||||
maxPos = Mathf.Max(maxPos, 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 xPos = stage.position.x;
|
||||||
var minDiff = minPos - xPos;
|
var minDiff = minPos - xPos;
|
||||||
|
|
@ -75,10 +75,10 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
Destroy(stage.gameObject);
|
Destroy(stage.gameObject);
|
||||||
}).AddTo(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