UnityView+iOS.mm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if PLATFORM_IOS
  2. #import "UnityView.h"
  3. #import "UnityAppController+Rendering.h"
  4. #include "OrientationSupport.h"
  5. extern bool _unityAppReady;
  6. @interface UnityView ()
  7. @property (nonatomic, readwrite) ScreenOrientation contentOrientation;
  8. @end
  9. @implementation UnityView (iOS)
  10. - (void)willRotateToOrientation:(UIInterfaceOrientation)toOrientation fromOrientation:(UIInterfaceOrientation)fromOrientation;
  11. {
  12. // to support the case of interface and unity content orientation being different
  13. // we will cheat a bit:
  14. // we will calculate transform between interface orientations and apply it to unity view orientation
  15. // you can still tweak unity view as you see fit in AppController, but this is what you want in 99% of cases
  16. ScreenOrientation to = ConvertToUnityScreenOrientation(toOrientation);
  17. ScreenOrientation from = ConvertToUnityScreenOrientation(fromOrientation);
  18. if (fromOrientation == UIInterfaceOrientationUnknown)
  19. _curOrientation = to;
  20. else
  21. _curOrientation = OrientationAfterTransform(_curOrientation, TransformBetweenOrientations(from, to));
  22. _viewIsRotating = YES;
  23. }
  24. - (void)didRotate
  25. {
  26. if (_shouldRecreateView)
  27. {
  28. [self recreateRenderingSurface];
  29. }
  30. _viewIsRotating = NO;
  31. }
  32. - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesBegin(touches, event); }
  33. - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesEnded(touches, event); }
  34. - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesCancelled(touches, event); }
  35. - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesMoved(touches, event); }
  36. @end
  37. #endif // PLATFORM_IOS