Add utils + refacto
This commit is contained in:
+41
-59
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unheimlich.Utility;
|
||||
|
||||
namespace Unheimlich.Interactions.FloatingWords
|
||||
{
|
||||
@@ -93,42 +94,41 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
|
||||
_isEffectActive = true;
|
||||
|
||||
_scribbleTweenId = LeanTween.value(gameObject, 0f, 1f, scribbleDuration)
|
||||
.setEase(LeanTweenType.easeInOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_scribbleMaterialInstance != null)
|
||||
_scribbleMaterialInstance.SetFloat(ProgressID, val);
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_scribbleTweenId = TweenHelper.AnimateMaterialFloat(
|
||||
gameObject,
|
||||
_scribbleMaterialInstance,
|
||||
ProgressID,
|
||||
0f,
|
||||
1f,
|
||||
scribbleDuration,
|
||||
() => {
|
||||
_scribbleTweenId = -1;
|
||||
|
||||
float ghostAlphaRatio = _ghostTextComponent != null ? (_originalGhostColor.a / _originalTextColor.a) : 0f;
|
||||
|
||||
_fadeTweenId = LeanTween.value(gameObject, _originalTextColor.a, finalAlpha, fadeDuration)
|
||||
.setEase(LeanTweenType.easeInQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_textComponent != null)
|
||||
{
|
||||
Color textColor = _textComponent.color;
|
||||
textColor.a = val;
|
||||
_textComponent.color = textColor;
|
||||
_textComponent.color = _textComponent.color.WithAlpha(val);
|
||||
}
|
||||
|
||||
if (_ghostTextComponent != null)
|
||||
{
|
||||
Color ghostColor = _ghostTextComponent.color;
|
||||
ghostColor.a = val * (_originalGhostColor.a / _originalTextColor.a);
|
||||
_ghostTextComponent.color = ghostColor;
|
||||
_ghostTextComponent.color = _ghostTextComponent.color.WithAlpha(val * ghostAlphaRatio);
|
||||
}
|
||||
|
||||
if (_scribbleOverlay != null)
|
||||
{
|
||||
Color scribbleColor = _scribbleOverlay.color;
|
||||
scribbleColor.a = val;
|
||||
_scribbleOverlay.color = scribbleColor;
|
||||
_scribbleOverlay.color = _scribbleOverlay.color.WithAlpha(val);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_fadeTweenId = -1;
|
||||
}).id;
|
||||
}).id;
|
||||
},
|
||||
LeanTweenType.easeInOutQuad);
|
||||
}
|
||||
|
||||
public void ResetEffect()
|
||||
@@ -141,17 +141,19 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
|
||||
if (currentProgress > 0f)
|
||||
{
|
||||
_scribbleTweenId = LeanTween.value(gameObject, currentProgress, 0f, 0.3f)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_scribbleMaterialInstance != null)
|
||||
_scribbleMaterialInstance.SetFloat(ProgressID, val);
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_scribbleTweenId = TweenHelper.AnimateMaterialFloat(
|
||||
gameObject,
|
||||
_scribbleMaterialInstance,
|
||||
ProgressID,
|
||||
currentProgress,
|
||||
0f,
|
||||
0.3f,
|
||||
() => {
|
||||
_scribbleTweenId = -1;
|
||||
if (_scribbleOverlay != null)
|
||||
_scribbleOverlay.gameObject.SetActive(false);
|
||||
}).id;
|
||||
},
|
||||
LeanTweenType.easeOutQuad);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,34 +163,23 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
|
||||
if (currentAlpha < _originalTextColor.a)
|
||||
{
|
||||
_fadeTweenId = LeanTween.value(gameObject, currentAlpha, _originalTextColor.a, 0.3f)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_textComponent != null)
|
||||
{
|
||||
Color c = _textComponent.color;
|
||||
c.a = val;
|
||||
_textComponent.color = c;
|
||||
}
|
||||
|
||||
if (_ghostTextComponent != null)
|
||||
{
|
||||
Color c = _ghostTextComponent.color;
|
||||
c.a = val * (_originalGhostColor.a / _originalTextColor.a);
|
||||
_ghostTextComponent.color = c;
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_fadeTweenId = -1;
|
||||
}).id;
|
||||
float ghostAlphaRatio = _ghostTextComponent != null ? (_originalGhostColor.a / _originalTextColor.a) : 0f;
|
||||
|
||||
_fadeTweenId = TweenHelper.FadeText(
|
||||
gameObject,
|
||||
_textComponent,
|
||||
_ghostTextComponent,
|
||||
_originalTextColor.a,
|
||||
0.3f,
|
||||
ghostAlphaRatio,
|
||||
() => { _fadeTweenId = -1; },
|
||||
LeanTweenType.easeOutQuad);
|
||||
}
|
||||
}
|
||||
|
||||
if (_scribbleOverlay != null)
|
||||
{
|
||||
Color c = _scribbleOverlay.color;
|
||||
c.a = 1f;
|
||||
_scribbleOverlay.color = c;
|
||||
_scribbleOverlay.color = _scribbleOverlay.color.WithAlpha(1f);
|
||||
}
|
||||
|
||||
_isEffectActive = false;
|
||||
@@ -196,17 +187,8 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
|
||||
private void CancelActiveTweens()
|
||||
{
|
||||
if (_scribbleTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_scribbleTweenId);
|
||||
_scribbleTweenId = -1;
|
||||
}
|
||||
|
||||
if (_fadeTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_fadeTweenId);
|
||||
_fadeTweenId = -1;
|
||||
}
|
||||
TweenHelper.CancelTween(ref _scribbleTweenId);
|
||||
TweenHelper.CancelTween(ref _fadeTweenId);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
||||
Reference in New Issue
Block a user