프로그램 공부/Unity 함수
EditorApplication : Unity 에디터에 대한 클래스
프로그램 호랭
2023. 12. 31. 01:43
using UnityEditor;
- EditorApplication.playmodeStateChanged
: 에디터에서 플레이를 감지하고 이벤트 함수를 호출한다.
람다식으로 함수를 넣고빼며 사용한다. (+= / -=)
(playModeStateChanged랑 헷갈리지 않기)
using UnityEditor;
using UnityEngine;
using UnityEditor;
public class TestScript : MonoBehaviour
{
private void Awake()
{
EditorApplication.playmodeStateChanged += testA;
EditorApplication.playmodeStateChanged += testB;
}
static void testA()
{
Debug.Log("A");
}
static void testB()
{
Debug.Log("B");
}
}
|
=> 에디터가 켜꺼질때, 재생이 시작될때, 일시정지를 누를때, 일시정지를 끌때, 재생을 끌때, 에디터가 꺼질때 마다
한번씩 실행이 된다.
에디터 켜짐(A,B) → 재생시작(A,B) → 일시정지 누름(A,B) → 일시정지를 끔(A,B) → 재생을끔(A,B) →에디터가 꺼짐(A,B)
A,B순으로 총 6번 출력된다.
- EditorApplication.isPlaying
: 에디터가 현재 켜져있는지 확인할수 있는 함수 (Bool값)
using UnityEngine;
using UnityEditor;
public class Test_InitializeOnLoad : MonoBehaviour
{
private void Awake()
{
EditorApplication.playmodeStateChanged += testA;
EditorApplication.playmodeStateChanged += testB;
}
static void testA()
{
if (EditorApplication.isPlaying)
Debug.Log("A");
}
static void testB()
{
Debug.Log("B");
}
}
|
testA는 에디터가 재생중일때만 출력된다.
에디터 켜짐(B) → 재생시작(A,B) → 일시정지 누름(A,B) → 일시정지를 끔(A,B) → 재생을끔(A,B) →에디터가 꺼짐(B)
A는 총 4번,B는 총 6번 출력된다.