Hi people. The problem has arisen.
There is Spine animation on canvas and asynchronous level loading.
It is necessary to ensure that the animation plays during the loading of the scene (tips for the game will still be shown in the cloud),
and now the animation starts after loading the scene.
VIDEO
the first script (hangs on the LoadingPlane component)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class LoadingHelper : Singleton<LoadingHelper>
{
[SerializeField] GameObject _panel;
[SerializeField] private Slider _progressSlider;
[SerializeField] private TextMeshProUGUI _progressText;
[SerializeField] private float _pause;
public void LoadScene(int sceneID)
{
_panel.SetActive(true);
StartCoroutine(AsyncLoad());
IEnumerator AsyncLoad()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneID);
StartCoroutine(Pausing());
while (!operation.isDone)
{
float progress = operation.progress / .9f;
_progressSlider.value = progress;
_progressText.text = $"Загружено {progress * 100} %";
yield return null;
}
StartCoroutine(Pausing());
//_panel.SetActive(false);
}
IEnumerator Pausing()
{
yield return new WaitForSeconds(_pause);
StopCoroutine(Pausing());
}
}
}
Second script that starts the animation (Hangs on Plane, turns on OnEnable when the loading bar appears)
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
[RequireComponent(typeof(Animator),typeof(SkeletonGraphic))]
public class LoadingAntsAnimations : MonoBehaviour
{
private SkeletonGraphic _anim;
private SkeletonDataAsset _asset;
private void Awake()
{
_asset = GetComponent<SkeletonGraphic>().skeletonDataAsset;
_anim = GetComponent<SkeletonGraphic>();
}
public void OnEnable()
{
SetAnimation();
}
private async void SetAnimation()
{
await Task.Run(()=>
{
_anim.Skeleton.SetSkin("Running");
_anim.Skeleton.SetSlotsToSetupPose();
_anim.AnimationState.SetAnimation(0, "run", true);
_anim.Update(0);
});
}
}