Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¡¡ºÇ½é¤Ë³Ð¤¨¤ëÈóƱ´ü½èÍý¤Ë¤Ä¤¤¤Æ¤Ï¥³¥ë¡¼¥Á¥ó¤¬¤¢¤ê¤Þ¤¹¡£
¤È¤Æ¤âÊØÍø¤Ê½èÍý¤Ç¤¹¤¬¡¢UniTask ¤È¤¤¤¦Ê̤ÎÈóƱ´ü½èÍý¤âÍÑ°Õ¤µ¤ì¤Æ¤Þ¤¹¡£

¡¡Î¾Êý¤Î»È¤¤Êý¤òÍý²ò¤¹¤ë¤³¤È¤Ç¡¢¾å¼ê¤Ë»È¤¤Ê¬¤±¤Æ¤¤¤¯¤³¤È¤¬½ÐÍè¤Þ¤¹¤Î¤Ç¡¢
¤³¤³¤Ç¤Ï¡¢¤³¤ì¤«¤é UniTask ¤ò³Ð¤¨¤Æ¤¤¤­¤¿¤¤Êý¸þ¤±¤Ë½èÍý¤òÈæ³Ó¤·¤Æ¡¢ÃÖ¤­´¹¤¨¤Ê¤¬¤é UniTask ¤ò³Ø½¬¤·¤Þ¤¹¡£

¡¡¤Ê¤ª¡¢¡Ö¤½¤â¤½¤â UniTask ¤È¤Ï¡©¡×¤È¤¤¤¦Éôʬ¤Ë¤Ä¤¤¤Æ¤Ï¿¨¤ì¤Þ¤»¤ó¡£

¡¡UniTask ¤ò³Ø½¬¤·¤Æ¤ß¤¿¤¤¤±¤É¡¢¤É¤Î¤è¤¦¤Ë¼ÂÁõ¤·¤Æ¤¤¤¤¤Î¤«¡¢Æ³Æþ¤Î»å¸ý¤¬¸«Åö¤¿¤é¤Ê¤¤¤È¤¤¤¦Êý¤òÂоݤȤ·¤Æ¤¤¤Þ¤¹¡£



£±¡¥ÈóƱ´ü½èÍý¤Î°ã¤¤


¡¡ÈóƱ´ü½èÍý¤Ë¤Ä¤¤¤Æ¡¢½èÍý¤òÈæ³Ó¤·¡¢°ã¤¤¤ò¸«¤Ê¤¬¤é³Ø½¬¤·¤Þ¤·¤ç¤¦¡£


£±¡¥¥³¥ë¡¼¥Á¥ó


¡¡¥³¥ë¡¼¥Á¥ó¤ò¥¹¥¿¡¼¥È¤·¡¢»þ´Ö¤Î·Ð²á¤Ë¹ç¤ï¤»¤Æ¥í¥°¤òɽ¼¨¤·¤Þ¤¹¡£

using System.Collections;
using UnityEngine;

public class CoroutineExample : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(MyCoroutine());
    }

    private IEnumerator MyCoroutine()
    {
        Debug.Log("Coroutine Started");
        yield return new WaitForSeconds(2.0f);
        Debug.Log("Coroutine Finished");
    }
}


£²¡¥UniTask


¡¡¤³¤³¤Ç¤ÏÀè¤Û¤É¤Î¥³¥ë¡¼¥Á¥ó¤Î½èÍý¤ò UniTask ¤òÍøÍѤ·¤ÆÃÖ¤­´¹¤¨¤¿¾ì¹ç¤Î¼ÂÁõÎã¤Ç¤¹¡£

using Cysharp.Threading.Tasks;
using UnityEngine;

public class UniTaskExample : MonoBehaviour
{
    private async void Start()
    {
        Debug.Log("UniTask Started");
        await UniTask.Delay(TimeSpan.FromSeconds(2));
        Debug.Log("UniTask Finished");
    }
}


£³¡¥½èÍý¤Î½ñ¤­Êý¤ÎÈæ³Ó


