障害物アクション仮追加/デバッグ機能追加

This commit is contained in:
kimura 2022-06-21 14:42:21 +09:00
parent 564cad3c86
commit 786465ef76
3 changed files with 36 additions and 7 deletions

View File

@ -497,6 +497,8 @@ MonoBehaviour:
headerView: {fileID: 2098933370}
player: {fileID: 2498033716723453586}
stageManager: {fileID: 1870432536}
resultManager: {fileID: 0}
isDebug: 0
--- !u!4 &1870432534
Transform:
m_ObjectHideFlags: 0

View File

@ -1,6 +1,7 @@
using System;
using UniRx;
using UniRx.Triggers;
using UnityEditor;
using UnityEngine;
namespace MyGame.Scenes.MiniGame.Scripts
@ -24,6 +25,10 @@ namespace MyGame.Scenes.MiniGame.Scripts
[SerializeField] private HeaderView headerView;
[SerializeField] private Player player;
[SerializeField] private StageManager stageManager;
[SerializeField] private ResultManager resultManager;
#if UNITY_EDITOR
[SerializeField] private bool isDebug;
#endif
private readonly ReactiveProperty<MenuState> menuState = new ReactiveProperty<MenuState>();
private readonly ReactiveProperty<GameState> state = new ReactiveProperty<GameState>();
@ -55,7 +60,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
this.UpdateAsObservable()
.Where(_ => menuState.Value == MenuState.Game)
.Where(_ => Input.GetMouseButtonDown(0))
.Where(_ => Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
.Subscribe(_ =>
{
state.Value = GameState.Play;
@ -74,15 +79,17 @@ namespace MyGame.Scenes.MiniGame.Scripts
timerDisposable?.Dispose();
timerDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1f))
.Select(time => (int)(timeLimit - time))
.TakeWhile(time => time > 0)
.TakeWhile(time => time >= 0)
.Subscribe(time =>
{
headerView.ChangeTimeCount(time);
}, () =>
{
state.Value = GameState.Success;
}).AddTo(this);
break;
case GameState.Success:
resultManager.ShowResult();
break;
case GameState.Failure:
break;
@ -102,7 +109,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
player.Move();
// カメラ移動
cameraTransform.position = playerTransform.position.x * Vector3.right + cameraOffset;
if (Input.GetMouseButtonDown(0))
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
{
player.Jump();
}
@ -116,6 +123,17 @@ namespace MyGame.Scenes.MiniGame.Scripts
return;
}
x.enabled = false;
#if UNITY_EDITOR
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.GetComponent<MeshRenderer>().material.color = Color.red;
sphere.transform.SetLocalScale(.4f);
sphere.transform.position = x.ClosestPoint(playerTransform.position);
sphere.transform.SetPositionZ(-5f);
if (item.ItemType == StageItem.Type.Obstacle && isDebug)
{
EditorApplication.isPaused = true;
}
#endif
switch (item.ItemType)
{
case StageItem.Type.Item1:

View File

@ -1,6 +1,5 @@
using System;
using UniRx;
using UniRx.Diagnostics;
using UniRx.Triggers;
using UnityEngine;
@ -14,6 +13,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
[SerializeField] private float hitTime = 1.5f;
[SerializeField] private float hitWaitTime = 1f;
private bool isJump;
private bool isPreHit;
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty();
private IDisposable hitDisposable;
@ -33,7 +33,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
public void Jump()
{
if (isJump)
if (isJump || isPreHit)
{
return;
}
@ -52,18 +52,27 @@ namespace MyGame.Scenes.MiniGame.Scripts
// こける
public void Hit()
{
if (isPreHit)
{
return;
}
isPreHit = true;
hitDisposable?.Dispose();
// ジャンプが終わるのを待つ
hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Debug("Hit").Subscribe(_ =>
hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Subscribe(_ =>
{
var orgRotation = transform.localRotation;
var orgYAngle = orgRotation.eulerAngles.y;
transform.rotation = Quaternion.identity;
this.CallLerp(hitTime, t =>
{
// transform.SetLocalPositionY(cachePos.y + Mathf.Sin(Mathf.PI * t) * jumpHeight);
transform.localRotation = Quaternion.AngleAxis(orgYAngle + t * (3f * 360), Vector3.up);
}, () =>
{
isHit.Value = true;
this.CallWaitForSeconds(hitWaitTime, () =>
{
isPreHit = false;
isHit.Value = false;
});
});