Merge branch 'develop' of bitbucket.org:usaya/popcorn into develop
This commit is contained in:
commit
d688994475
|
|
@ -7981,8 +7981,10 @@ MonoBehaviour:
|
||||||
cornPrefab: {fileID: 5499754490129207122, guid: 2b790fd908bd14de4a601c21374fb55b,
|
cornPrefab: {fileID: 5499754490129207122, guid: 2b790fd908bd14de4a601c21374fb55b,
|
||||||
type: 3}
|
type: 3}
|
||||||
cornSpawnCount: 20
|
cornSpawnCount: 20
|
||||||
cornGrowSpeed: 0
|
baseGrowSpeed: 1
|
||||||
cornHotGrowSpeed: 0
|
hotGrowSpeed: 1.5
|
||||||
|
baseCornPopTime: 10
|
||||||
|
cornBurntDuration: 3
|
||||||
--- !u!1 &1928679189
|
--- !u!1 &1928679189
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UniRx;
|
||||||
|
using UniRx.Triggers;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
public enum CornCondition
|
||||||
|
{
|
||||||
|
Seed,
|
||||||
|
Simple,
|
||||||
|
Burnt,
|
||||||
|
Spilled
|
||||||
|
}
|
||||||
|
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public class Corn : MonoBehaviour
|
public class Corn : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
@ -11,83 +21,119 @@ public class Corn : MonoBehaviour
|
||||||
[SerializeField] private Sprite cornSeedSprite;
|
[SerializeField] private Sprite cornSeedSprite;
|
||||||
[SerializeField] private Sprite cornSimpleSprite;
|
[SerializeField] private Sprite cornSimpleSprite;
|
||||||
[SerializeField] private Sprite cornBurntSprite;
|
[SerializeField] private Sprite cornBurntSprite;
|
||||||
// コーン速度
|
|
||||||
[SerializeField] private float cornVelocity;
|
private Rigidbody2D rigidbody;
|
||||||
// コーンがスポーンしてからの時間
|
|
||||||
[SerializeField] private float cornLifeTime;
|
|
||||||
// コーン弾ける時間!
|
|
||||||
private float cornPopTime;
|
private float cornPopTime;
|
||||||
// コーンが停まってる時間(焦げる判定
|
private float cornBurntTime;
|
||||||
private float cornStopTime;
|
private float cornGrowTime;
|
||||||
private float maxCornStopTime = 5f;
|
private float cornGrowSpeed;
|
||||||
// コーンが動いている総時間
|
private float maxSpeed = 50f;
|
||||||
private float cornMovingTime => cornLifeTime - cornStopTime;
|
private float popSpeed = 20f;
|
||||||
// コーン誕生時間
|
|
||||||
private float cornSpawnTime;
|
public IReadOnlyReactiveProperty<CornCondition> Condition => condition;
|
||||||
private bool isPop;
|
private readonly ReactiveProperty<CornCondition> condition = new ReactiveProperty<CornCondition>(CornCondition.Seed);
|
||||||
|
|
||||||
private Rigidbody2D rigidbody2D;
|
|
||||||
|
// 角度調整
|
||||||
private Transform rotationResolverTransform;
|
private Transform rotationResolverTransform;
|
||||||
private Transform spriteTransform;
|
private Transform spriteTransform;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
private void Awake()
|
||||||
void Start()
|
|
||||||
{
|
{
|
||||||
rigidbody2D = GetComponent<Rigidbody2D>();
|
condition.AddTo(this);
|
||||||
spriteTransform = spriteRenderer.transform;
|
rigidbody = GetComponent<Rigidbody2D>();
|
||||||
rotationResolverTransform = spriteRenderer.transform.parent.parent;
|
|
||||||
spriteRenderer.sprite = cornSeedSprite;
|
spriteRenderer.sprite = cornSeedSprite;
|
||||||
cornSpawnTime = Time.time;
|
|
||||||
var cornPopBasicTime = 5f;
|
|
||||||
cornPopTime = cornPopBasicTime + Random.Range(0, 5f);
|
|
||||||
|
|
||||||
rigidbody2D.position = new Vector2(Random.value, Random.value);
|
spriteTransform = spriteRenderer.transform;
|
||||||
|
rotationResolverTransform = spriteTransform.parent.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
rigidbody.MovePosition(new Vector2(Random.value * 2 - 1, Random.value * 2 - 1));
|
||||||
|
|
||||||
|
// コーンが飛んでいく
|
||||||
|
this.ObserveEveryValueChanged(x => x.rigidbody.velocity.magnitude)
|
||||||
|
.Where(x => x >= maxSpeed)
|
||||||
|
.FirstOrDefault()
|
||||||
|
.Subscribe(_ =>
|
||||||
|
{
|
||||||
|
condition.Value = CornCondition.Spilled;
|
||||||
|
}).AddTo(this);
|
||||||
|
|
||||||
|
condition.Subscribe(x =>
|
||||||
|
{
|
||||||
|
switch (x)
|
||||||
|
{
|
||||||
|
case CornCondition.Seed:
|
||||||
|
break;
|
||||||
|
case CornCondition.Simple:
|
||||||
|
CornPop();
|
||||||
|
break;
|
||||||
|
case CornCondition.Burnt:
|
||||||
|
CornBurnt();
|
||||||
|
break;
|
||||||
|
case CornCondition.Spilled:
|
||||||
|
CornSpilled();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(x), x, null);
|
||||||
|
}
|
||||||
|
}).AddTo(this);
|
||||||
|
|
||||||
|
this.UpdateAsObservable().Subscribe(_ =>
|
||||||
|
{
|
||||||
|
// アニメーション向けに回転をリセット
|
||||||
|
rotationResolverTransform.rotation = Quaternion.identity;
|
||||||
|
// コーンの回転を伝搬
|
||||||
|
spriteTransform.localRotation = transform.localRotation;
|
||||||
|
}).AddTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float maxVelocity;
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
cornVelocity = rigidbody2D.velocity.magnitude;
|
if (condition.Value == CornCondition.Spilled)
|
||||||
cornLifeTime = Time.time - cornSpawnTime;
|
|
||||||
|
|
||||||
if (rigidbody2D.velocity.magnitude > maxVelocity)
|
|
||||||
{
|
{
|
||||||
maxVelocity = Mathf.Max(rigidbody2D.velocity.magnitude, maxVelocity);
|
return;
|
||||||
Debug.Log(maxVelocity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxVelocity >= 50f)
|
cornGrowTime += Time.deltaTime * cornGrowSpeed;
|
||||||
|
if (cornGrowTime >= cornBurntTime)
|
||||||
{
|
{
|
||||||
GetComponent<Collider2D>().enabled = false;
|
condition.Value = CornCondition.Burnt;
|
||||||
}
|
}
|
||||||
|
else if (cornGrowTime >= cornPopTime)
|
||||||
// アニメーション向けに回転をリセット
|
|
||||||
rotationResolverTransform.rotation = Quaternion.identity;
|
|
||||||
// コーンの回転を伝搬
|
|
||||||
spriteTransform.localRotation = transform.localRotation;
|
|
||||||
|
|
||||||
if (cornVelocity <= 0.2f)
|
|
||||||
{
|
{
|
||||||
cornStopTime += Time.deltaTime;
|
condition.Value = CornCondition.Simple;
|
||||||
}
|
|
||||||
|
|
||||||
if (cornStopTime >= maxCornStopTime && isPop)
|
|
||||||
{
|
|
||||||
spriteRenderer.sprite = cornBurntSprite;
|
|
||||||
}
|
|
||||||
if (cornLifeTime >= cornPopTime)
|
|
||||||
{
|
|
||||||
CornPop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CornPop()
|
private void CornPop()
|
||||||
{
|
{
|
||||||
if (isPop) return;
|
|
||||||
isPop = true;
|
|
||||||
var popVelocity = 20f;
|
|
||||||
var popDirection = new Vector2(Random.value * 2 - 1, Random.value * 2 - 1);
|
|
||||||
rigidbody2D.AddForce(popVelocity * popDirection, ForceMode2D.Impulse);
|
|
||||||
spriteRenderer.sprite = cornSimpleSprite;
|
spriteRenderer.sprite = cornSimpleSprite;
|
||||||
|
rigidbody.AddForce(popSpeed * new Vector2(Random.value * 2 - 1, Random.value * 2 - 1), ForceMode2D.Impulse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CornBurnt()
|
||||||
|
{
|
||||||
|
spriteRenderer.sprite = cornBurntSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CornSpilled()
|
||||||
|
{
|
||||||
|
GetComponent<Collider2D>().enabled = false;
|
||||||
|
// アニメーション消す
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCornProperty(float popTime, float burntDuration)
|
||||||
|
{
|
||||||
|
cornPopTime = popTime + Random.Range(0, 2f);
|
||||||
|
cornBurntTime = cornPopTime + burntDuration + Random.Range(0, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeGrowSpeed(float speed)
|
||||||
|
{
|
||||||
|
Debug.Log($"{speed:F}");
|
||||||
|
cornGrowSpeed = speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using UniRx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class CornManager : MonoBehaviour
|
public class CornManager : MonoBehaviour
|
||||||
|
|
@ -6,25 +7,55 @@ public class CornManager : MonoBehaviour
|
||||||
[SerializeField] private Transform cornSpawnTarget;
|
[SerializeField] private Transform cornSpawnTarget;
|
||||||
[SerializeField] private Corn cornPrefab;
|
[SerializeField] private Corn cornPrefab;
|
||||||
[SerializeField] private int cornSpawnCount = 20;
|
[SerializeField] private int cornSpawnCount = 20;
|
||||||
[SerializeField] private float cornGrowSpeed;
|
[SerializeField, ReadOnly] private float baseGrowSpeed = 1f;
|
||||||
[SerializeField] private float cornHotGrowSpeed;
|
[SerializeField] private float hotGrowSpeed;
|
||||||
|
[SerializeField] private float baseCornPopTime = 5f;
|
||||||
|
[SerializeField] private float cornBurntDuration = 5f;
|
||||||
|
|
||||||
private Corn[] cornArray;
|
private Corn[] cornArray;
|
||||||
|
private readonly ReactiveProperty<float> cornGrowSpeed = new FloatReactiveProperty(0f);
|
||||||
|
private bool isHot;
|
||||||
|
|
||||||
|
// クリア判定を通知
|
||||||
|
|
||||||
|
// コーンの状態を取得する
|
||||||
|
|
||||||
private void Start()
|
private void Awake()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
|
||||||
{
|
{
|
||||||
cornArray = new Corn[cornSpawnCount];
|
cornArray = new Corn[cornSpawnCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GenerateCorn()
|
public void RespawnCorn()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cornSpawnCount; i++)
|
for (int i = 0; i < cornSpawnCount; i++)
|
||||||
{
|
{
|
||||||
cornArray[i] = Instantiate(cornPrefab, cornSpawnTarget);
|
var corn = Instantiate(cornPrefab, cornSpawnTarget);
|
||||||
|
cornArray[i] = corn;
|
||||||
|
corn.SetCornProperty(baseCornPopTime, cornBurntDuration);
|
||||||
|
|
||||||
|
cornGrowSpeed.Subscribe(x =>
|
||||||
|
{
|
||||||
|
Debug.Log($"corn: {corn.Condition.Value} isHot: {isHot}");
|
||||||
|
// コーンが弾けた後はRedの場合のみ焦げ進行する
|
||||||
|
if (corn.Condition.Value == CornCondition.Simple && !isHot)
|
||||||
|
{
|
||||||
|
corn.ChangeGrowSpeed(0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
corn.ChangeGrowSpeed(x);
|
||||||
|
}).AddTo(this);
|
||||||
|
|
||||||
|
// コーンが弾けたとき、GrowSpeedを再設定する
|
||||||
|
corn.Condition
|
||||||
|
.Where(x => x == CornCondition.Simple)
|
||||||
|
.FirstOrDefault()
|
||||||
|
.Subscribe(_ =>
|
||||||
|
{
|
||||||
|
if (!isHot)
|
||||||
|
{
|
||||||
|
corn.ChangeGrowSpeed(0f);
|
||||||
|
}
|
||||||
|
}).AddTo(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,10 +64,16 @@ public class CornManager : MonoBehaviour
|
||||||
switch (condition)
|
switch (condition)
|
||||||
{
|
{
|
||||||
case ThermalCondition.Cold:
|
case ThermalCondition.Cold:
|
||||||
|
isHot = false;
|
||||||
|
cornGrowSpeed.Value = 0f;
|
||||||
break;
|
break;
|
||||||
case ThermalCondition.Yellow:
|
case ThermalCondition.Yellow:
|
||||||
|
isHot = false;
|
||||||
|
cornGrowSpeed.Value = baseGrowSpeed;
|
||||||
break;
|
break;
|
||||||
case ThermalCondition.Hot:
|
case ThermalCondition.Hot:
|
||||||
|
isHot = true;
|
||||||
|
cornGrowSpeed.Value = hotGrowSpeed;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(condition), condition, null);
|
throw new ArgumentOutOfRangeException(nameof(condition), condition, null);
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MyGame.Scenes.Main
|
public class Pan : MonoBehaviour
|
||||||
{
|
{
|
||||||
public class Pan : MonoBehaviour
|
[SerializeField] private PanController controller;
|
||||||
{
|
[SerializeField] private float thrust;
|
||||||
[SerializeField] private PanController controller;
|
|
||||||
[SerializeField] private float thrust;
|
|
||||||
|
|
||||||
private void OnTriggerStay2D(Collider2D other)
|
private void OnTriggerStay2D(Collider2D other)
|
||||||
{
|
{
|
||||||
// Debug.Log(controller.Direction);
|
// Debug.Log(controller.Direction);
|
||||||
// 移動量が少ないときは動かない
|
// 移動量が少ないときは動かない
|
||||||
// if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude);
|
// if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude);
|
||||||
var direct = 1f;
|
var direct = 1f;
|
||||||
direct = controller.Delta.magnitude < 0.1f ? 0 : 1;
|
direct = controller.Delta.magnitude < 0.1f ? 0 : 1;
|
||||||
other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse);
|
other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue