Multi Sprite Fader (Script+CustomAction)

Description: This is a modified SpriteFader and ActionSpriteFade. Made to also fade all child SpriteRenderers. Like with the SpriteFader.cs, you must place the MultiSpriteFader script on the parent Sprite. Then use the "Fade Multiple Sprites" action.

To use these, you need to create two text files and rename them MultiSpriteFader.cs and ActionMultiSpriteFade.cs and then overwrite their contents with the code below. Finally, the ActionMultiSpriteFade.cs needs to be placed in your Custom actions folder (assigned in the Actions manager) or you can drop it in the Actions folder under Adventure Creator/Scripts/Actions.

Base script: /* *  *	Adventure Creator *	by Chris Burton, 2013-2016 *	 *	"SpriteFader.cs" *  *	Attach this to any sprite you wish to fade. *   *      Alverik: *	Modified to fade all child SpriteRenderers */ using UnityEngine; using System.Collections; namespace AC { /** 	 * Provides functions that can fade a sprite in and out. */ 	[AddComponentMenu("Adventure Creator/Misc/Multi Sprite fader")] [RequireComponent (typeof (SpriteRenderer))] #if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0) [HelpURL("http://www.adventurecreator.org/scripting-guide/class_a_c_1_1_sprite_fader.html")] #endif public class MultiSpriteFader : MonoBehaviour { 		/** True if the Sprite attached to the GameObject this script is attached to is currently fading */ [HideInInspector] public bool isFading = true; /** The time at which the sprite began fading */ [HideInInspector] public float fadeStartTime; /** The duration of the sprite-fading effect */ [HideInInspector] public float fadeTime; /** The direction of the sprite-fading effect (fadeIn, fadeOut) */ [HideInInspector] public FadeType fadeType; private SpriteRenderer[] _spriteRenderers; private void Awake { 			_spriteRenderers = GetComponentsInChildren; } 		/** 		 * Forces the alpha value of a sprite to a specific value. * The alpha value to assign the sprite attached to this GameObject */ 		public void SetAlpha (float _alpha) { 		   for (var index = 0; index < _spriteRenderers.Length; index++) { 		       var sr = _spriteRenderers[index]; Color color = sr.color; color.a = _alpha; sr.color = color; } 		} 		/** 		 * Fades the Sprite attached to this GameObject in or out. * The direction of the fade effect (fadeIn, fadeOut) * The duration, in seconds, of the fade effect * The alpha value that the Sprite should have when the effect begins. If <0, the Sprite's original alpha will be used. */ 		public void Fade (FadeType _fadeType, float _fadeTime, float startAlpha = -1) { 		   StopAllCoroutines; float currentAlpha = 0f; for (var index = 0; index < _spriteRenderers.Length; index++) { 		       var sr = _spriteRenderers[index]; currentAlpha = sr.color.a; 		       if (startAlpha >= 0) { 		           currentAlpha = startAlpha; SetAlpha(startAlpha); } 		       else { 		           if (sr.enabled) continue; sr.enabled = true; if (_fadeType != FadeType.fadeIn) continue; currentAlpha = 0f; SetAlpha(0f); } 		   } 		    if (_fadeType == FadeType.fadeOut) { 				fadeStartTime = Time.time - (currentAlpha * _fadeTime); } 			else { 				fadeStartTime = Time.time - ((1f - currentAlpha) * _fadeTime); } 			fadeTime = _fadeTime; fadeType = _fadeType; if (fadeTime > 0f) { 			   for (var index = 0; index < _spriteRenderers.Length; index++) { 			       var sr = _spriteRenderers[index]; StartCoroutine(DoFade(sr)); } 			} 			else { 				EndFade ; } 		} 		/** 		 * Ends the sprite-fading effect, and sets the Sprite's alpha to its target value. */ 		public void EndFade { 			StopAllCoroutines; isFading = false; for (var index = 0; index < _spriteRenderers.Length; index++) { 		       var sr = _spriteRenderers[index]; Color color = sr.color; color.a = fadeType == FadeType.fadeIn ? 1f : 0f; sr.color = color; } 		} 		private IEnumerator DoFade (SpriteRenderer sr) { 			sr.enabled = true; isFading = true; Color color = sr.color; if (fadeType == FadeType.fadeIn) { 				while (color.a < 1f) { 					color.a = -1f + AdvGame.Interpolate (fadeStartTime, fadeTime, MoveMethod.Linear, null); sr.color = color; yield return new WaitForFixedUpdate ; } 			} 			else { 				while (color.a > 0f) { 					color.a = 2f - AdvGame.Interpolate (fadeStartTime, fadeTime, MoveMethod.Linear, null); sr.color = color; yield return new WaitForFixedUpdate ; } 			} 			isFading = false; } 	} }

Modified Action: /* * *	Adventure Creator *	by Chris Burton, 2013-2016 *	 *	"ActionSpriteFade.cs" *  *	Fades a sprite in or out. *	 *	Alverik: *	Modified to use MultiSpriteFader *  */ using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor; namespace AC { [System.Serializable] public class ActionMultiSpriteFade : Action { 		public int constantID = 0; public int parameterID = -1; public MultiSpriteFader spriteFaders; public FadeType fadeType = FadeType.fadeIn; public float fadeSpeed; public ActionMultiSpriteFade { 			this.isDisplayed = true; category = ActionCategory.Object; title = "Fade multiple sprites"; description = "Fades multiple sprites in or out."; } 		override public void AssignValues (List parameters) { 			spriteFaders = AssignFile  (parameters, parameterID, constantID, spriteFaders); } 		override public float Run { 			if (spriteFaders == null) { 				return 0f; } 			if (!isRunning) { 				isRunning = true; spriteFaders.Fade (fadeType, fadeSpeed); if (willWait) { 					return fadeSpeed; } 			} 			else { 				isRunning = false; } 			return 0f; } 		override public void Skip { 			if (spriteFaders != null) { 				spriteFaders.Fade (fadeType, 0f); } 		} 		#if UNITY_EDITOR override public void ShowGUI (List parameters) { 			parameterID = Action.ChooseParameterGUI ("Sprite to fade:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { 				constantID = 0; spriteFaders = null; } 			else { 				spriteFaders = (MultiSpriteFader) EditorGUILayout.ObjectField ("Sprite to fade:", spriteFaders, typeof (MultiSpriteFader), true); constantID = FieldToID  (spriteFaders, constantID); spriteFaders = IDToField  (spriteFaders, constantID, false); } 			fadeType = (FadeType) EditorGUILayout.EnumPopup ("Type:", fadeType); fadeSpeed = EditorGUILayout.Slider ("Time to fade:", fadeSpeed, 0, 3); willWait = EditorGUILayout.Toggle ("Wait until finish?", willWait); AfterRunningOption ; } 		override public void AssignConstantIDs (bool saveScriptsToo) { 			if (saveScriptsToo) { 				AddSaveScript  (spriteFaders); } 			AssignConstantID  (spriteFaders, constantID, parameterID); } 		override public string SetLabel { 			string labelAdd = ""; if (spriteFaders != null) { 				labelAdd = " (" + fadeType.ToString + " " + spriteFaders.gameObject.name + ")"; } 			return labelAdd; } 		#endif } }
 * 1) if UNITY_EDITOR
 * 1) endif