Assets > Plugins > IOS에 AppPauseHandler.mm 파일을 추가한다.
#import <UIKit/UIKit.h>
@interface AppPauseHandler : NSObject
@end
@implementation AppPauseHandler
+ (void)load {
// 백그라운드로 전환될 때 실행
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillResignActive)
name:UIApplicationWillResignActiveNotification
object:nil];
// 다시 포커스를 얻을 때 실행
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
+ (void)appWillResignActive {
// 유니티 화면을 덮을 검은색 뷰 추가
UIView *blackView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
blackView.backgroundColor = [UIColor blackColor];
blackView.tag = 9999; // 태그 추가 (나중에 제거하기 위함)
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (window) {
[window addSubview:blackView];
}
});
}
+ (void)appDidBecomeActive {
// 다시 게임으로 돌아올 때 검은 화면 제거
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIView *blackView = [window viewWithTag:9999];
if (blackView) {
[blackView removeFromSuperview];
}
});
}
@end
이렇게 하면 포커스를 잃었을 때 검은 화면이 나오고, 다시 포커스 찾았을때 복구된다.
'Unity' 카테고리의 다른 글
[ Unity ] scrollbar 위, 아래로 내리기. value 숫자 범위 0~1 아닐때 (0) | 2025.02.06 |
---|---|
[ Unity ] 해상도 조절 후 뒷배경 잔상. 레터박스 잔상과 플리커 현상 (0) | 2025.01.26 |
[ Unity3d ] Off Mesh Link 자동으로 링크 생성안될 때 (0) | 2025.01.23 |
[ Unity ] 동적 목록 스크롤뷰 가장 아래로 내리기 (0) | 2024.11.23 |
[ Unity ] 갑자기 xcode 안열릴때 반응 없을때 (0) | 2024.10.25 |