UnityAppController+ViewHandling.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 unity 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. // willTransitionToViewController:fromViewController: didTransitionToViewController:fromViewController:
  38. // are called before/after we are doing some magic to switch to new root controller due to forced orientation change
  39. // by default:
  40. // willStartWithViewController: will make _unityView as root view
  41. // willTransitionToViewController:fromViewController: will do nothing
  42. // didTransitionToViewController:fromViewController: will send orientation events to unity view
  43. // you can use them to tweak view hierarchy if needed
  44. - (void)willStartWithViewController:(UIViewController*)controller;
  45. - (void)willTransitionToViewController:(UIViewController*)toController fromViewController:(UIViewController*)fromController;
  46. - (void)didTransitionToViewController:(UIViewController*)toController fromViewController:(UIViewController*)fromController;
  47. // override this if you want to have custom snapshot view.
  48. // by default it will capture the frame drawn inside applicationWillResignActive specifically to let app respond to OnApplicationPause
  49. // will be called on every applicationWillResignActive; returned view will be released in applicationDidBecomeActive
  50. // NB: case of returning nil will be handled gracefully
  51. - (UIView*)createSnapshotView;
  52. // you should not override these methods
  53. // creates initial UI hierarchy (e.g. splash screen) and calls willStartWithViewController
  54. - (void)createUI;
  55. // shows game itself (hides splash, and bring _rootView to front)
  56. - (void)showGameUI;
  57. // returns the topmost presentedViewController if there is one, or just rootViewController
  58. - (UIViewController*)topMostController;
  59. // will create or return from cache correct view controller for requested orientation
  60. - (UIViewController*)createRootViewController;
  61. // old deprecated methods: no longer used
  62. // the caveat is: there are some issues in clang related to method deprecation
  63. // which results in warnings not being generated for overriding deprecated methods (in some circumstances).
  64. // so instead of deprecating these methods we just remove them and will check at runtime if user have them and whine about it
  65. //- (UnityView*)createUnityViewImpl DEPRECATED_MSG_ATTRIBUTE("Will not be called. Override createUnityView");
  66. //- (void)createViewHierarchyImpl DEPRECATED_MSG_ATTRIBUTE("Will not be called. Override willStartWithViewController");
  67. //- (void)createViewHierarchy DEPRECATED_MSG_ATTRIBUTE("Is not implemented. Use createUI");
  68. @end
  69. #if UNITY_SUPPORT_ROTATION
  70. @interface UnityAppController (OrientationSupport)
  71. // will create or return from cache correct view controller for given orientation
  72. - (UIViewController*)createRootViewControllerForOrientation:(UIInterfaceOrientation)orientation;
  73. // forcibly orient interface
  74. - (void)orientInterface:(UIInterfaceOrientation)orient;
  75. // check unity requested orientation and applies it
  76. - (void)checkOrientationRequest;
  77. - (void)orientUnity:(UIInterfaceOrientation)orient __deprecated_msg("use orientInterface instead.");
  78. @end
  79. #endif