¡¡ÈóƱ´ü½èÍý¤Ë¤Ä¤¤¤Æ¡¢¥³¥ë¡¼¥Á¥ó¤È UniTask ¤ò¡¢½ñ¤­Êý¤ÇÈæ³Ó¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
Àè¤Ë¥³¥ë¡¼¥Á¥ó¤Î½èÍý¤òÄ󼨤·¡¢¤½¤Î¸å¡¢Æ±¤¸ÆâÍƤò UniTask ¤ÇºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£


using System.Collections;
using UnityEngine;

public class CoroutineExample : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(MyCoroutine());
    }

    private IEnumerator MyCoroutine()
    {
        Debug.Log("Coroutine Started");
        yield return new WaitForSeconds(2.0f);
        Debug.Log("Waited for 2 seconds in Coroutine");
        
        yield return new WaitForEndOfFrame(); // ¸½ºß¤Î¥Õ¥ì¡¼¥à¤Î½ªÎ»¤òÂÔ¤Ä
        Debug.Log("Waited for EndOfFrame in Coroutine");
        
        yield return new WaitForFixedUpdate(); // ¼¡¤ÎFixedUpdate¤òÂÔ¤Ä
        Debug.Log("Waited for FixedUpdate in Coroutine");
        
        yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Space)); // ¾ò·ï¤¬Ëþ¤¿¤µ¤ì¤ë¤Þ¤ÇÂÔ¤Ä
        Debug.Log("Waited until Space key is pressed in Coroutine");
        
        yield return null; // 1¥Õ¥ì¡¼¥àÂÔµ¡
        Debug.Log("Waited for 1 frame in Coroutine");
    }
}



¡¡¤³¤³¤«¤é¤Ï UniTask ¤Î¾ì¹ç¤Ç¤¹¡£


using Cysharp.Threading.Tasks;
using UnityEngine;

public class UniTaskExample : MonoBehaviour
{
    private async void Start()
    {
        Debug.Log("UniTask Started");
        await UniTask.Delay(TimeSpan.FromSeconds(2));
        Debug.Log("Waited for 2 seconds in UniTask");
        
        await UniTask.NextFrame(); // ¸½ºß¤Î¥Õ¥ì¡¼¥à¤Î½ªÎ»¤òÂÔ¤Ä
        Debug.Log("Waited for EndOfFrame in UniTask");
        
        await UniTask.WaitForFixedUpdate(); // ¼¡¤ÎFixedUpdate¤òÂÔ¤Ä
        Debug.Log("Waited for FixedUpdate in UniTask");
        
        await UniTask.WaitUntil(() => Input.GetKeyDown(KeyCode.Space)); // ¾ò·ï¤¬Ëþ¤¿¤µ¤ì¤ë¤Þ¤ÇÂÔ¤Ä
        Debug.Log("Waited until Space key is pressed in UniTask");
        
        await UniTask.Yield(PlayerLoopTiming.PostLateUpdate); // 1¥Õ¥ì¡¼¥àÂÔµ¡
        Debug.Log("Waited for 1 frame in UniTask");
    }
}

¡¡¤É¤Á¤é¤âƱ¤¸¤è¤¦¤ËÈóƱ´ü½èÍý¤¬ºîÀ®¤Ç¤­¤Þ¤¹¡£


£´¡¥¥Ý¥¤¥ó¥È

¡¡
¡¡¥³¥ë¡¼¥Á¥ó¤ÈUniTask¤ÎÈóƱ´ü½èÍý¤Ë¤Ï¡¢½ñ¤­Êý¤À¤±¤Ç¤Ê¤¯¡¢¤¤¤¯¤Ä¤«¤Î½ÅÍפʰ㤤¤¬Â¸ºß¤·¤Þ¤¹¡£

¡¡°Ê²¼¤Ë¡¢¤½¤ì¤é¤Î°ã¤¤¤ò¤Þ¤È¤á¤Þ¤¹¡£


£±¡¥Ìá¤êÃͤΰ㤤

¡¡¡ã¥³¥ë¡¼¥Á¥ó¡ä

¡¡¡¡¥³¥ë¡¼¥Á¥ó¤ÏIEnumerator·¿¤òÌá¤êÃͤȤ·¤Æ»ý¤Á¡¢¥³¥ë¡¼¥Á¥óÆâ¤Çyield return¥¹¥Æ¡¼¥È¥á¥ó¥È¤ò»ÈÍѤ·¤ÆÈóƱ´ü½èÍý¤òɽ¸½¤·¤Þ¤¹¡£
¡¡¡¡¼ÂºÝ¤Î·ë²Ì¤òÊÖ¤¹¤Î¤ÏÆñ¤·¤¤¤¿¤á¡¢Ä̾ï¤Ï¥³¥ë¡¼¥Á¥ó¼«ÂΤ¬¾õÂÖ¤òÄÉÀפ¹¤ëÌÜŪ¤Ë»ÈÍѤµ¤ì¤Þ¤¹¡£

¡¡¡ãUniTask¡ä
¡¡¡¡¡¡
¡¡¡¡UniTask¤ÏUniTask·¿¤òÌá¤êÃͤȤ·¤Æ»ý¤Á¡¢ÈóƱ´ü½èÍý¤¬´°Î»¤·¤¿·ë²Ì¤ò»ý¤Ä¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢ÈóƱ´ü½èÍý¤Î·ë²Ì¤ò´Êñ¤Ë¼èÆÀ¤Ç¤­¤Þ¤¹¡£


£²¡¥ÂÔµ¡Á°Äó¤Î°ã¤¤

¡¡¡ã¥³¥ë¡¼¥Á¥ó¡ä

¡¡¡¡¥³¥ë¡¼¥Á¥ó¤ÏÌÀ¼¨Åª¤Êyield return¥¹¥Æ¡¼¥È¥á¥ó¥È¤ò»ÈÍѤ·¤ÆÂÔµ¡¤òɽ¸½¤·¡¢¥³¡¼¥É¤ÎÆÃÄê¤Î¥Ý¥¤¥ó¥È¤Ç½èÍý¤¬°ì»þÄä»ß¤µ¤ì¤Þ¤¹¡£
¡¡¡¡¥³¥ë¡¼¥Á¥óÆâ¤Î½èÍý¤ÏÄ̾ïÂÔµ¡¥¹¥Æ¡¼¥È¥á¥ó¥È¤Î¼þ¤ê¤ËÁȤ߹þ¤Þ¤ì¤Þ¤¹¡£

¡¡¡ãUniTask¡ä

¡¡¡¡¡¡UniTask¤Ç¤Ï¡¢ÈóƱ´ü¥á¥½¥Ã¥É¤òawait¤¹¤ë¤³¤È¤Ë¤è¤Ã¤ÆÂÔµ¡¤òɽ¸½¤·¤Þ¤¹¡£
¡¡¡¡¡¡ÂÔµ¡¤ÏÈóƱ´ü½èÍý¤Î°ìÉô¤È¤·¤Æ¼«Á³¤Ê·Á¤ÇÁȤ߹þ¤Þ¤ì¡¢¥³¡¼¥É¤ÎľÎ󲽤¬ÍưפǤ¹¡£


£³¡¥Îã³°½èÍý¤Î°ã¤¤

¡¡¡ã¥³¥ë¡¼¥Á¥ó¡ä

¡¡¡¡¡¡¥³¥ë¡¼¥Á¥óÆâ¤ÇÎã³°¤¬¥¹¥í¡¼¤µ¤ì¤ë¤È¡¢Unity¥¨¥Ç¥£¥¿Æâ¤Ç¥¨¥é¡¼¥í¥°¤¬É½¼¨¤µ¤ì¤Þ¤¹¤¬¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥óÁ´ÂΤˤÏÇȵڤ·¤Þ¤»¤ó¡£


¡¡¡ãUniTask¡ä

¡¡¡¡¡¡UniTask¤Ïtry...catch¥Ö¥í¥Ã¥¯¤ò»ÈÍѤ·¤ÆÎã³°½èÍý¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¡¢Îã³°¤ò¥­¥ã¥Ã¥Á¤·¤ÆŬÀڤʽèÍý¤ò¼Â¹Ô¤Ç¤­¤Þ¤¹¡£
¡¡¡¡¡¡UniTask¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥óÁ´ÂΤÎÎã³°¥Ï¥ó¥É¥ê¥ó¥°¤ò¥µ¥Ý¡¼¥È¤·¤ä¤¹¤¤´Ä¶­¤Ë¤¢¤ê¤Þ¤¹¡£


£´¡¥ÈóƱ´ü½èÍý¤ÎÀ­Ç½

¡¡UniTask¤ÏÆâÉôŪ¤Ë¹âÅÙ¤ÊÈóƱ´ü¥é¥¤¥Ö¥é¥ê¤ò»ÈÍѤ·¡¢¥³¥ë¡¼¥Á¥ó¤è¤ê¤â¹âÀ­Ç½¤Ç¸úΨŪ¤Ç¤¹¡£
¡¡UniTask¤Ï¤è¤ê¾¯¤Ê¤¤¥ª¡¼¥Ð¡¼¥Ø¥Ã¥É¤ò»ý¤Á¡¢¥á¥â¥ê¸úΨ¤¬¹â¤¤¤¿¤á¡¢Â¿¤¯¤Î¾ìÌ̤ǥ³¥ë¡¼¥Á¥ó¤è¤ê¤â¹¥¤Þ¤·¤¤ÁªÂò»è¤È¤Ê¤ê¤Þ¤¹¡£


£²¡¥¥¨¥é¡¼¥Ï¥ó¥É¥ê¥ó¥°


¡¡¥¨¥é¡¼¥Ï¥ó¥É¥ê¥ó¥°¤Ë¤Ä¤¤¤Æ¡¢Èæ³Ó¤·¤Ê¤¬¤é³Ø½¬¤·¤Þ¤¹¡£


£±¡¥¥³¥ë¡¼¥Á¥ó¤Î¾ì¹ç



using System.Collections;
using UnityEngine;

public class CoroutineErrorHandling : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(MyCoroutine());
    }

    private IEnumerator MyCoroutine()
    {
        Debug.Log("Coroutine Started");
        yield return new WaitForSeconds(2.0f);
        Debug.LogError("Coroutine Error");
    }
}


£²¡¥UniTask¤Î¾ì¹ç



using Cysharp.Threading.Tasks;
using UnityEngine;

public class UniTaskErrorHandling : MonoBehaviour
{
    private async void Start()
    {
        Debug.Log("UniTask Started");
        await UniTask.Delay(TimeSpan.FromSeconds(2));
        Debug.LogError("UniTask Error");
    }
}


£³¡¥ ¥­¥ã¥ó¥»¥ë²Äǽ¤Ê¥¿¥¹¥¯


¡¡UniTask¤Ï¥³¥ë¡¼¥Á¥ó¤è¤ê¤â´Êñ¤Ë¥­¥ã¥ó¥»¥ë¤Ç¤­¤Þ¤¹¤¬¡¢¥³¥ë¡¼¥Á¥ó¤Ç¤Ï¥­¥ã¥ó¥»¥ë¤¬Æñ¤·¤¤¤Ç¤¹¡£



£±¡¥¥³¥ë¡¼¥Á¥ó¤Î¾ì¹ç



using System.Collections;
using UnityEngine;

public class CoroutineCancellationExample : MonoBehaviour
{
    private Coroutine myCoroutine;

    private void Start()
    {
        myCoroutine = StartCoroutine(MyCoroutine());
        // 2Éøå¤Ë¥³¥ë¡¼¥Á¥ó¤ò¥­¥ã¥ó¥»¥ë
        StartCoroutine(CancelCoroutineAfterDelay(2.0f));
    }

    private IEnumerator MyCoroutine()
    {
        Debug.Log("Coroutine Started");
        while (true)
        {
            yield return null;
        }
    }

    private IEnumerator CancelCoroutineAfterDelay(float delay)
    {
        yield return new WaitForSeconds(delay);
        StopCoroutine(myCoroutine); // ¥³¥ë¡¼¥Á¥ó¤ò¥­¥ã¥ó¥»¥ë
        Debug.Log("Coroutine Canceled");
    }
}


£²¡¥UniTask¤Î¾ì¹ç



using Cysharp.Threading.Tasks;
using UnityEngine;

public class UniTaskCancellationExample : MonoBehaviour
{
    private async void Start()
    {
        // UniTask¤ò»ÈÍѤ·¤ÆÈóƱ´ü¥¿¥¹¥¯¤ò³«»Ï
        var task = MyUniTask();
        
        // 2Éøå¤Ë¥¿¥¹¥¯¤ò¥­¥ã¥ó¥»¥ë
        await UniTask.Delay(2000);
        task.Cancel();
        Debug.Log("UniTask Canceled");
    }

    private async UniTask MyUniTask()
    {
        Debug.Log("UniTask Started");
        while (true)
        {
            await UniTask.Yield();
        }
    }
}

¡¡¤³¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ç¤Ï¡¢¥³¥ë¡¼¥Á¥ó¤ÈUniTask¤Î¥­¥ã¥ó¥»¥ë²Äǽ¤Ê¥¿¥¹¥¯¤Î°ã¤¤¤ò¼¨¤·¤Æ¤¤¤Þ¤¹¡£

¡¡¥³¥ë¡¼¥Á¥ó¤Î¾ì¹ç¡¢¥­¥ã¥ó¥»¥ë¤ò¼ÂÁõ¤¹¤ë¤Î¤ËÄÉ²Ã¤Î¥í¥¸¥Ã¥¯¤¬É¬Íפǡ¢StopCoroutine¤ò»ÈÍѤ·¤Æ¥³¥ë¡¼¥Á¥ó¤ò¥­¥ã¥ó¥»¥ë¤·¤Þ¤¹¡£

¡¡°ìÊý¡¢UniTask¤Ç¤Ïawait¤ÎÂå¤ï¤ê¤Ëtask.Cancel()¤ò»ÈÍѤ·¤Æ´Êñ¤Ë¥¿¥¹¥¯¤ò¥­¥ã¥ó¥»¥ë¤Ç¤­¤Þ¤¹¡£

¡¡¤½¤¦¤¤¤Ã¤¿ÅÀ¤Ë¤ª¤¤¤Æ¤â¡¢UniTask¤Ï¥­¥ã¥ó¥»¥ë²Äǽ¤Ê¥¿¥¹¥¯¤ò´ÉÍý¤·¤ä¤¹¤¯¡¢¥³¡¼¥É¤ò¤è¤ê¥·¥ó¥×¥ë¤ËÊݤÁ¤Þ¤¹¡£


£´¡¥Ê£¿ô¤ÎÈóƱ´ü½èÍý¤ÎÂÔµ¡


¡¡¤³¤³¤Ç¤â¤½¤ì¤¾¤ì¤Î½ñ¤­Êý¤òÈæ³Ó¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
¡¡

£±¡¥¥³¥ë¡¼¥Á¥ó¤Î¾ì¹ç


using System.Collections;
using UnityEngine;

public class CoroutineMultipleTasks : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(DoMultipleTasks());
    }

    private IEnumerator DoMultipleTasks()
    {
        Debug.Log("Coroutine Started");
        yield return StartCoroutine(Task1());
        yield return StartCoroutine(Task2());
        Debug.Log("All Coroutine Tasks Finished");
    }

    private IEnumerator Task1()
    {
        yield return new WaitForSeconds(2.0f);
        Debug.Log("Coroutine Task 1 Finished");
    }

    private IEnumerator Task2()
    {
        yield return new WaitForSeconds(1.0f);
        Debug.Log("Coroutine Task 2 Finished");
    }
}


£²¡¥UniTask¤Î¾ì¹ç


using Cysharp.Threading.Tasks;
using UnityEngine;

public class UniTaskMultipleTasks : MonoBehaviour
{
    private async void Start()
    {
        Debug.Log("UniTask Started");
        await Task1().ToUniTask();
        await Task2().ToUniTask();
        Debug.Log("All UniTask Tasks Finished");
    }

    private async UniTaskVoid Task1()
    {
        await UniTask.Delay(TimeSpan.FromSeconds(2));
        Debug.Log("UniTask Task 1 Finished");
    }

    private async UniTaskVoid Task2()
    {
        await UniTask.Delay(TimeSpan.FromSeconds(1));
        Debug.Log("UniTask Task 2 Finished");
    }
}

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