using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace Michsky.UI.MTP { [RequireComponent(typeof(Animator))] public class StyleManager : MonoBehaviour { public List textItems = new List(); public List imageItems = new List(); public Animator styleAnimator; public AnimationClip inAnim; public AnimationClip outAnim; public bool playOnEnable = true; [Range(0.1f, 2.5f)] public float animationSpeed = 1f; public float showFor = 2.5f; public bool forceUpdate = true; public bool customContent; public bool customizableWidth; public bool customizableHeight; public bool customScale; public bool playOutAnimation = true; public bool disableOnOut = true; public bool loopAnimations; [Range(0.1f, 10f)] public float scale = 1f; public UnityEvent onEnable; public UnityEvent onDisable; private void OnEnable() { if (playOnEnable) { Play(); } } public void Play() { base.gameObject.SetActive(value: true); InitializeSpeedInternal(); PlayIn(); onEnable.Invoke(); if (playOutAnimation) { StartCoroutine("StartTimer"); StartCoroutine("DisableStyle"); } } public void PlayIn() { base.gameObject.SetActive(value: true); StopCoroutine("StartTimer"); StopCoroutine("DisableStyle"); styleAnimator.Rebind(); styleAnimator.Play("In"); } public void PlayOut() { if (!styleAnimator.GetCurrentAnimatorStateInfo(0).IsName("Finished")) { styleAnimator.Play("Out"); } } public void PlayOutAndDisable() { StartCoroutine("StartTimer"); StartCoroutine("DisableStyle"); } private void InitializeSpeedInternal() { styleAnimator.SetFloat("Anim Speed", animationSpeed); } public void InitializeSpeed(float speed) { animationSpeed = speed; styleAnimator.SetFloat("Anim Speed", animationSpeed); } private IEnumerator StartTimer() { yield return new WaitForSeconds(showFor); PlayOut(); if (loopAnimations) { StartCoroutine("DisableStyle"); } } private IEnumerator DisableStyle() { while (!styleAnimator.GetCurrentAnimatorStateInfo(0).IsName("Finished")) { yield return new WaitForSeconds(1f); } if (loopAnimations) { styleAnimator.Play("In"); StartCoroutine("StartTimer"); } else if (styleAnimator.GetCurrentAnimatorStateInfo(0).IsName("Finished")) { onDisable.Invoke(); if (disableOnOut) { base.gameObject.SetActive(value: false); } } } } }