Created
April 26, 2018 21:37
-
-
Save abeldantas/8941071c362b8b08bdb0e4efe1c2b335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using FullInspector; | |
using MathUtils; | |
using UnityEngine.UI; | |
public class FadeGraphics : BaseBehavior | |
{ | |
public Dictionary<float, List<Graphic>> GraphicFinalAlphaMap; | |
public void Start() | |
{ | |
if ( GraphicFinalAlphaMap.Values.Count == 0 || GraphicFinalAlphaMap.Values.First() == null ) | |
{ | |
PopulateNestedGraphics(); | |
} | |
Hide(); | |
StartCoroutine( CoroutineHelper.WaitAndDo( 0.5f, | |
() => | |
{ | |
foreach ( var v in GraphicFinalAlphaMap.Keys ) | |
{ | |
var v1 = v; | |
StartCoroutine( CoroutineHelper.ChangeFloatBetween( 0.5f, 0f, v1, ( a ) => | |
{ | |
SetTransparency( GraphicFinalAlphaMap[v1], a ); | |
}, | |
Easer.Equations.QuartEaseIn ) ); | |
} | |
} ) ); | |
} | |
[InspectorButton] public void PopulateNestedGraphics() | |
{ | |
var graphics = GetComponentsInChildren<Graphic>().ToList(); | |
foreach ( var g in graphics ) | |
{ | |
GraphicFinalAlphaMap[1f].Add( g ); | |
} | |
} | |
public void SetTransparency( List<Graphic> graphics, float alpha ) | |
{ | |
foreach ( var g in graphics ) | |
{ | |
g.SetTransparency( alpha ); | |
} | |
} | |
[InspectorButton] public void Hide() | |
{ | |
foreach(var v in GraphicFinalAlphaMap.Values ) { | |
SetTransparency( v, 0 ); | |
} | |
} | |
[InspectorButton] public void Show() | |
{ | |
foreach ( var k in GraphicFinalAlphaMap.Keys ) | |
{ | |
SetTransparency( GraphicFinalAlphaMap[k], k ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment