コーン飛び出し演出実装

This commit is contained in:
kimura 2021-07-09 17:19:11 +09:00
parent fae77f841d
commit a9f1d3e530
2 changed files with 37 additions and 5 deletions

View File

@ -2720,7 +2720,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 1448897407} - component: {fileID: 1448897407}
m_Layer: 0 m_Layer: 0
m_Name: ' cooking' m_Name: cooking
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0

View File

@ -35,6 +35,8 @@ public class Corn : MonoBehaviour
private float cornGrowSpeed; private float cornGrowSpeed;
private float cornSpillSpeed; private float cornSpillSpeed;
private float cornPopSpeed; private float cornPopSpeed;
private float worldWidth;
public IReadOnlyReactiveProperty<CornCondition> Condition => condition; public IReadOnlyReactiveProperty<CornCondition> Condition => condition;
private readonly ReactiveProperty<CornCondition> condition = new ReactiveProperty<CornCondition>(CornCondition.Seed); private readonly ReactiveProperty<CornCondition> condition = new ReactiveProperty<CornCondition>(CornCondition.Seed);
@ -52,6 +54,9 @@ public class Corn : MonoBehaviour
spriteTransform = spriteRenderer.transform; spriteTransform = spriteRenderer.transform;
rotationResolverTransform = spriteTransform.parent.parent; rotationResolverTransform = spriteTransform.parent.parent;
var rightTop = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
worldWidth = rightTop.x;
} }
private void Start() private void Start()
@ -67,9 +72,9 @@ public class Corn : MonoBehaviour
condition.Value = CornCondition.Spilled; condition.Value = CornCondition.Spilled;
}).AddTo(this); }).AddTo(this);
condition.Subscribe(x => condition.Pairwise().Subscribe(x =>
{ {
switch (x) switch (x.Current)
{ {
case CornCondition.Seed: case CornCondition.Seed:
break; break;
@ -80,7 +85,7 @@ public class Corn : MonoBehaviour
CornBurnt(); CornBurnt();
break; break;
case CornCondition.Spilled: case CornCondition.Spilled:
CornSpilled(); CornSpilled(x.Previous);
break; break;
default: default:
throw new ArgumentOutOfRangeException(nameof(x), x, null); throw new ArgumentOutOfRangeException(nameof(x), x, null);
@ -129,9 +134,36 @@ public class Corn : MonoBehaviour
Instantiate(effectBurnt, transform); Instantiate(effectBurnt, transform);
} }
private void CornSpilled() private void CornSpilled(CornCondition prevCondition)
{ {
GetComponent<Collider2D>().enabled = false; GetComponent<Collider2D>().enabled = false;
// フライパンに追従しないようにparent解除
transform.parent = null;
Observable.Timer(TimeSpan.FromSeconds(Random.Range(.5f, .9f))).Subscribe(_ =>
{
Destroy(gameObject);
switch (prevCondition)
{
case CornCondition.Seed:
VibrationManager.Instance.PlayVibrationOnce();
break;
case CornCondition.Simple:
case CornCondition.Burnt:
// 画面KO再生同時飛び出し時ランダム
var animation = Instantiate(spilledCornAnimationPrefab, new Vector2(Random.value * worldWidth * 2 - worldWidth, Random.value * 2 * 2 - 2), Quaternion.identity);
VibrationManager.Instance.PlayVibrationOnce();
Observable.Timer(TimeSpan.FromSeconds(1.5f)).Subscribe(__ =>
{
Destroy(animation);
});
break;
case CornCondition.Spilled:
break;
default:
throw new ArgumentOutOfRangeException(nameof(prevCondition), prevCondition, null);
}
}).AddTo(this);
} }
public void SetCornProperty(float popTime, float burntDuration, float spillSpeed, float popSpeed) public void SetCornProperty(float popTime, float burntDuration, float spillSpeed, float popSpeed)