From 554d595440d933a2bdd5808eda013f160ae30352 Mon Sep 17 00:00:00 2001 From: Virtuesky Date: Mon, 18 Sep 2023 23:26:43 +0700 Subject: [PATCH] add new effect control --- README.md | 4 +- VirtueSky/Misc/EffectAppear.cs | 27 +++++ VirtueSky/Misc/EffectAppear.cs.meta | 11 ++ VirtueSky/Misc/EffectZoomInOut.cs | 45 ++++++++ VirtueSky/Misc/EffectZoomInOut.cs.meta | 11 ++ VirtueSky/Misc/UIEffect.cs | 141 +++++++++++++++++++++++++ VirtueSky/Misc/UIEffect.cs.meta | 11 ++ package.json | 2 +- 8 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 VirtueSky/Misc/EffectAppear.cs create mode 100644 VirtueSky/Misc/EffectAppear.cs.meta create mode 100644 VirtueSky/Misc/EffectZoomInOut.cs create mode 100644 VirtueSky/Misc/EffectZoomInOut.cs.meta create mode 100644 VirtueSky/Misc/UIEffect.cs create mode 100644 VirtueSky/Misc/UIEffect.cs.meta diff --git a/README.md b/README.md index 5938bbc1..c1694b40 100644 --- a/README.md +++ b/README.md @@ -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", ``` \ No newline at end of file diff --git a/VirtueSky/Misc/EffectAppear.cs b/VirtueSky/Misc/EffectAppear.cs new file mode 100644 index 00000000..4bcca1e4 --- /dev/null +++ b/VirtueSky/Misc/EffectAppear.cs @@ -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); + } +} \ No newline at end of file diff --git a/VirtueSky/Misc/EffectAppear.cs.meta b/VirtueSky/Misc/EffectAppear.cs.meta new file mode 100644 index 00000000..5c1aaa8e --- /dev/null +++ b/VirtueSky/Misc/EffectAppear.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8d6d71043917f4558833eb085b54db75 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VirtueSky/Misc/EffectZoomInOut.cs b/VirtueSky/Misc/EffectZoomInOut.cs new file mode 100644 index 00000000..cec5cda4 --- /dev/null +++ b/VirtueSky/Misc/EffectZoomInOut.cs @@ -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 _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); }); + }); + } +} \ No newline at end of file diff --git a/VirtueSky/Misc/EffectZoomInOut.cs.meta b/VirtueSky/Misc/EffectZoomInOut.cs.meta new file mode 100644 index 00000000..30121209 --- /dev/null +++ b/VirtueSky/Misc/EffectZoomInOut.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f734c74ff660e4781ab333e1fd42d8a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VirtueSky/Misc/UIEffect.cs b/VirtueSky/Misc/UIEffect.cs new file mode 100644 index 00000000..bf4407a5 --- /dev/null +++ b/VirtueSky/Misc/UIEffect.cs @@ -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(); + _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.anchoredPosition = _saveAnchorPosition; + _rectTransform.localScale = saveLocalScale; + } +} + +public enum AnimType +{ + OutBack, + Shake, + Move, +} + +public enum MoveType +{ + Vector3, + Direction, +} + +public enum DirectionType +{ + Up, + Down, + Left, + Right, +} \ No newline at end of file diff --git a/VirtueSky/Misc/UIEffect.cs.meta b/VirtueSky/Misc/UIEffect.cs.meta new file mode 100644 index 00000000..17d8dc9e --- /dev/null +++ b/VirtueSky/Misc/UIEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 47d8fa17fdafb4fa58ca0a7d8410a5b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index b0d4aa99..54dfd2a1 100644 --- a/package.json +++ b/package.json @@ -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": [