|
| 1 | +using UnityEngine; |
| 2 | +using UnityEngine.UI; |
| 3 | + |
| 4 | +namespace Zigurous.UI |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Extension methods for UI canvas. |
| 8 | + /// </summary> |
| 9 | + public static class CanvasExtensions |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Fades the alpha of all graphics of the canvas to 100% over the given |
| 13 | + /// <paramref name="duration"/>. |
| 14 | + /// </summary> |
| 15 | + /// <param name="canvas">The canvas to fade.</param> |
| 16 | + /// <param name="duration">The amount of seconds it takes to fade the graphics.</param> |
| 17 | + /// <param name="ignoreTimeScale">Ignores the time scale when fading the graphics.</param> |
| 18 | + public static void FadeInGraphics(this Canvas canvas, float duration, bool ignoreTimeScale = false) |
| 19 | + { |
| 20 | + Graphic[] graphics = canvas.GetComponentsInChildren<Graphic>(); |
| 21 | + |
| 22 | + for (int i = 0; i < graphics.Length; i++) { |
| 23 | + graphics[i].CrossFadeAlpha(1.0f, duration, ignoreTimeScale); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Fades the alpha of all graphics of the canvas to 0% over the given |
| 29 | + /// <paramref name="duration"/>. |
| 30 | + /// </summary> |
| 31 | + /// <param name="canvas">The canvas to fade.</param> |
| 32 | + /// <param name="duration">The amount of seconds it takes to fade the graphics.</param> |
| 33 | + /// <param name="ignoreTimeScale">Ignores the time scale when fading the graphics.</param> |
| 34 | + public static void FadeOutGraphics(this Canvas canvas, float duration, bool ignoreTimeScale = false) |
| 35 | + { |
| 36 | + Graphic[] graphics = canvas.GetComponentsInChildren<Graphic>(); |
| 37 | + |
| 38 | + for (int i = 0; i < graphics.Length; i++) { |
| 39 | + graphics[i].CrossFadeAlpha(0.0f, duration, ignoreTimeScale); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments