https://docs.unity3d.com/2022.1/Documentation/ScriptReference/MonoBehaviour.OnApplicationFocus.html
Unity - Scripting API: MonoBehaviour.OnApplicationFocus(bool)
OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the arg
docs.unity3d.com
https://docs.unity3d.com/2022.1/Documentation/ScriptReference/MonoBehaviour.OnApplicationPause.html
Unity - Scripting API: MonoBehaviour.OnApplicationPause(bool)
OnApplicationPause is set to true or false. Normally, false is the value returned by the OnApplicationPause message. This means the game is running normally in the editor. If an editor window such as the Inspector is chosen the game is paused and OnApplica
docs.unity3d.com
doc 내용 확인
+
Can somebody explain the OnApplicationPause/Focus scenarios? - Unity Answers
answers.unity.com
Unity Community Answers에 있는 글 중 친절한 내용
->
처음 시작 시 - OnApplicationFocus(true)
이탈 시 - OnApplicationFocus(false), OnApplicationPause(true)
복귀 시 - OnApplicationFocus(true), OnApplicationPause(false)
=>
첫 시작 시 focus가 on이니까 당연히 true로 들어올 것
이탈 시 focus가 out이니까 false로 들어올 것 + pause는 당연히 true 일 것이고.,.,.
아무래도 focus의 경우 시작 시 바로 들어오다 보니 Pause를 더 사용하게 되는 즁
private void OnApplicationPause(bool pause)
{
// 이탈
if (pause == true)
{
}
// 복귀
if (pause == false)
{
}
}
대충 이탈, 복귀 시 할 내용 정리해서 사용하는
+
https://docs.unity3d.com/kr/530/ScriptReference/Application-runInBackground.html
Unity - 스크립팅 API: Application.runInBackground
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. 닫기
docs.unity3d.com
runInBackground의 경우 기본 설정이 false인데 OnApplicationPause의 경우 에디터상에서는 요 녀석이 true면 focus가 나가도 계속 플레이하니까 확인할 수 없어서 false로 그대로 두면 되는데
void 어디든
{
#if UNITY_EDITOR
Application.runInBackground = 상태;
#endif
}
에이터상에서만 테스트가 필요하면 이런 느낌으로 사용해도 될 듯
* PlayerSettings에서도 변경 가능
'Unity > Tips' 카테고리의 다른 글
Unity delegate(대리자)와 Action 간단하지만 명확하게 + 예제 (0) | 2022.01.02 |
---|---|
Unity 메모리 관리 간단한 [ UnloadUnusedAssets(), Singleton 사용 시 ] (0) | 2021.12.16 |
Unity PackageCache 등의 package 오류 (특히 Unity버전 변경 시) (0) | 2021.12.07 |
Unity Script 한글 깨짐 현상 (0) | 2021.12.06 |
Unity 순서대로 초기화하고 싶을 경우 코드를 이런 식으로 ~---~_~-~- (0) | 2021.11.30 |