Browse Source

Added FadeSprite command

master
chrisgregan 11 years ago
parent
commit
15d0236430
  1. 15
      Assets/Fungus/Scripts/SpriteFader.cs
  2. 39
      Assets/Fungus/VisualScripting/FadeSprite.cs
  3. 8
      Assets/Fungus/VisualScripting/FadeSprite.cs.meta

15
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
{

39
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();
}
}
}
}

8
Assets/Fungus/VisualScripting/FadeSprite.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: accc065c3e9a6457496f075b1bd49adc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
Loading…
Cancel
Save