블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00
public class CoroutineHelper : MonoBehaviour
{
    private static MonoBehaviour monoInstance;
    
    [RuntimeInitializeOnLoadMethod]
    private static void Initializer()
    {
        monoInstance = new GameObject($"[{nameof(CoroutineHelper)}]").AddComponent<CoroutineHelper>();
        DontDestroyOnLoad(monoInstance.gameObject);
    }
    
    public new static Coroutine StartCoroutine(IEnumerator coroutine)
    {
        return monoInstance.StartCoroutine(coroutine);
    }

    public new static void StopCoroutine(Coroutine coroutine)
    {
        monoInstance.StopCoroutine(coroutine);
    }
}

 

 

사용법 :

CoroutineHelper.StartCoroutine(코루틴_함수());

CoroutineHelper.StopCoroutine(코루틴);

 

그냥 유니티 생명주기를 가진 한 싱글톤 객체에 코루틴 실행을 몰아주는 방식

가끔 MonoBehaviour 상속 안 받고 코루틴 실행하고 싶을 때가 있는데 그럴때 사용할 수 있을듯..

 

예전에 unirx(MainThreadDispatcher)한 번 사용해본적 있었는데 거기서 아이디어 얻음

 

[출처] https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=66595

 

유니티 MonoBehaviour 상속 안 받고 코루틴 사용하기 - 인디 게임 개발 마이너 갤러리

public class CoroutineHelper : MonoBehaviour{ private static MonoBehaviour monoInstance; [RuntimeInitializeOnLo

gall.dcinside.com

 

반응형
Posted by blueasa
, |