Halaman ini menjelaskan fitur yang didukung saat menjalankan Editor Unity dan Pemain Standalone dalam mode batch.
Ketika menjalankan Unity, operator built-in coroutine berikut menambahkan fungsi:
Tabel berikut menunjukkan mana dari operator ini Unity mendukung di dalam Editor dan Standalone Player, dan ketika menjalankan masing-masing dalam mode batch menggunakan argumen baris perintah -batchmode:
Editor | WordPress.org | Pemain Standalone Unity | WordPress.org | |
---|---|---|---|---|
AsyncOperation |
Yes | Yes | Yes | Yes |
WaitForEndOfFrame |
Yes | No* | Yes | Yes |
WaitForFixedUpdate |
Yes | Yes | Yes | Yes |
WaitForSeconds |
Yes | Yes | Yes | Yes |
WaitForSecondsRealtime |
Yes | Yes | Yes | Yes |
WaitUntil |
Yes | Yes | Yes | Yes |
WaitWhile |
Yes | Yes | Yes | Yes |
Sitemap Anda tidak dapat menggunakan WaitForEndOfFrame
ketika menjalankan Editor dengan -batchmode
, karena sistem seperti animasi, fisika dan timeline mungkin tidak bekerja dengan benar di Editor. Ini karena Unity tidak saat ini memperbarui sistem ini saat menggunakan WaitForEndOfFrame
.
Di Editor, tekan tombol “Play” untuk menjalankan kode Anda dengan koroutines.
Untuk menjalankan koroutines ketika meluncurkan Editor dalam mode batch dari baris perintah, masukkan:
C:\Program Files\Unity\Editor\Unity.exe -projectPath PROJECT_PATH -batchMode
Luncurkan Pemain Anda untuk menjalankan kode Anda. Pemain memuat dan kemudian menunggu koroutin Anda untuk menyelesaikan.
Untuk menjalankan koroutines ketika meluncurkan Pemain dalam mode batch dari baris perintah, masukkan:
PATH_TO_STANDALONE_BUILD -projectPath PROJECT_PATH -batchMode
Contohnya, di Windows:
C:\projects\myproject\builds\myproject.exe -batchMode
Di Mac:
Sitemap -batchMode
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_AsyncTests());
}
public IEnumerator Example_AsyncTests()
{
Debug.Log("Start of AsyncLoad Example");
var load = UnityEngine.Resources.LoadAsync("");
yield return load;
yield return null;
Debug.Log("End of AsyncLoad Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForEndOfFrame_Coroutine());
}
public IEnumerator Example_WaitForEndOfFrame_Coroutine()
{
Debug.Log("Start of WaitForEndOfFrame Example");
yield return new WaitForEndOfFrame();
Debug.Log("End of WaitForEndOfFrame Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForFixedUpdate_Coroutine());
}
public IEnumerator Example_WaitForFixedUpdate_Coroutine()
{
Debug.Log("Start of WaitForFixedUpdate Example");
yield return new WaitForFixedUpdate();
Debug.Log("End of WaitForFixedUpdate Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForSeconds_Coroutine());
}
public IEnumerator Example_WaitForSeconds_Coroutine()
{
Debug.Log("Start of WaitForSeconds Example");
yield return new WaitForSeconds(1.5f);
Debug.Log("End of WaitForSeconds Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitForSecondsRealtime_Coroutine());
}
public IEnumerator Example_WaitForSecondsRealtime_Coroutine()
{
Debug.Log("Start of WaitForSecondsRealtime Example");
yield return new WaitForSecondsRealtime(1.5f);
Debug.Log("End of WaitForSecondsRealtime Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitUntil_Coroutine());
}
public IEnumerator Example_WaitUntil_Coroutine()
{
Debug.Log("Start of WaitUntil Example");
yield return new WaitUntil(() => Time.time > 5.0f);
Debug.Log("End of WaitUntil Example");
}
}
using System.Collections;
using UnityEngine;
[ExecuteInEditMode]
public class ExampleClass : MonoBehaviour
{
public void Start()
{
StartCoroutine(Example_WaitWhile_Coroutine());
}
public IEnumerator Example_WaitWhile_Coroutine()
{
Debug.Log("Start of WaitWhile Example");
yield return new WaitWhile(() => Time.time < 5.0f);
Debug.Log("End of WaitWhile Example");
}
}
2018–06–06 Sitemap
Menambahkan saran tentang menggunakan batchmode dan koroutines di 2017. 4 Artikel