Skip to content

Scripting

Everything the inspector does can be done from code. All the toolkit’s classes are in one namespace:

using AllIn1Assets.AllIn1TextShader;

A text’s look is its material, read from the text itself:

using TMPro;
using UnityEngine;
public class HitFlash : MonoBehaviour
{
[SerializeField] private TMP_Text text;
public void Flash(float amount)
{
Material material = text.fontSharedMaterial;
material.SetFloat("_OuterGlowSize", Mathf.Lerp(0.2f, 0.7f, amount));
material.SetColor("_Outline01Color", Color.Lerp(Color.black, Color.red, amount));
}
}

Use fontSharedMaterial and read it from the text each time rather than keeping the material asset in a field: each text has its own material, and in play mode a text whose material another text already uses gets its own copy, so the asset is not what it draws with.

Property names: hover over a property in the material inspector and its tooltip shows the name to use, such as _Outline01Width for Outline Thickness. An effect’s toggle shows its keyword the same way, such as _OUTLINE_ON.

Animating: any float or color can be tweened from a script or a tween library, every frame if you like.

Turning effects on and off: an effect’s toggle is a shader keyword, and a build only contains the combinations of keywords its materials use. Rather than enabling a keyword from code, keep the effect on and fade it with its own values, or swap to another material that has it on. See Performance and Shader Variants.

AllIn1TextTypewriter, see Typewriter for what each part does.

CallWhat it does
Play()Starts playing. The first time, or after SetText() on a stopped typewriter, that starts the reveal
Reveal()Plays the reveal from the start
RevealImmediate()Shows the whole text at once, loops running
Hide()Plays the hide
HideImmediate()Hides the text at once
Pause(), Resume()Freeze everything where it is, and continue
Stop()Stops the typewriter where it is. Loops stop too
GetPlaybackState()STOPPED, PLAYING or PAUSED
CallWhat it does
SetText(string)Changes the text, reads its tags, regroups the letters and restarts the reveal. If the typewriter is stopped, the reveal waits for Play()
SetEffectConfigurations(reveal, loop, hide)Swaps the presets. Pass null to keep one as it is. Call Refresh() afterwards
Refresh()Rebuilds with the current presets and restarts the reveal

A preset is a MeshEffectGroupConfig asset, the files in the toolkit’s Config folder, so a script can hold several in serialized fields and swap them:

[SerializeField] private AllIn1TextTypewriter typewriter;
[SerializeField] private MeshEffectGroupConfig angryReveal;
[SerializeField] private MeshEffectGroupConfig angryLoop;
public void SayAngrily(string line)
{
typewriter.SetEffectConfigurations(angryReveal, angryLoop, null);
typewriter.SetText(line);
}

Change the text with SetText() rather than through the TextMeshPro component, so tags are read and the letters are regrouped.

CallWhat it returns
IsRevealed(), IsHidden()Whether the reveal or the hide has finished
GetRevealProgressNormalized(), GetHideProgressNormalized()How far along they are, from 0 to 1

The events are usually simpler than checking every frame:

UnityEvent fieldC# event
onRevealStartedEventOnRevealStarted
onCharacterRevealStartedEvent (char, int)OnCharacterRevealStarted
onRevealCompletedEventOnRevealCompleted
onHideStartedEventOnHideStarted
onHideCompletedEventOnHideCompleted

They fire in play mode, from the typewriter’s update, after the letters have moved. See Events for when each one fires and a typing sound example.

RevealAtProgress(float) and HideAtProgress(float) set the reveal or the hide to a progress from 0 to 1 instead of letting time run it, for a reveal tied to a slider, a scroll position or a charge bar. Every letter gets the same progress. Call FinishProgressControl() when you are done, to land at the end and hand control back to time. This is what Text on a Spline uses for its travel.

AllIn1TextSpline. Show(), Hide(), ShowImmediate() and HideImmediate() move the text in and out, IsShown and IsTraveling say where it is, and OnShowCompleted and OnHideCompleted fire when a travel lands. Every inspector setting is a property, and the points are edited with GetPoint, SetPoint, AddPoint, InsertPoint and RemovePoint. With no typewriter on the text, call RequestWriteBack() after changing a setting from code. Details and an example: Text on a Spline.

AllIn1TextWarp. Set Style, Bend, Amount and the rest, and the text follows the same frame, with nothing to apply. Tween Amount to warp a text in and out, and shape a Custom cage with SetCagePoint. Details and an example: Warp.

AllIn1TextParticles. Play(), Stop() and Clear() run an emitter and the ones below it, Emit(count) and EmitAtLetter(characterIndex, count) release particles right away, and rateMultiplier scales the emission rate. Every module is a public field. Details and an example: Text Particles.

BevelLightController. Its settings are public fields (lightAngle, lightElevation, lightColor, lightIntensity and so on) and it sends them to the shader every frame, so setting one from code moves the light on every text in Global mode at once:

[SerializeField] private BevelLightController bevelLight;
private void Update()
{
bevelLight.lightAngle = Mathf.Repeat(Time.time * 45f, 360f);
}