Skip to content

Commit

Permalink
add new effect control
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtueSky committed Sep 18, 2023
1 parent db6016d commit 554d595
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Add the lines below to `Packages/manifest.json`

for version `1.0.2`
for version `1.0.3`
```csharp
"com.virtuesky.scriptableobject.architecture":"https://github.com/VirtueSky/SO.Architecture.git#1.0.2",
"com.virtuesky.scriptableobject.architecture":"https://github.com/VirtueSky/SO.Architecture.git#1.0.3",
```
27 changes: 27 additions & 0 deletions VirtueSky/Misc/EffectAppear.cs
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);
}
}
11 changes: 11 additions & 0 deletions VirtueSky/Misc/EffectAppear.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions VirtueSky/Misc/EffectZoomInOut.cs
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); });
});
}
}
11 changes: 11 additions & 0 deletions VirtueSky/Misc/EffectZoomInOut.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions VirtueSky/Misc/UIEffect.cs
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,
}
11 changes: 11 additions & 0 deletions VirtueSky/Misc/UIEffect.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.virtuesky.scriptableobject.architecture",
"displayName": "ScriptableObjectArchitecture",
"description": "ScriptableObjectArchitecture for unity",
"version": "1.0.2",
"version": "1.0.3",
"unity": "2021.3",
"category": "virtuesky",
"keywords": [
Expand Down

0 comments on commit 554d595

Please sign in to comment.