UnityAppController+ViewHandling.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include "UnityAppController.h"
  3. #include <AvailabilityMacros.h>
  4. @interface UnityAppController (ViewHandling)
  5. // tweaking view hierarchy and handling of orientation
  6. // there are 3 main uses cases regarding UI handling:
  7. //
  8. // 1. normal game case: you shouldnt care about all this at all
  9. //
  10. // 2. you need some not-so-trivial overlayed views and/or minor UI tweaking
  11. // most likely all you need is to subscribe to "orientation changed" notification
  12. // or in case you have per-orientation UI logic override willTransitionToViewController
  13. //
  14. // 3. you create UI-rich app where uinty view is just one of many
  15. // in that case you might want to create your own controllers and implement transitions on top
  16. // also instead of orientUnity: (and Screen.orientation in script) you should use orientInterface
  17. // override this if you need customized unityview (subclassing)
  18. // if you simply want different root view, tweak view hierarchy in createAutorotatingUnityViewController
  19. - (UnityView*)createUnityView;
  20. // for view controllers we discern between platforms that do support orientation (e.g. iOS) and the ones that dont (e.g. tvOS)
  21. // both have concept of "default" view controller: for iOS it will be auto-rotating one (with possible constraints) and "simple" controller otherwise
  22. // in case of supporting orientation we will discern case of fixed-orientation view controller (that seems to be the only way to handle it robustly)
  23. // _unityView will be inited at the point of calling any of "create view controller" methods
  24. // please note that these are actual "create" methods: there is no need to tweak hierarchy right away
  25. - (UIViewController*)createUnityViewControllerDefault;
  26. #if UNITY_SUPPORT_ROTATION
  27. - (UIViewController*)createUnityViewControllerForOrientation:(UIInterfaceOrientation)orient;
  28. #endif
  29. #if UNITY_SUPPORT_ROTATION
  30. // if you override these you need to call super
  31. // if your root controller is not subclassed from UnityViewControllerBase, call these when rotation is happening
  32. - (void)interfaceWillChangeOrientationTo:(UIInterfaceOrientation)toInterfaceOrientation;
  33. - (void)interfaceDidChangeOrientationFrom:(UIInterfaceOrientation)fromInterfaceOrientation;
  34. #endif
  35. // handling of changing ViewControllers:
  36. // willStartWithViewController: will be called on startup, when creating view hierarchy
  37. // transitionToViewController:fromViewController: will be called when user changes Screen.orientation
  38. // and we are forced to change root controller.
  39. // by default:
  40. // willStartWithViewController: will make _unityView as root view
  41. // transitionToViewController:fromViewController: will simply move _rootView to a different controller
  42. // you can use both to tweak view hierarchy if needed
  43. - (void)willStartWithViewController:(UIViewController*)controller;
  44. - (void)willTransitionToViewController:(UIViewController*)toController fromViewController:(UIViewController*)fromController;
  45. // override this if you want to have custom snapshot view.
  46. // by default it will capture the frame drawn inside applicationWillResignActive specifically to let app respond to OnApplicationPause
  47. // will be called on every applicationWillResignActive; returned view will be released in applicationDidBecomeActive
  48. // NB: case of returning nil will be handled gracefully
  49. - (UIView*)createSnapshotView;
  50. // you should not override these methods
  51. // creates initial UI hierarchy (e.g. splash screen) and calls willStartWithViewController
  52. - (void)createUI;
  53. // shows game itself (hides splash, and bring _rootView to front)
  54. - (void)showGameUI;
  55. // returns the topmost presentedViewController if there is one, or just rootViewController
  56. - (UIViewController*)topMostController;
  57. // will create or return from cache correct view controller for requested orientation
  58. - (UIViewController*)createRootViewController;
  59. // old deprecated methods: no longer used
  60. // the caveat is: there are some issues in clang related to method deprecation
  61. // which results in warnings not being generated for overriding deprecated methods (in some circumstances).
  62. // so instead of deprecating these methods we just remove them and will check at runtime if user have them and whine about it
  63. //- (UnityView*)createUnityViewImpl DEPRECATED_MSG_ATTRIBUTE("Will not be called. Override createUnityView");
  64. //- (void)createViewHierarchyImpl DEPRECATED_MSG_ATTRIBUTE("Will not be called. Override willStartWithViewController");
  65. //- (void)createViewHierarchy DEPRECATED_MSG_ATTRIBUTE("Is not implemented. Use createUI");
  66. @end
  67. #if UNITY_SUPPORT_ROTATION
  68. @interface UnityAppController (OrientationSupport)
  69. // will create or return from cache correct view controller for given orientation
  70. - (UIViewController*)createRootViewControllerForOrientation:(UIInterfaceOrientation)orientation;
  71. // forcibly orient interface
  72. - (void)orientInterface:(UIInterfaceOrientation)orient;
  73. // check unity requested orientation and applies it
  74. - (void)checkOrientationRequest;
  75. - (void)orientUnity:(UIInterfaceOrientation)orient __deprecated_msg("use orientInterface instead.");
  76. // force iOS to switch to newly enabled orientation or away from disabled
  77. // orientation. [UIViewController attemptRotationToDeviceOrientation] is
  78. // insufficient for this purpose
  79. - (void)forceAutorotatingControllerToRefreshEnabledOrientationsIfNeeded;
  80. @end
  81. #endif