Class TMPMediator
- Namespace
- TMPEffects.Components.Mediator
A mediator class for TMPAnimator and TMPWriter (and potential additions, if any).
Handles the pre- and postprocessing of the text, as well as maintaining information
about it in the form of a CharData and VisibilityState collection.
public class TMPMediator : IDisposable
- Inheritance
-
TMPMediator
- Implements
- Inherited Members
Fields
CharData
Collection containing all the current CharData.
You can rely on this never being reassigned (therefore any wrappers
you may create, e.g. Collection<VisibilityData>, can be relied on as well.)
public readonly ReadOnlyCollection<CharData> CharData
Field Value
Processor
The TMPEffectsTextProcessor used by the associated TMP_Text component.
public readonly TMPEffectsTextProcessor Processor
Field Value
Text
The associated TMP_Text component.
public readonly TMP_Text Text
Field Value
- TMP_Text
VisibilityStates
Collection containing all the current VisibilityState states of the CharData collection.
The mapping of VisibilityState to CharData is index based, i.e. the n-th VisibilityState
is associated with the n-th CharData.
You can rely on this never being reassigned (therefore any wrappers
you may create, e.g. Collection<VisibilityData>, can be relied on as well.)
public readonly ReadOnlyCollection<VisibilityState> VisibilityStates
Field Value
Methods
Dispose()
Dispose the TMPMediator instance.
public void Dispose()
ForceReprocess()
Forces a mesh update on the associated TMP_Text component.
Will reprocess the text.
public void ForceReprocess()
GetVisibilityState(CharData)
Get the associated VisibilityState of the given CharData.
public VisibilityState GetVisibilityState(CharData cData)
Parameters
cData
CharDataThe CharData to get the VisibilityState of.
Returns
- VisibilityState
The associated VisibilityState of the given CharData.
Remarks
This uses the index property of info to get the associated VisibilityState.
Therefore, the responsiblity is on you to ensure cData
is valid, i.e. belongs to this TMPMediator instance.
Exceptions
RegisterVisibilityProcessor(object)
Register as the visibility processor of this TMPMediator.
There may be at most one visibility processor registered at any given time.
This makes you responsible of applying any actual changes to the mesh of
the character when its associated VisibilityState is updated.
Subscribe to the VisibilityStateUpdated event to get a callback whenever
an VisibilityState is updated.
public bool RegisterVisibilityProcessor(object obj)
Parameters
obj
objectThe object to identify the subscriber.
Returns
- bool
true if registration was successful; otherwise false.
SetText(string)
Set the text of the associated TMP_Text component.
public void SetText(string text)
Parameters
text
string
SetVisibilityState(int, int, VisibilityState)
Set the VisibilityState associated with the CharData at the given indices.
public void SetVisibilityState(int startIndex, int length, VisibilityState state)
Parameters
startIndex
intThe first index of the to-be-updated VisibilityState.
length
intThe amount of to-be-updated VisibilityState.
state
VisibilityStateThe VisibilityState to set to.
Exceptions
SetVisibilityState(int, VisibilityState)
Set the VisibilityState associated with the CharData at the given index.
public void SetVisibilityState(int index, VisibilityState state)
Parameters
index
intThe index of the to-be-updated VisibilityState.
state
VisibilityStateThe VisibilityState to set to.
Exceptions
SetVisibilityState(CharData, VisibilityState)
Set the VisibilityState associated with the given CharData.
public void SetVisibilityState(CharData cData, VisibilityState state)
Parameters
cData
CharDataThe CharData to set the associated VisibilityState of.
state
VisibilityStateThe VisibilityState to set to.
Remarks
This uses the index property of info to get the associated VisibilityState.
Therefore, the responsiblity is on you to ensure cData
is valid, i.e. belongs to this TMPMediator instance.
Exceptions
UnregisterVisibilityProcessor(object)
Unregister as the visibility processor of this TMPMediator.
public bool UnregisterVisibilityProcessor(object obj)
Parameters
obj
objectThe object to identify the subscriber.
Returns
- bool
true if registration was successful; otherwise false.
Events
TextChanged_Early
Raised when the associated TMP_Text component raises its TEXT_CHANGED_EVENT, before TextChanged_Late.
You should use this callback for initialization, e.g. processing tags. Don't modify data that might mess with the initialization of other
listeners, such as setting visibilities or char data. For such operations, use TextChanged_Late.
public event TMPMediator.TextChangedEarlyEventHandler TextChanged_Early
Event Type
TextChanged_Late
Raised when the associated TMP_Text component raises its TEXT_CHANGED_EVENT, after TextChanged_Early.
public event TMPMediator.TextChangedLateEventHandler TextChanged_Late
Event Type
VisibilityStateUpdated
Raised when the VisibilityState of one of the contained CharData is updated.
public event TMPMediator.VisibilityEventHandler VisibilityStateUpdated