add miniGame

This commit is contained in:
kimura 2022-06-14 09:52:00 +09:00
parent 146e2c7e2a
commit 9c171e2db1
10 changed files with 5064 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cc3a591a3c4ca4b07876ee989ddf10dc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c21a0a611342d4e4b90e83df43aa3e5e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4140d30c512de44bca2d70f1ac818a1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,117 @@
using System;
using UniRx;
using UniRx.Diagnostics;
using UniRx.Triggers;
using UnityEngine;
namespace MyGame.Scenes.MiniGame.Scripts
{
public class GameManager : MonoBehaviour
{
public enum State
{
Ready,
Play,
Success,
Failure
}
[SerializeField] private float speed = 1f;
[SerializeField] private float jumpTime = .8f;
[SerializeField] private float jumpHeight = 2f;
[SerializeField] private HeaderView headerView;
[SerializeField] private Transform characterTransform;
private readonly ReactiveProperty<State> state = new ReactiveProperty<State>();
// Start is called before the first frame update
private void Start()
{
state.AddTo(this);
state.Value = State.Ready;
this.UpdateAsObservable()
.Where(_ => Input.GetMouseButtonDown(0))
// .Debug("tap")
.Subscribe(_ =>
{
ChangeState();
}).AddTo(this);
var cameraTransform = Camera.main.transform;
this.UpdateAsObservable()
.Where(_ => state.Value == State.Play)
.DelayFrame(1)
.Subscribe(_ =>
{
// カメラ移動
cameraTransform.AddPositionX(speed * Time.deltaTime);
// キャラクター移動
characterTransform.AddPositionX(speed * Time.deltaTime);
if (Input.GetMouseButtonDown(0))
{
Jump();
}
}).AddTo(this);
characterTransform.OnTriggerEnter2DAsObservable().Subscribe(x =>
{
var item = x.GetComponent<StageItem>();
if (item is null)
{
return;
}
x.enabled = false;
switch (item.ItemType)
{
case StageItem.Type.Item1:
headerView.AddCount();
break;
default:
throw new ArgumentOutOfRangeException();
}
}).AddTo(this);
}
private bool isJump;
private void Jump()
{
if (isJump)
{
return;
}
isJump = true;
// Observable.Timer(TimeSpan.FromSeconds(.5f)).Subscribe(_ =>
// {
// isJump = false;
// }).AddTo(this);
// var basePosY = characterTransform.position.y;
// characterTransform.GetComponent<Rigidbody2D>().AddForce(Vector2.up * height, ForceMode2D.Impulse);
this.CallLerp(jumpTime, t =>
{
characterTransform.SetLocalPositionY(Mathf.Sin(Mathf.PI * t) * jumpHeight);
}, () =>
{
isJump = false;
});
}
private void ChangeState()
{
switch (state.Value)
{
case State.Ready:
state.Value = State.Play;
break;
case State.Play:
break;
case State.Success:
break;
case State.Failure:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96c2b99ef2e6c42dd998b782def0bd0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
namespace MyGame.Scenes.MiniGame.Scripts
{
public class HeaderView : MonoBehaviour
{
[SerializeField] private Text text;
private readonly ReactiveProperty<int> itemCount = new ReactiveProperty<int>();
private void Start()
{
itemCount.AddTo(this);
itemCount.Subscribe(x =>
{
text.text = $"{x}";
}).AddTo(this);
}
public void ResetView()
{
itemCount.Value = 0;
}
public void AddCount()
{
itemCount.Value++;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 109145d75cad47b886be1e9be454f54b
timeCreated: 1654843868

View File

@ -0,0 +1,29 @@
using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
namespace MyGame.Scenes.MiniGame.Scripts
{
public class StageItem : MonoBehaviour
{
public enum Type
{
Item1
}
[SerializeField] private Type itemType;
public Type ItemType => itemType;
private void Start()
{
this.OnTriggerEnter2DAsObservable()
.Take(1)
.Subscribe(_ =>
{
// effect
gameObject.SetActive(false);
}).AddTo(this);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b62a13975f3446e1b15bf182305ce742
timeCreated: 1654843868