アニメーションのフレームから時間を計算するように変更
This commit is contained in:
parent
3282eb745e
commit
bec80c9c43
|
|
@ -16,7 +16,6 @@ namespace MyGame.Scenes.Main.Scripts
|
|||
[SerializeField] private int heartCount = 5;
|
||||
[SerializeField] private float minCurve = 100f;
|
||||
[SerializeField] private float maxCurve = 400f;
|
||||
[SerializeField] private float waitTime = .3f;
|
||||
[SerializeField] private float curveTime = .5f;
|
||||
[SerializeField] private float linerTime = .5f;
|
||||
private readonly Subject<Unit> effectCompleteSubject = new Subject<Unit>();
|
||||
|
|
@ -39,7 +38,10 @@ namespace MyGame.Scenes.Main.Scripts
|
|||
{
|
||||
var coin = Instantiate(coinPrefab, beginPos, Quaternion.identity, transform);
|
||||
coin.GetComponent<Animator>()?.Play("BulkOrde_EarnedCoins");
|
||||
Effect(coin, goalPos, () => effectCompleteSubject.OnNext(Unit.Default));
|
||||
Observable.NextFrame().Subscribe(_ =>
|
||||
{
|
||||
Effect(coin, goalPos, () => effectCompleteSubject.OnNext(Unit.Default));
|
||||
}).AddTo(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -48,8 +50,8 @@ namespace MyGame.Scenes.Main.Scripts
|
|||
{
|
||||
// 最後のeffect終了時か、このオブジェクトが破棄された時に1度だけonCompleteが実行される
|
||||
effectCompleteSubject.Take(heartCount).Last()
|
||||
.Amb(this.OnDestroyAsObservable())
|
||||
.Subscribe(_ => { }, () =>
|
||||
.Amb(this.OnDestroyAsObservable())
|
||||
.Subscribe(_ => { }, () =>
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
|
|
@ -65,12 +67,19 @@ namespace MyGame.Scenes.Main.Scripts
|
|||
|
||||
private void Effect(Transform target, Vector3 goalPos, Action onComplete = null)
|
||||
{
|
||||
// localPosじゃなくて worldでやりたい
|
||||
var animator = target.GetComponent<Animator>();
|
||||
var nameHash = animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
|
||||
var clip = animator.GetCurrentAnimatorClipInfo(0)[0].clip;
|
||||
var beginDuration = 37 / clip.frameRate;
|
||||
var beginNormalizedTime = beginDuration / clip.length;
|
||||
var endNormalizedTime = 52 / clip.frameRate / clip.length;
|
||||
var endDuration = (1 - endNormalizedTime) * clip.length;
|
||||
|
||||
var direction = Random.value <= .5f ? -1 : 1;
|
||||
var depth = Random.Range(minCurve, maxCurve);
|
||||
this.CallWaitForSeconds(waitTime, () =>
|
||||
this.CallWaitForSeconds(beginDuration, () =>
|
||||
{
|
||||
animator.Play(nameHash, 0, beginNormalizedTime);
|
||||
animator.speed = 0f;
|
||||
var initPos = target.localPosition;
|
||||
this.CallLerp(curveTime, f =>
|
||||
|
|
@ -79,15 +88,19 @@ namespace MyGame.Scenes.Main.Scripts
|
|||
target.localPosition = initPos + new Vector3(f * direction * depth, x * x * depth - depth);
|
||||
}, () =>
|
||||
{
|
||||
var pos = target.position;
|
||||
this.CallLerp(linerTime, f =>
|
||||
{
|
||||
var pos = target.position;
|
||||
target.position = Vector2.Lerp(pos, goalPos, f);
|
||||
}, () =>
|
||||
{
|
||||
animator.speed = 1f;
|
||||
onComplete?.Invoke();
|
||||
Destroy(target.gameObject, 5f);
|
||||
animator.Play(nameHash, 0, endNormalizedTime);
|
||||
this.CallWaitForSeconds(endDuration, () =>
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
Destroy(target.gameObject);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue