TMP_TextCanvasTypeSettings - jimdroberts/FishMMO GitHub Wiki
The TMP_TextCanvasTypeSettings
class is a canvas type settings handler for TextMeshPro's TMP_Text
component in the FishMMO client. It applies color settings from a configuration file to TMP text components, supporting theming for placeholder and regular text based on the object's name.
-
public override void ApplySettings(object component, Configuration configuration)
Applies color settings from configuration to the given
TMP_Text
component. Uses the primary color for placeholders and the text color for regular text, based on the object's name.
- Ensure
TMP_TextCanvasTypeSettings
is registered in your canvas settings map forTMP_Text
components. - Store color values (Primary, Text) in your configuration file.
- When
ApplySettings
is called, the TMP text's color will be set according to its name and the configuration.
// Example usage in a canvas crawler or theming system:
var text = myGameObject.GetComponent<TMP_Text>();
var settings = new TMP_TextCanvasTypeSettings();
settings.ApplySettings(text, configuration);
- Use consistent naming conventions for TMP text objects to enable automatic theming.
- Store all color values in a configuration file for easy theme changes.
- Register this handler in your canvas settings map to ensure all TMP text components are themed consistently.
- Extend or override for custom text behavior or additional color logic if needed.
- Validate component types in
ApplySettings
to avoid runtime errors.