private IEnumerator ShakeRoutine(ShakeInstance shakeInstance, Common.StaticData.ShakeInfo shakeInfo) { if (shakeInfo.Delay > 0) { yield return(new WaitForSeconds(shakeInfo.Delay)); } shakeInstance.StartFadeIn(shakeInfo.FadeInTime); _shakeInstances.Add(shakeInstance); if (shakeInfo.Duration <= 0f) // 무한 쉐이크, StartShake()로 리턴받은 ShakeInstance를 가지고 수동으로 꺼줘야 한다. ShakeHolder 참고 { yield break; } float elapsedTime = 0f; float endTime = shakeInfo.Duration + shakeInfo.FadeInTime; while (elapsedTime <= endTime) { elapsedTime += Time.deltaTime * _freezeSpeed; yield return(null); } if (shakeInstance.CurrentState != ShakeState.FadingOut) { shakeInstance.StartFadeOut(shakeInfo.FadeOutTime); } }
private void Update() { if (_target == null) { return; } Vector3 posAddShake = _originPosition; Vector3 rotAddShake = _originRotation; for (int i = 0; i < _shakeInstances.Count; i++) { if (i >= _shakeInstances.Count) { break; } ShakeInstance c = _shakeInstances[i]; if (c.CurrentState == ShakeState.Inactive && c.DeleteOnInactive) { _shakeInstances.RemoveAt(i); --i; } else if (c.CurrentState != ShakeState.Inactive) { posAddShake += MultiplyVectors(c.UpdateShake(), c.PositionInfluence); rotAddShake += MultiplyVectors(c.UpdateShake(), c.RotationInfluence); } } if (ShakePosition == true) { _target.localPosition = posAddShake; } if (ShakeRotation == true) { _target.localEulerAngles = rotAddShake; } }
public ShakeHolder StartShake(Common.StaticData.ShakeInfo shakeInfo) { if (_target == null || shakeInfo == null) { return(null); } ShakeInstance newInstance = new ShakeInstance(shakeInfo.FadeInTime, shakeInfo.FadeOutTime) { Magnitude = shakeInfo.Scale, Roughness = shakeInfo.Speed, PositionInfluence = shakeInfo.PositionInfluence.Convert(), RotationInfluence = shakeInfo.RotationInfluence.Convert() }; newInstance.ScaleRoughness = this._freezeSpeed; StartCoroutine( ShakeRoutine(newInstance, shakeInfo)); return(new ShakeHolder(newInstance, shakeInfo.FadeOutTime)); }
public void Release(bool doFadeOut = true) { if (ShakeInstance == null) { return; } if (ShakeInstance.CurrentState == ShakeState.Inactive) { ShakeInstance = null; return; } if (doFadeOut == true) { ShakeInstance.StartFadeOut(FadeOutTime); } else { ShakeInstance.StartFadeOut(0f); } ShakeInstance = null; }
public ShakeHolder(ShakeInstance shakeInstance, float fadeOutTime) { this.ShakeInstance = shakeInstance; this.FadeOutTime = fadeOutTime; }