Scripting
Learn more about MTP scripting API.
Workflow
For animation or playback, you can use the functions available in the Style Manager. As long as Force Update is disabled, you can also directly reference the TextMeshPro or Image components and modify them through their APIs.
Code Example
using Michsky.UI.MTP;
using UnityEngine;
public class StyleManagerAdvancedExample : MonoBehaviour
{
[Header("UI Style Manager")]
public StyleManager styleManager;
void Start()
{
// General playback settings
styleManager.loopAnimations = false; // Loop style animations
styleManager.playOnEnable = false; // Play when object is enabled
styleManager.AnimationSpeed = 1.2f; // Speed adjustment
styleManager.showFor = 2.5f; // Delay before out
styleManager.playOutAnimation = true; // Play out animation after showFor
// Disable object after the out animation
styleManager.disableOnOut = true;
// Set whether to use deltaTime or unscaledDeltaTime
styleManager.UseUnscaledTime = true;
// Optional events
styleManager.onEnable.AddListener(() => Debug.Log("Style enabled"));
styleManager.onDisable.AddListener(() => Debug.Log("Style disabled"));
// Trigger animation
styleManager.Play();
}
void Update()
{
// Press Space to toggle In/Out
if (Input.GetKeyDown(KeyCode.Space))
{
if (styleManager.IsPlaying)
styleManager.PlayOut();
else
styleManager.PlayIn();
}
}
}
How can we help?
A premium WordPress theme with an integrated Knowledge Base,
providing 24/7 community-based support.