UnityView+iOS.mm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }
  23. - (void)didRotate
  24. {
  25. if (_shouldRecreateView)
  26. {
  27. // we are not inside repaint so we need to draw second time ourselves
  28. [self recreateRenderingSurface];
  29. if (_unityAppReady && !UnityIsPaused())
  30. UnityRepaint();
  31. }
  32. }
  33. - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesBegin(touches, event); }
  34. - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesEnded(touches, event); }
  35. - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesCancelled(touches, event); }
  36. - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UnitySendTouchesMoved(touches, event); }
  37. @end
  38. #endif // PLATFORM_IOS