Last active
April 24, 2023 19:18
-
-
Save skatamatic/9bbafb6eee88520d1437c1e7bad3fc7b to your computer and use it in GitHub Desktop.
UUM-9480 Workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
@interface UnityView (iOS) | |
// will simply update content orientation (it might be tweaked in layoutSubviews, due to disagreement between unity and view controller) | |
- (void)willRotateToOrientation:(UIInterfaceOrientation)toOrientation fromOrientation:(UIInterfaceOrientation)fromOrientation; | |
// will recreate gles backing if needed and repaint once to make sure we dont have black frame creeping in | |
- (void)didRotate; | |
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event; | |
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event; | |
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event; | |
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event; | |
- (BOOL)is10thGenIpad; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if PLATFORM_IOS | |
#import "UnityView.h" | |
#import "UnityAppController+Rendering.h" | |
#include "OrientationSupport.h" | |
extern bool _unityAppReady; | |
@interface UnityView () | |
@property (nonatomic, readwrite) ScreenOrientation contentOrientation; | |
@end | |
@implementation UnityView (iOS) | |
- (void)willRotateToOrientation:(UIInterfaceOrientation)toOrientation fromOrientation:(UIInterfaceOrientation)fromOrientation; | |
{ | |
// to support the case of interface and unity content orientation being different | |
// we will cheat a bit: | |
// we will calculate transform between interface orientations and apply it to unity view orientation | |
// you can still tweak unity view as you see fit in AppController, but this is what you want in 99% of cases | |
ScreenOrientation to = ConvertToUnityScreenOrientation(toOrientation); | |
ScreenOrientation from = ConvertToUnityScreenOrientation(fromOrientation); | |
if (fromOrientation == UIInterfaceOrientationUnknown) | |
_curOrientation = to; | |
else | |
_curOrientation = OrientationAfterTransform(_curOrientation, TransformBetweenOrientations(from, to)); | |
_viewIsRotating = YES; | |
} | |
- (void)didRotate | |
{ | |
BOOL is10thGenIpad = [self is10thGenIpad]; | |
//https://issuetracker.unity3d.com/issues/ios-rendering-freezes-when-the-orientation-is-changed | |
//Theres a bug in 10th gen ipads that fails to load the proper dimensions at the right time | |
//so _shouldRecreateView never gets set. Short circuit that here. Side effects may be we | |
//recreate the rendering surface more often than we should when rotating | |
//Moreover, a long delay is required upon rotation. Haven't tracked down why, but without approx | |
//500ms sleep above the rendering will stop working seemingly at the OS level (even minimizing the | |
//app takes 10+ seconds to refresh) | |
if (is10thGenIpad) | |
{ | |
[NSThread sleepForTimeInterval:0.5f]; | |
} | |
if (_shouldRecreateView || is10thGenIpad) | |
{ | |
[self recreateRenderingSurface]; | |
} | |
_viewIsRotating = NO; | |
} | |
- (BOOL) is10thGenIpad | |
{ | |
static BOOL hasCheckedIf10thGen = NO; | |
static BOOL is10thGen = NO; | |
if (hasCheckedIf10thGen) | |
return is10thGen; | |
NSString * modelStr = [NSString stringWithUTF8String:UnityDeviceModel()]; | |
is10thGen = [modelStr hasPrefix:@"iPad13,"]; | |
hasCheckedIf10thGen = true; | |
return is10thGen; | |
} | |
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesBegin(touches, event); } | |
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesEnded(touches, event); } | |
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesCancelled(touches, event); } | |
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesMoved(touches, event); } | |
@end | |
#endif // PLATFORM_IOS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment