Skip to main content

FadeInOutBase

A class in Root.Township, the global namespace.

Base for objects that fade out using a _Progress shader value, or by spawning pooled mesh fader effects in their place. Does nothing on a headless server.

Constructors​

MemberWhat it is
FadeInOutBase()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected static readonly int _ProgressShader property ID for _Progress.
protected Material baseMaterialThe material copied for the fade.
protected Coroutine fadingCoroutineThe running fade coroutine, or null.
protected Material materialThe copied material the renderers use.
protected PooledObjectDefinition meshFaderObjectPooled effect spawned per mesh by FadeOut.
3 private and internal fields
MemberWhat it is
private float fadeDurationSeconds the _Progress shader value takes to go from 1 to 0 in Fade. Read through FadeDuration.
private List<MeshFilter> filtersMesh filters that get a pooled ProgressMaterialEffect copy of their mesh on FadeOut. Filled from renderers if empty.
private List<Renderer> renderersRenderers given the copied fade material. Filled from child renderers in OnValidate or ForceInitialize if empty.

Properties​

MemberWhat it is
float FadeDuration { get; }How long the fade takes, in seconds.

Methods​

MemberWhat it is
void FadeOut()Stops any running fade and spawns a pooled mesh fader effect for each mesh.
void ForceInitialize(Material baseMaterial, PooledObjectDefinition meshFaderObject)Finds renderers and mesh filters if none are set, fills in missing material and fader, then copies the material.
virtual void PostBake()Removes destroyed renderers and filters from the lists after a build bake.
protected void CopyBaseMaterial()Makes a copy of the base material, puts it on every renderer and sets its progress to 1 (fully shown).
protected virtual IEnumerator Fade() (iterator)Coroutine that lowers _Progress from 1 to 0 over FadeDuration.
protected virtual void OnValidate()Editor: fills the renderer and mesh filter lists from children, preferring renderers that use the base material.
protected void StartFade()Starts the fade coroutine if one is not already running.