diff --git a/Assets/Fungus/Scripts/SpriteFader.cs b/Assets/Fungus/Scripts/SpriteFader.cs index f3864b24..8bcc5d00 100644 --- a/Assets/Fungus/Scripts/SpriteFader.cs +++ b/Assets/Fungus/Scripts/SpriteFader.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System; using System.Collections; namespace Fungus @@ -19,10 +20,12 @@ namespace Fungus SpriteRenderer spriteRenderer; + Action onFadeComplete; + /** * Attaches a SpriteFader component to a sprite object to transition its color over time. */ - public static void FadeSprite(SpriteRenderer spriteRenderer, Color targetColor, float duration, Vector2 slideOffset) + public static void FadeSprite(SpriteRenderer spriteRenderer, Color targetColor, float duration, Vector2 slideOffset, Action onComplete = null) { if (spriteRenderer == null) { @@ -52,6 +55,10 @@ namespace Fungus if (duration == 0f) { spriteRenderer.color = targetColor; + if (onComplete != null) + { + onComplete(); + } return; } @@ -62,6 +69,7 @@ namespace Fungus spriteFader.endColor = targetColor; spriteFader.endPosition = spriteRenderer.transform.position; spriteFader.slideOffset = slideOffset; + spriteFader.onFadeComplete = onComplete; } void Start() @@ -83,6 +91,11 @@ namespace Fungus // Remove this component when transition is complete Destroy(this); + + if (onFadeComplete != null) + { + onFadeComplete(); + } } else { diff --git a/Assets/Fungus/VisualScripting/FadeSprite.cs b/Assets/Fungus/VisualScripting/FadeSprite.cs new file mode 100644 index 00000000..2d89afb0 --- /dev/null +++ b/Assets/Fungus/VisualScripting/FadeSprite.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using System; +using System.Collections; + +namespace Fungus.Script +{ + + public class FadeSprite : FungusCommand + { + public float duration; + public SpriteRenderer spriteRenderer; + public Color targetColor = Color.white; + public bool waitUntilFinished = true; + + public override void OnEnter() + { + Game game = Game.GetInstance(); + + if (waitUntilFinished) + { + game.waiting = true; + } + + SpriteFader.FadeSprite(spriteRenderer, targetColor, duration, Vector2.zero, delegate { + if (waitUntilFinished) + { + game.waiting = false; + Continue(); + } + }); + + if (!waitUntilFinished) + { + Continue(); + } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/FadeSprite.cs.meta b/Assets/Fungus/VisualScripting/FadeSprite.cs.meta new file mode 100644 index 00000000..a02bdc1c --- /dev/null +++ b/Assets/Fungus/VisualScripting/FadeSprite.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: accc065c3e9a6457496f075b1bd49adc +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: