[Unity] Coroutine에 맡긴 IEnumarator는 재활용할 수 없습니다.
4403 단어 Unity
개요
IEnumerator에는 Reset 메서드가 있습니다.
Coroutine에 맡긴 IEnumarator의 실험을 재활용할 수 있다.
비망록입니다.
컨디션
Unity5.5.2p4
결실
안돼.
뭐, 내가 예상한 대로.
컨텐트
다음 코드는 GameObject와 함께 제공됩니다.
메소드 On Presed Button을 UGUI 버튼 이벤트와 연결합니다.using UnityEngine;
using System.Collections;
public class Test2Coroutine : MonoBehaviour
{
IEnumerator _iEnumerator;
Coroutine _coroutine;
private void Awake()
{
_iEnumerator = Loop();
}
IEnumerator Loop()
{
Debug.LogFormat("[LOOP] Start()");
int i = 0;
while(true)
{
i++;
Debug.LogFormat("[LOOP] i:{0}", i);
yield return null;
}
}
public void OnPressedButton()
{
Debug.LogFormat("Pressed button.");
_iEnumerator.Reset();
if (_coroutine != null)
StopCoroutine(_coroutine);
_coroutine = StartCoroutine(_iEnumerator);
}
}
로그 내용
Pressed button.
NotSupportedException: Operation is not supported.
at My.Test2Coroutine+<Loop>c__Iterator0.Reset () [0x00000]
at My.Test2Coroutine.OnPressedButton () [0x00017]
at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00017]
at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00056]
at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x0000e]
at UnityEngine.Events.UnityEvent.Invoke () [0x00008]
at UnityEngine.UI.Button.Press () [0x00022]
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00012]
at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008]
at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00073]
리스트 등이 소장하고 있는 아이뉴머레이터라면 가능할 것 같다.
예상대로.
Reference
이 문제에 관하여([Unity] Coroutine에 맡긴 IEnumarator는 재활용할 수 없습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/akerusoft/items/1305cf4cd8b65e3333dc
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Unity5.5.2p4
결실
안돼.
뭐, 내가 예상한 대로.
컨텐트
다음 코드는 GameObject와 함께 제공됩니다.
메소드 On Presed Button을 UGUI 버튼 이벤트와 연결합니다.using UnityEngine;
using System.Collections;
public class Test2Coroutine : MonoBehaviour
{
IEnumerator _iEnumerator;
Coroutine _coroutine;
private void Awake()
{
_iEnumerator = Loop();
}
IEnumerator Loop()
{
Debug.LogFormat("[LOOP] Start()");
int i = 0;
while(true)
{
i++;
Debug.LogFormat("[LOOP] i:{0}", i);
yield return null;
}
}
public void OnPressedButton()
{
Debug.LogFormat("Pressed button.");
_iEnumerator.Reset();
if (_coroutine != null)
StopCoroutine(_coroutine);
_coroutine = StartCoroutine(_iEnumerator);
}
}
로그 내용
Pressed button.
NotSupportedException: Operation is not supported.
at My.Test2Coroutine+<Loop>c__Iterator0.Reset () [0x00000]
at My.Test2Coroutine.OnPressedButton () [0x00017]
at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00017]
at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00056]
at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x0000e]
at UnityEngine.Events.UnityEvent.Invoke () [0x00008]
at UnityEngine.UI.Button.Press () [0x00022]
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00012]
at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008]
at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00073]
리스트 등이 소장하고 있는 아이뉴머레이터라면 가능할 것 같다.
예상대로.
Reference
이 문제에 관하여([Unity] Coroutine에 맡긴 IEnumarator는 재활용할 수 없습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/akerusoft/items/1305cf4cd8b65e3333dc
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
다음 코드는 GameObject와 함께 제공됩니다.
메소드 On Presed Button을 UGUI 버튼 이벤트와 연결합니다.
using UnityEngine;
using System.Collections;
public class Test2Coroutine : MonoBehaviour
{
IEnumerator _iEnumerator;
Coroutine _coroutine;
private void Awake()
{
_iEnumerator = Loop();
}
IEnumerator Loop()
{
Debug.LogFormat("[LOOP] Start()");
int i = 0;
while(true)
{
i++;
Debug.LogFormat("[LOOP] i:{0}", i);
yield return null;
}
}
public void OnPressedButton()
{
Debug.LogFormat("Pressed button.");
_iEnumerator.Reset();
if (_coroutine != null)
StopCoroutine(_coroutine);
_coroutine = StartCoroutine(_iEnumerator);
}
}
로그 내용
Pressed button.
NotSupportedException: Operation is not supported.
at My.Test2Coroutine+<Loop>c__Iterator0.Reset () [0x00000]
at My.Test2Coroutine.OnPressedButton () [0x00017]
at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00017]
at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00056]
at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x0000e]
at UnityEngine.Events.UnityEvent.Invoke () [0x00008]
at UnityEngine.UI.Button.Press () [0x00022]
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00012]
at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008]
at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00073]
리스트 등이 소장하고 있는 아이뉴머레이터라면 가능할 것 같다.예상대로.
Reference
이 문제에 관하여([Unity] Coroutine에 맡긴 IEnumarator는 재활용할 수 없습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/akerusoft/items/1305cf4cd8b65e3333dc텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)