ActivityIndicator.mm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "ActivityIndicator.h"
  2. #include "OrientationSupport.h"
  3. @interface ActivityIndicator : UIActivityIndicatorView
  4. {
  5. UIView* _parent;
  6. }
  7. @end
  8. static ActivityIndicator* _activityIndicator = nil;
  9. @implementation ActivityIndicator
  10. - (void)show:(UIView*)parent
  11. {
  12. _parent = parent;
  13. [parent addSubview: self];
  14. [self startAnimating];
  15. }
  16. - (void)layoutSubviews
  17. {
  18. self.center = CGPointMake([_parent bounds].size.width / 2, [_parent bounds].size.height / 2);
  19. }
  20. @end
  21. void ShowActivityIndicator(UIView* parent, int style)
  22. {
  23. if (_activityIndicator != nil)
  24. return;
  25. if (style >= 0)
  26. {
  27. _activityIndicator = [[ActivityIndicator alloc] initWithActivityIndicatorStyle: (UIActivityIndicatorViewStyle)style];
  28. #if !PLATFORM_VISIONOS
  29. _activityIndicator.contentScaleFactor = [UIScreen mainScreen].scale;
  30. #endif
  31. }
  32. if (_activityIndicator != nil)
  33. [_activityIndicator show: parent];
  34. }
  35. void ShowActivityIndicator(UIView* parent)
  36. {
  37. ShowActivityIndicator(parent, UnityGetShowActivityIndicatorOnLoading());
  38. }
  39. void HideActivityIndicator()
  40. {
  41. if (_activityIndicator)
  42. {
  43. [_activityIndicator stopAnimating];
  44. [_activityIndicator removeFromSuperview];
  45. _activityIndicator = nil;
  46. }
  47. }
  48. extern "C" void UnityStartActivityIndicator()
  49. {
  50. // AppleTV does not support activity indicators
  51. ShowActivityIndicator(UnityGetGLView());
  52. }
  53. extern "C" void UnityStopActivityIndicator()
  54. {
  55. HideActivityIndicator();
  56. }