-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
249 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using DG.Tweening; | ||
using UnityEngine; | ||
|
||
public class EffectAppear : MonoBehaviour | ||
{ | ||
[Range(0, 2f)] public float TimeScale = .7f; | ||
public Ease EaseType; | ||
public Vector3 fromScale; | ||
private Vector3 CurrentScale; | ||
|
||
public void Awake() | ||
{ | ||
CurrentScale = transform.localScale; | ||
} | ||
|
||
public void OnEnable() | ||
{ | ||
transform.localScale = fromScale; | ||
DoEffect(); | ||
} | ||
|
||
public void DoEffect() | ||
{ | ||
if (!gameObject.activeInHierarchy) return; | ||
transform.DOScale(CurrentScale, TimeScale).SetEase(EaseType); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using DG.Tweening; | ||
using DG.Tweening.Core; | ||
using DG.Tweening.Plugins.Options; | ||
using UnityEngine; | ||
|
||
public class EffectZoomInOut : MonoBehaviour | ||
{ | ||
public Vector3 CurrentScale; | ||
[Range(0, 2f)] public float TimeDelay; | ||
[Range(.1f, 2f)] public float SizeScale = .1f; | ||
[Range(0, 2f)] public float TimeScale = .7f; | ||
|
||
private Sequence _sequence; | ||
private TweenerCore<Vector3, Vector3, VectorOptions> _tweenerCore; | ||
|
||
public void Awake() | ||
{ | ||
CurrentScale = transform.localScale; | ||
} | ||
|
||
public void OnEnable() | ||
{ | ||
transform.localScale = CurrentScale; | ||
DoEffect(SizeScale, false); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
_sequence?.Kill(); | ||
_tweenerCore?.Kill(); | ||
} | ||
|
||
public void DoEffect(float sizeScale, bool delay) | ||
{ | ||
if (!gameObject.activeInHierarchy) return; | ||
_sequence = DOTween.Sequence().AppendInterval(TimeDelay * (delay ? 1 : 0)).AppendCallback(() => | ||
{ | ||
_tweenerCore = transform.DOScale( | ||
new Vector3(transform.localScale.x + sizeScale, transform.localScale.y + sizeScale, | ||
transform.localScale.z), | ||
TimeScale).SetEase(Ease.Linear).OnComplete(() => { DoEffect(-sizeScale, !delay); }); | ||
}); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using DG.Tweening; | ||
using Sirenix.OdinInspector; | ||
using UnityEngine; | ||
|
||
public class UIEffect : MonoBehaviour | ||
{ | ||
[Header("Data config")] [SerializeField] | ||
private AnimType animType; | ||
|
||
[SerializeField] private bool playOnAwake = true; | ||
[SerializeField] private float animTime = .5f; | ||
[SerializeField] private float delayAnimTime; | ||
|
||
[SerializeField] private Vector3 fromScale = Vector3.one; | ||
[SerializeField] private Vector3 saveLocalScale = Vector3.one; | ||
|
||
[Header("Shake Effect")] [SerializeField] | ||
private float strength = 3f; | ||
|
||
[Header("Move Effect")] [ShowIf(nameof(animType), AnimType.Move)] [SerializeField] | ||
private MoveType _moveType; | ||
|
||
[ShowIf(nameof(IsShowAttributeFromPosition))] [SerializeField] | ||
private Vector3 fromPosition; | ||
|
||
[ShowIf(nameof(IsShowAttributesMoveDirection))] [SerializeField] | ||
private DirectionType directionType; | ||
|
||
[ShowIf(nameof(IsShowAttributesMoveDirection))] [SerializeField] | ||
private float offset; | ||
|
||
[ShowIf(nameof(animType), AnimType.Move)] [ReadOnly] | ||
private Vector3 _saveAnchorPosition; | ||
|
||
private RectTransform _rectTransform; | ||
private Sequence _sequence; | ||
|
||
private bool IsShowAttributeFromPosition => animType == AnimType.Move && _moveType == MoveType.Vector3; | ||
private bool IsShowAttributesMoveDirection => animType == AnimType.Move && _moveType == MoveType.Direction; | ||
|
||
public void Awake() | ||
{ | ||
_rectTransform = GetComponent<RectTransform>(); | ||
_saveAnchorPosition = _rectTransform.anchoredPosition; | ||
saveLocalScale = _rectTransform.localScale; | ||
} | ||
|
||
public void OnEnable() | ||
{ | ||
if (playOnAwake) | ||
{ | ||
PlayAnim(); | ||
} | ||
} | ||
|
||
public void PlayAnim() | ||
{ | ||
switch (animType) | ||
{ | ||
case AnimType.OutBack: | ||
transform.localScale = fromScale; | ||
_sequence = DOTween.Sequence().OnStart(() => transform.localScale = fromScale).SetDelay(delayAnimTime) | ||
.Append(transform.DOScale(Vector3.one, animTime).OnKill(() => transform.localScale = saveLocalScale) | ||
.SetEase(Ease.OutBack)); | ||
break; | ||
case AnimType.Shake: | ||
_sequence = DOTween.Sequence().SetDelay(delayAnimTime) | ||
.Append(transform.DOShakeRotation(animTime, strength).SetEase(Ease.Linear)); | ||
break; | ||
case AnimType.Move: | ||
_rectTransform.anchoredPosition = _saveAnchorPosition; | ||
switch (_moveType) | ||
{ | ||
case MoveType.Vector3: | ||
transform.DOLocalMove(_saveAnchorPosition, animTime).SetDelay(delayAnimTime) | ||
.SetEase(Ease.Linear); | ||
break; | ||
case MoveType.Direction: | ||
switch (directionType) | ||
{ | ||
case DirectionType.Up: | ||
_sequence = DOTween.Sequence().SetDelay(delayAnimTime).Append(transform | ||
.DOLocalMoveY(transform.localPosition.y + offset, animTime).SetEase(Ease.InBack)); | ||
break; | ||
case DirectionType.Down: | ||
_sequence = DOTween.Sequence().SetDelay(delayAnimTime).Append(transform | ||
.DOLocalMoveY(transform.localPosition.y - offset, animTime).SetEase(Ease.InBack)); | ||
break; | ||
case DirectionType.Left: | ||
_sequence = DOTween.Sequence().SetDelay(delayAnimTime).Append(transform | ||
.DOLocalMoveX(transform.localPosition.x - offset, animTime).SetEase(Ease.InBack)); | ||
break; | ||
case DirectionType.Right: | ||
_sequence = DOTween.Sequence().SetDelay(delayAnimTime).Append(transform | ||
.DOLocalMoveX(transform.localPosition.x + offset, animTime).SetEase(Ease.InBack)); | ||
break; | ||
} | ||
|
||
break; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
public void OnDisable() | ||
{ | ||
Reset(); | ||
_sequence?.Kill(); | ||
} | ||
|
||
|
||
public void Reset() | ||
{ | ||
if (!Application.isPlaying) return; | ||
_rectTransform = GetComponent<RectTransform>(); | ||
_rectTransform.anchoredPosition = _saveAnchorPosition; | ||
_rectTransform.localScale = saveLocalScale; | ||
} | ||
} | ||
|
||
public enum AnimType | ||
{ | ||
OutBack, | ||
Shake, | ||
Move, | ||
} | ||
|
||
public enum MoveType | ||
{ | ||
Vector3, | ||
Direction, | ||
} | ||
|
||
public enum DirectionType | ||
{ | ||
Up, | ||
Down, | ||
Left, | ||
Right, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters