You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
4.9 KiB
155 lines
4.9 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
9 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using Fungus;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Fades a UI object.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("UI",
|
||
|
"Fade UI",
|
||
|
"Fades a UI object")]
|
||
|
public class FadeUI : TweenUI
|
||
|
{
|
||
|
public enum FadeMode
|
||
|
{
|
||
|
Alpha,
|
||
|
Color
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
[SerializeField] protected FadeMode fadeMode = FadeMode.Alpha;
|
||
9 years ago
|
|
||
8 years ago
|
[SerializeField] protected ColorData targetColor = new ColorData(Color.white);
|
||
9 years ago
|
|
||
8 years ago
|
[SerializeField] protected FloatData targetAlpha = new FloatData(1f);
|
||
9 years ago
|
|
||
8 years ago
|
protected override void ApplyTween(GameObject go)
|
||
|
{
|
||
|
foreach (Image image in go.GetComponentsInChildren<Image>())
|
||
|
{
|
||
|
if (duration == 0f)
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
Color tempColor = image.color;
|
||
|
tempColor.a = targetAlpha;
|
||
|
image.color = tempColor;
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
image.color = targetColor;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType);
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
foreach (Text text in go.GetComponentsInChildren<Text>())
|
||
|
{
|
||
|
if (duration == 0f)
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
Color tempColor = text.color;
|
||
|
tempColor.a = targetAlpha;
|
||
|
text.color = tempColor;
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
text.color = targetColor;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType);
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
foreach (TextMesh textMesh in go.GetComponentsInChildren<TextMesh>())
|
||
|
{
|
||
|
if (duration == 0f)
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
Color tempColor = textMesh.color;
|
||
|
tempColor.a = targetAlpha;
|
||
|
textMesh.color = tempColor;
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
textMesh.color = targetColor;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
switch (fadeMode)
|
||
|
{
|
||
|
case FadeMode.Alpha:
|
||
|
LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType);
|
||
|
break;
|
||
|
case FadeMode.Color:
|
||
|
LeanTween.color(go, targetColor, duration).setEase(tweenType);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
protected override string GetSummaryValue()
|
||
|
{
|
||
9 years ago
|
if (fadeMode == FadeMode.Alpha)
|
||
|
{
|
||
|
return targetAlpha.Value.ToString() + " alpha";
|
||
|
}
|
||
|
else if (fadeMode == FadeMode.Color)
|
||
|
{
|
||
|
return targetColor.Value.ToString() + " color";
|
||
|
}
|
||
|
|
||
|
return "";
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override bool IsPropertyVisible(string propertyName)
|
||
|
{
|
||
|
if (fadeMode == FadeMode.Alpha &&
|
||
|
propertyName == "targetColor")
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (fadeMode == FadeMode.Color &&
|
||
|
propertyName == "targetAlpha")
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
return true;
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|