Chris Gregan
9 years ago
5 changed files with 966 additions and 192 deletions
@ -0,0 +1,143 @@
|
||||
using UnityEngine; |
||||
using UnityEngine.UI; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
[CommandInfo("UI", |
||||
"Fade UI", |
||||
"Fades a UI object")] |
||||
public class FadeUI : TweenUI |
||||
{ |
||||
public enum FadeMode |
||||
{ |
||||
Alpha, |
||||
Color |
||||
} |
||||
|
||||
public FadeMode fadeMode = FadeMode.Alpha; |
||||
|
||||
public ColorData targetColor = new ColorData(Color.white); |
||||
|
||||
public FloatData targetAlpha = new FloatData(1f); |
||||
|
||||
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; |
||||
} |
||||
} |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected override string GetSummaryValue() |
||||
{ |
||||
return targetAlpha.Value.ToString(); |
||||
} |
||||
|
||||
public override bool IsPropertyVisible(string propertyName) |
||||
{ |
||||
if (fadeMode == FadeMode.Alpha && |
||||
propertyName == "targetColor") |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
if (fadeMode == FadeMode.Color && |
||||
propertyName == "targetAlpha") |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 5c6dd8d3a780f4d1ea772e3daf10c372 |
||||
timeCreated: 1444819884 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,131 @@
|
||||
using UnityEngine; |
||||
using UnityEngine.UI; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Fungus; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
|
||||
public abstract class TweenUI : Command |
||||
{ |
||||
[Tooltip("List of objects to be affected by the tween")] |
||||
public List<GameObject> targetObjects = new List<GameObject>(); |
||||
|
||||
[Tooltip("Type of tween easing to apply")] |
||||
public LeanTweenType tweenType = LeanTweenType.easeOutQuad; |
||||
|
||||
[Tooltip("Wait until this command completes before continuing execution")] |
||||
public BooleanData waitUntilFinished = new BooleanData(true); |
||||
|
||||
[Tooltip("Time for the tween to complete")] |
||||
public FloatData duration = new FloatData(1f); |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (targetObjects.Count == 0) |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
|
||||
ApplyTween(); |
||||
|
||||
if (!waitUntilFinished) |
||||
{ |
||||
Continue(); |
||||
} |
||||
} |
||||
|
||||
protected virtual void ApplyTween() |
||||
{ |
||||
foreach (GameObject targetObject in targetObjects) |
||||
{ |
||||
if (targetObject == null) |
||||
{ |
||||
continue; |
||||
} |
||||
|
||||
ApplyTween(targetObject); |
||||
} |
||||
|
||||
if (waitUntilFinished) |
||||
{ |
||||
LeanTween.value(gameObject, 0f, 1f, duration).setOnComplete(OnComplete); |
||||
} |
||||
} |
||||
|
||||
protected abstract void ApplyTween(GameObject go); |
||||
|
||||
protected virtual void OnComplete() |
||||
{ |
||||
Continue(); |
||||
} |
||||
|
||||
public override void OnCommandAdded(Block parentBlock) |
||||
{ |
||||
// Add an empty slot by default. Saves an unnecessary user click. |
||||
if (targetObjects.Count == 0) |
||||
{ |
||||
targetObjects.Add(null); |
||||
} |
||||
} |
||||
|
||||
protected virtual string GetSummaryValue() |
||||
{ |
||||
return ""; |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (targetObjects.Count == 0) |
||||
{ |
||||
return "Error: No targetObjects selected"; |
||||
} |
||||
else if (targetObjects.Count == 1) |
||||
{ |
||||
if (targetObjects[0] == null) |
||||
{ |
||||
return "Error: No targetObjects selected"; |
||||
} |
||||
return targetObjects[0].name + " = " + GetSummaryValue() + " alpha"; |
||||
} |
||||
|
||||
string objectList = ""; |
||||
foreach (GameObject gameObject in targetObjects) |
||||
{ |
||||
if (gameObject == null) |
||||
{ |
||||
continue; |
||||
} |
||||
|
||||
if (objectList == "") |
||||
{ |
||||
objectList += gameObject.name; |
||||
} |
||||
else |
||||
{ |
||||
objectList += ", " + gameObject.name; |
||||
} |
||||
} |
||||
|
||||
return objectList + " = " + GetSummaryValue() + " alpha"; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(180, 250, 250, 255); |
||||
} |
||||
|
||||
public override bool IsReorderableArray(string propertyName) |
||||
{ |
||||
if (propertyName == "targetObjects") |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: c43a65504f4024abaa7581ddfa448f2d |
||||
timeCreated: 1444819884 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue