UnityViewControllerBase.mm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #import "UnityViewControllerBase.h"
  2. #import "UnityAppController.h"
  3. #import "UnityAppController+ViewHandling.h"
  4. #include "OrientationSupport.h"
  5. @implementation UnityViewControllerBase
  6. @synthesize notificationDelegate = _notificationDelegate;
  7. - (id)init
  8. {
  9. if ((self = [super init]))
  10. self.modalPresentationStyle = UIModalPresentationFullScreen;
  11. return self;
  12. }
  13. - (void)viewWillLayoutSubviews
  14. {
  15. [super viewWillLayoutSubviews];
  16. [_notificationDelegate onViewWillLayoutSubviews];
  17. }
  18. - (void)viewDidLayoutSubviews
  19. {
  20. [super viewDidLayoutSubviews];
  21. [_notificationDelegate onViewDidLayoutSubviews];
  22. }
  23. - (void)viewDidDisappear:(BOOL)animated
  24. {
  25. [super viewDidDisappear: animated];
  26. [_notificationDelegate onViewDidDisappear: animated];
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated
  29. {
  30. [super viewWillDisappear: animated];
  31. [_notificationDelegate onViewWillDisappear: animated];
  32. }
  33. - (void)viewDidAppear:(BOOL)animated
  34. {
  35. [super viewDidAppear: animated];
  36. [_notificationDelegate onViewDidAppear: animated];
  37. }
  38. - (void)viewWillAppear:(BOOL)animated
  39. {
  40. [super viewWillAppear: animated];
  41. [_notificationDelegate onViewWillAppear: animated];
  42. }
  43. @end
  44. UnityViewControllerBase* AllocUnityDefaultViewController()
  45. {
  46. return [UnityDefaultViewController alloc];
  47. }
  48. #if UNITY_SUPPORT_ROTATION
  49. UnityViewControllerBase* AllocUnitySingleOrientationViewController(UIInterfaceOrientation orient)
  50. {
  51. switch (orient)
  52. {
  53. case UIInterfaceOrientationPortrait: return [UnityPortraitOnlyViewController alloc];
  54. case UIInterfaceOrientationPortraitUpsideDown: return [UnityPortraitUpsideDownOnlyViewController alloc];
  55. case UIInterfaceOrientationLandscapeLeft: return [UnityLandscapeLeftOnlyViewController alloc];
  56. case UIInterfaceOrientationLandscapeRight: return [UnityLandscapeRightOnlyViewController alloc];
  57. default: assert(false && "bad UIInterfaceOrientation provided");
  58. }
  59. return nil;
  60. }
  61. #endif
  62. UnityViewControllerBase* AllocUnityViewController()
  63. {
  64. #if UNITY_SUPPORT_ROTATION
  65. if (UnityShouldAutorotate())
  66. return AllocUnityDefaultViewController();
  67. UIInterfaceOrientation orient = ConvertToIosScreenOrientation((ScreenOrientation)UnityRequestedScreenOrientation());
  68. return AllocUnitySingleOrientationViewController(orient);
  69. #else
  70. return AllocUnityDefaultViewController();
  71. #endif
  72. }