Skip to main content

SpectralMaterialTransition

A class in Root.Township, the global namespace.

Client visual that swaps a set of renderers between their normal materials and a spectral (ghost) look, with materialize, fade and crack shader animations. Does nothing on headless servers.

Constructors​

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

Fields​

16 private and internal fields
MemberWhat it is
private SpectralMaterialTransition.Animator[] animatorsOne material animator per distinct original material.
private float crackDurationSeconds the crack animation takes.
private float crackProgressCurrent crack progress, 0 to 1.
private IUnityUpdateMethod cracksUpdateHandle of the crack update.
private float fadeDurationSeconds a fade takes.
private float fadeProgressCurrent fade-out progress, 0 to 1.
private IUnityUpdateMethod fadeUpdateHandle of the fade update.
private bool isFadingSet by FadeOut; stops further materialize changes.
private bool isFadingInOnStartFades in when the object wakes.
private bool isMaterializedWhether the object is, or is heading to, its solid look. Also the starting state.
private float progressBacking field for MaterializationProgress.
private Material spectralMaterialBase ghost material, copied per original with its texture as cutout.
private Renderer[] targetRenderersRenderers whose materials are swapped.
private float transitionDurationSeconds a materialize or dematerialize takes.
private Material transitionMaterialBase material used while animating, copied per original.
private IUnityUpdateMethod transitionUpdateHandle of the materialize update.

Properties​

8 private and internal properties
MemberWhat it is
private static int _BumpMap { get; }Shader ID of _BumpMap.
private static int _CracksProgress { get; }Shader ID of _CracksProgress.
private static int _Cutout { get; }Shader ID of _Cutout.
private static int _FadeOutProgress { get; }Shader ID of _FadeOutProgress.
private static int _MainTex { get; }Shader ID of _MainTex.
private static int _MaterializationProgress { get; }Shader ID of _MaterializationProgress.
private static int _NormalMap { get; }Shader ID of _NormalMap.
private float MaterializationProgress { get; set; }0 (spectral) to 1 (solid) progress; setting it pushes _MaterializationProgress to every transition material.

Methods​

MemberWhat it is
void AnimateCracks(bool isCrackingIn)Animates the cracks effect in or out. Cracking out ends on the spectral look.
void FadeOut()Client: starts fading the object out. Blocks SetMaterialized from then on.
void SetMaterialized(bool isMaterialized)Client: animates towards the solid or spectral look, unless already there or fading out.
10 private and internal methods
MemberWhat it is
private void Awake()Client: groups renderers by material, builds a spectral and transition copy for each, and snaps to the starting state.
private void CrackInUpdate()Raises _CracksProgress to 1 over crackDuration.
private void CrackOutUpdate()Lowers _CracksProgress to 0 then snaps renderers to spectral.
private void FadeIn()Starts fading the object in from fully faded out.
private void FadeInUpdate()Lowers _FadeOutProgress to 0 then snaps to the current state.
private void FadeOutUpdate()Raises _FadeOutProgress towards 1 over fadeDuration.
private void FinishTransition()Stops the transition update and snaps renderers to the original or spectral material.
private void OnDestroy()Removes all running updates.
private void IBuildRendererPostBake.PostBake()Build step: removes null entries from targetRenderers.
private void TransitionUpdate()Moves materialization progress towards the target each frame and finishes at the end.