ActivityIndicator.mm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. _activityIndicator.contentScaleFactor = [UIScreen mainScreen].scale;
  29. }
  30. if (_activityIndicator != nil)
  31. [_activityIndicator show: parent];
  32. }
  33. void ShowActivityIndicator(UIView* parent)
  34. {
  35. ShowActivityIndicator(parent, UnityGetShowActivityIndicatorOnLoading());
  36. }
  37. void HideActivityIndicator()
  38. {
  39. if (_activityIndicator)
  40. {
  41. [_activityIndicator stopAnimating];
  42. [_activityIndicator removeFromSuperview];
  43. _activityIndicator = nil;
  44. }
  45. }
  46. extern "C" void UnityStartActivityIndicator()
  47. {
  48. // AppleTV does not support activity indicators
  49. ShowActivityIndicator(UnityGetGLView());
  50. }
  51. extern "C" void UnityStopActivityIndicator()
  52. {
  53. HideActivityIndicator();
  54. }