我在文档中找不到任何可以破坏场景加载过程以及如何确定response.css("a._b >span::text").extract()
属性的内容。
我需要模拟大型场景加载,并且找不到找到延迟场景加载的方法。了解流程非常有用,尤其是在需要在场景中加载外部资产并且仅将场景标记为通过代码加载时。
答案 0 :(得分:1)
您应该查看SceneManager.LoadSceneAsync
,尤其是allowSceneActivation
,它可以使您做到这一点:延迟场景加载,例如同时显示加载屏幕。
文档示例:
<script>
$(document).on("click", "#save", function(e) {
let url = "{{route('product.store')}}";
e.preventDefault();
$.ajax({
type: "post",
url: url,
data: $(".add-productForm").serialize(),
success: function(store) {
},
error: function() {
}
});
});
</script>
也结帐sceneLoaded
:如文档
为此添加一个委托,以在加载场景时获得通知。
发生这种情况是在场景加载完毕并且afaik在 之后// This script lets you load a Scene asynchronously.
// It uses an asyncOperation to calculate the progress and outputs
// the current progress to Text (could also be used to make progress bars).
// Attach this script to a GameObject
// Create a Button (Create>UI>Button) and a Text GameObject (Create>UI>Text)
// and attach them both to the Inspector of your GameObject
//In Play Mode, press your Button to load the Scene, and the Text
// changes depending on progress. Press the space key to activate the Scene.
//Note: The progress may look like it goes straight to 100% if your Scene doesn’t have a lot to load.
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class AsyncOperationProgressExample : MonoBehaviour
{
public Text m_Text;
public Button m_Button;
void Start()
{
//Call the LoadButton() function when the user clicks this Button
m_Button.onClick.AddListener(LoadButton);
}
void LoadButton()
{
//Start loading the Scene asynchronously and output the progress bar
StartCoroutine(LoadScene());
}
IEnumerator LoadScene()
{
yield return null;
//Begin to load the Scene you specify
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Scene3");
//Don't let the Scene activate until you allow it to
asyncOperation.allowSceneActivation = false;
Debug.Log("Pro :" + asyncOperation.progress);
//When the load is still in progress, output the Text and progress bar
while (!asyncOperation.isDone)
{
//Output the current progress
m_Text.text = "Loading progress: " + (asyncOperation.progress * 100) + "%";
// Check if the load has finished
if (asyncOperation.progress >= 0.9f)
{
//Change the Text to show the Scene is ready
m_Text.text = "Press the space bar to continue";
//Wait to you press the space key to activate the Scene
if (Input.GetKeyDown(KeyCode.Space))
//Activate the Scene
asyncOperation.allowSceneActivation = true;
}
yield return null;
}
}
}
调用完成之后发生的。您可以使用类似
Awake
您将同时看到
public class Test : MonoBehaviour
{
private void Awake()
{
Debug.Log("Awake");
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Debug.Log("OnSceneLoaded");
}
}
在控制台中进行调试,这意味着Awake
OnSceneLoaded
在Awake
之前被调用。
→此时,我还希望Scene.isLoaded
设置为true。