NightKot

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.



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);

});
}
}
NightKot
  • 記事: 10

Harald

First of all, please add triple-backticks before and after code sections to format it properly:
```
or surround it with
[code]code goes here[/code]
Your above posting is very hard to read in this form.

Regarding your problem: It seems as if you are encountering a general problem with Unity's async calls here or a similar logic problem. I'm afraid this is not related to the spine-unity runtime, so the best we can do is suggest to debug your code and check when each method gets called.
アバター
Harald

Harri
  • 記事: 3353

NightKot

I was afraid of this ... The problem is at the junction of Spine and Unity. Tell me, and ... something like a frame-by-frame yeld return can help resolve the issue?
NightKot
  • 記事: 10

Harald

NightKot さんが書きました:Tell me, and ... something like a frame-by-frame yeld return can help resolve the issue?
I'm not sure I understand this sentence correctly. If you are asking whether replacing an async call with yield return .. based coroutine calls: It could perhaps be easier for you to implement, yes.

In general you need to debug your application if it does not do what you want, either via "printf-debugging" by adding Log statements, or by attaching e.g. the Visual Studio debugger and placing breakpoints at the interesting locations.

Apart from that, I see no reason why you are calling SetAnimation() in an async way, you just need to start the animation, also no need to update it, the SkeletonAnimation component will do that automatically.
アバター
Harald

Harri
  • 記事: 3353


Return to Unity