void ITransition.Animate(TransitionType transitionType, float delay, Action <ITransition> callback) { CurrentTransitionType_ = transitionType; EaseType easeType = (transitionType == TransitionType.In) ? inEaseType_ : outEaseType_; T startValue = (transitionType == TransitionType.In) ? GetOutValue() : GetInValue(); if (currentCoroutine_ != null) { currentCoroutine_.Cancel(); currentCoroutine_ = null; // If interrupted - start from current value startValue = GetCurrentValue(); } T endValue = (transitionType == TransitionType.In) ? GetInValue() : GetOutValue(); SetValue(startValue, endValue, 0.0f); currentCoroutine_ = CoroutineWrapper.DoAfterDelay(baseDelay_ + delay, () => { currentCoroutine_ = CoroutineWrapper.DoEaseFor(duration_, easeType, (float p) => { SetValue(startValue, endValue, p); }, () => { currentCoroutine_ = null; callback.Invoke(this); }); }); }
public void AnimateAlpha(float alpha, float duration) { CancelAnimation(); animateCoroutine_ = CoroutineWrapper.DoEaseFor(duration, EaseType.QuinticEaseIn, (float p) => { SetAlpha(Mathf.Lerp(alpha, 0.0f, p)); }); }
// PRAGMA MARK - IRecycleSetupSubscriber Implementation void IRecycleSetupSubscriber.OnRecycleSetup() { dispersing_ = false; CancelCoroutines(); renderer_.material.SetFloat("_DissolveFactor", 0.0f); coroutines_.Add(CoroutineWrapper.DoEaseFor(kInDuration * 0.6f, EaseType.CubicEaseOut, (float percentage) => { float scale = Mathf.Lerp(0.0f, kFinalScale, percentage); this.transform.localScale = new Vector3(scale, scale, scale); float emissionGain = Mathf.Lerp(0.0f, kMaxEmissionGain, percentage); renderer_.material.SetFloat("_EmissionGain", emissionGain); }, () => { coroutines_.Add(CoroutineWrapper.DoEaseFor(kInDuration * 0.4f, EaseType.CubicEaseOut, (float percentage2) => { float newScale = Mathf.Lerp(kFinalScale, kHeldScale, percentage2); this.transform.localScale = new Vector3(newScale, newScale, newScale); float newEmissionGain = Mathf.Lerp(kMaxEmissionGain, kHeldEmissionGain, percentage2); renderer_.material.SetFloat("_EmissionGain", newEmissionGain); }, () => { CancelCoroutines(); StartHeldLooping(); })); })); }
private void AnimateToState(BGMState state) { if (coroutine_ != null) { coroutine_.Cancel(); coroutine_ = null; } float oldVolume = backgroundMusicAudioSource_.volume; float newVolume = 0.0f; switch (state) { case BGMState.Normal: newVolume = 1.0f; break; case BGMState.Muted: newVolume = kBGMMutedVolume; break; } coroutine_ = CoroutineWrapper.DoEaseFor(kBGMStateTransitionDuration, EaseType.SineEaseInOut, (float p) => { backgroundMusicAudioSource_.volume = Mathf.Lerp(oldVolume, newVolume, p); }); }
private void SetDepthOfFieldEnabledInternal(bool enabled, bool animate) { if (depthOfFieldCoroutine_ != null) { depthOfFieldCoroutine_.Cancel(); depthOfFieldCoroutine_ = null; } DepthOfFieldModel.Settings settings = postProcessingProfile_.depthOfField.settings; if (!animate) { settings.focalLength = enabled ? kMaxFocalLength : kMinFocalLength; postProcessingProfile_.depthOfField.settings = settings; postProcessingProfile_.depthOfField.enabled = enabled; } else { postProcessingProfile_.depthOfField.enabled = true; float start = enabled ? kMinFocalLength : kMaxFocalLength; float end = enabled ? kMaxFocalLength : kMinFocalLength; depthOfFieldCoroutine_ = CoroutineWrapper.DoEaseFor(kDepthOfFieldAnimationDuration, EaseType.CubicEaseOut, (float p) => { settings.focalLength = Mathf.Lerp(start, end, p); postProcessingProfile_.depthOfField.settings = settings; }, () => { postProcessingProfile_.depthOfField.enabled = enabled; }); } }
// PRAGMA MARK - IRecycleSetupSubscriber Implementation public void OnRecycleSetup() { coroutine_ = CoroutineWrapper.DoEaseFor(duration_, EaseType.CubicEaseOut, (float percentage) => { light_.intensity = Mathf.Lerp(kLightIntensity, 0.0f, percentage); }, () => { ObjectPoolManager.Recycle(this); }); }
private void AnimateDamageEmissionFor(IEnumerable <Material> materials) { CoroutineWrapper.DoEaseFor(kEmissionDuration, EaseType.QuadraticEaseOut, (float percentage) => { float inversePercentage = 1.0f - percentage; float whiteBalance = inversePercentage * kEmissionWhiteBalance; foreach (Material material in materials) { material.SetColor("_EmissionColor", new Color(whiteBalance, whiteBalance, whiteBalance)); } }); }
private void AnimateShieldHit(bool hideShieldAfterwards = false) { CoroutineWrapper.DoEaseFor(kShieldAnimateDuration, EaseType.QuadraticEaseOut, (float percentage) => { float inversePercentage = 1.0f - percentage; float alpha = Mathf.Lerp(GameConstants.Instance.PlayerShieldAlphaMin, kShieldAlphaMax, inversePercentage); Player_.SetShieldAlpha(alpha); }, () => { if (hideShieldAfterwards) { Player_.SetShieldAlpha(0.0f); } }); }
private void AnimateChromaticAberration(float intensity, float duration) { if (aberrationCoroutine_ != null) { aberrationCoroutine_.Cancel(); aberrationCoroutine_ = null; } aberrationCoroutine_ = CoroutineWrapper.DoEaseFor(duration, EaseType.CubicEaseIn, (float p) => { ChromaticAberrationModel.Settings settings = postProcessingProfile_.chromaticAberration.settings; settings.intensity = Mathf.Lerp(intensity, 0.0f, p); postProcessingProfile_.chromaticAberration.settings = settings; }); }
private void RefreshSelectorPosition(bool animate) { CleanupSelectorAnimationCoroutine(); MonoBehaviour selectableMonoBehaviour = (currentSelectable_ as MonoBehaviour); Vector3[] fourCorners = new Vector3[4]; RectTransform selectableTransform = selectableMonoBehaviour.GetComponent <RectTransform>(); selectableTransform.GetWorldCorners(fourCorners); Vector2 targetStartPosition = (Vector2)selectableTransform.position; // relies on XY coordinate space Vector2 targetPosition = new Vector2(fourCorners.Average(v => v.x), fourCorners.Average(v => v.y)); selectorTransform_.GetWorldCorners(fourCorners); Vector2 currentPosition = new Vector2(fourCorners.Average(v => v.x), fourCorners.Average(v => v.y)); float scaleFactor = GameViewManagerLocator.Selector.transform.localScale.x; Vector2 startPosition = selectorTransform_.anchoredPosition; Vector2 endPosition = startPosition + ((targetPosition - currentPosition) / scaleFactor); Vector2 startSize = selectorTransform_.sizeDelta; Vector2 endSize = selectableTransform.sizeDelta + kPadding; AudioConstants.Instance.ScrollClick.PlaySFX(volumeScale: 0.7f); OnSelectorMoved.Invoke(); if (animate) { selectorAnimationCoroutine_ = CoroutineWrapper.DoEaseFor(kSelectorAnimationDuration, EaseType.QuadraticEaseOut, (p) => { Vector2 currentTargetPosition = (Vector2)selectableTransform.position; Vector2 targetOffsetPosition = currentTargetPosition - targetStartPosition; selectorTransform_.anchoredPosition = Vector2.Lerp(startPosition, endPosition + targetOffsetPosition, p); selectorTransform_.sizeDelta = Vector2.Lerp(startSize, endSize, p); }); } else { selectorTransform_.anchoredPosition = endPosition; selectorTransform_.sizeDelta = endSize; } }
// PRAGMA MARK - Public Interface public GhostModePlayerAddOn(BattlePlayer battlePlayer) { battlePlayer_ = battlePlayer; recyclablePrefab_ = battlePlayer_.GetComponentInParent <RecyclablePrefab>(); recyclablePrefab_.OnCleanup += HandleCleanup; battlePlayer_.DustParticleSystem.gameObject.SetActive(false); SetAlpha(1.0f); foreach (Renderer r in battlePlayer_.BodyRenderers) { Color diffuseColor = r.material.GetColor("_DiffuseColor"); r.material = GameConstants.Instance.PlayerTransparentMaterial; r.material.SetColor("_DiffuseColor", diffuseColor); r.shadowCastingMode = ShadowCastingMode.Off; } CoroutineWrapper.DoAfterDelay(kFadeAwayDelay, () => { CoroutineWrapper.DoEaseFor(kFadeAwayDuration, EaseType.QuadraticEaseOut, (p) => { SetAlpha(Mathf.Lerp(1.0f, 0.0f, p)); }); }); }
private void StartHeldLooping() { coroutines_.Add(CoroutineWrapper.DoEaseFor(kHelpLoopDuration / 2.0f, EaseType.CubicEaseInOut, (float percentage) => { float scale = Mathf.Lerp(kHeldScale, kHeldMaxScale, percentage); this.transform.localScale = new Vector3(scale, scale, scale); float emissionGain = Mathf.Lerp(kHeldEmissionGain, kHeldMaxEmissionGain, percentage); renderer_.material.SetFloat("_EmissionGain", emissionGain); }, () => { coroutines_.Add(CoroutineWrapper.DoEaseFor(kHelpLoopDuration / 2.0f, EaseType.CubicEaseInOut, (float percentage) => { float scale = Mathf.Lerp(kHeldMaxScale, kHeldScale, percentage); this.transform.localScale = new Vector3(scale, scale, scale); float emissionGain = Mathf.Lerp(kHeldMaxEmissionGain, kHeldEmissionGain, percentage); renderer_.material.SetFloat("_EmissionGain", emissionGain); }, () => { // loop continuously CancelCoroutines(); StartHeldLooping(); })); })); }
public void Disperse() { if (dispersing_) { return; } dispersing_ = true; CancelCoroutines(); coroutines_.Add(CoroutineWrapper.DoEaseFor(kOutDuration, EaseType.CubicEaseOut, (float percentage) => { float scale = Mathf.Lerp(kHeldScale, kFinalScale, percentage); this.transform.localScale = new Vector3(scale, scale, scale); })); coroutines_.Add(CoroutineWrapper.DoEaseFor(kOutDuration, EaseType.CubicEaseIn, (float percentage) => { renderer_.material.SetFloat("_DissolveFactor", percentage * kDissolveMaxCap); float emissionGain = Mathf.Lerp(kMaxEmissionGain, 0.0f, percentage); renderer_.material.SetFloat("_EmissionGain", emissionGain); }, () => { ObjectPoolManager.Recycle(this); })); }
private void Animate() { image_.material.SetFloat("_SegmentLength", segmentLength_); image_.material.SetFloat("_AngleOffset", angleOffset_); // animate color in CoroutineWrapper.DoEaseFor(kAnimateColorDuration, EaseType.CubicEaseInOut, (float p) => { image_.color = ColorUtil.LerpWhiteBlack(1.0f - p); }); // animate color out CoroutineWrapper.DoAfterDelay(kAnimateDuration - kAnimateColorDuration, () => { CoroutineWrapper.DoEaseFor(kAnimateColorDuration, EaseType.CubicEaseInOut, (float p) => { image_.color = ColorUtil.LerpWhiteBlack(p); }); }); CoroutineWrapper.DoEaseFor(kAnimateDuration, EaseType.CubicEaseOut, (float p) => { image_.material.SetFloat("_SegmentLength", segmentLength_ + (p * segmentLengthChange_)); image_.material.SetFloat("_AngleOffset", angleOffset_ + (p * angleOffsetChange_)); }); }