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번 출력된다.
'프로그램 공부 > Unity 함수' 카테고리의 다른 글
이벤트 콜백 함수 (0) | 2023.12.31 |
---|---|
EditorSceneManager : 에디터에 있는 씬매니저 클래스 (0) | 2023.12.31 |
[InitializeOnLoad] : 유니티 시작시 스크립트 실행 (1) | 2023.12.31 |
특정시간을 주고 호출되는 함수 만들기 (0) | 2019.08.08 |
[Range(Min, Max)] (0) | 2019.07.11 |