FirstViewController.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using CoreGraphics;
  3. using UIKit;
  4. using Urho;
  5. using Urho.iOS;
  6. namespace Playgrounds.iOS
  7. {
  8. public partial class FirstViewController : UIViewController
  9. {
  10. UrhoSurface urhoSurface;
  11. Game game;
  12. protected FirstViewController(IntPtr handle) : base(handle)
  13. {
  14. }
  15. public override async void ViewDidLoad()
  16. {
  17. base.ViewDidLoad();
  18. // Restart button
  19. UIButton restartBtn = new UIButton(UIButtonType.RoundedRect);
  20. restartBtn.Frame = new CGRect(10f, 0f, 50, 50f);
  21. restartBtn.SetTitle("Restart", UIControlState.Normal);
  22. restartBtn.TouchUpInside += async (sender, e) => game = await urhoSurface.Show<Game>(new ApplicationOptions());
  23. View.AddSubview(restartBtn);
  24. // Stop button
  25. UIButton stopBtn = new UIButton(UIButtonType.RoundedRect);
  26. stopBtn.Frame = new CGRect(75f, 0f, 50, 50f);
  27. stopBtn.SetTitle("Stop", UIControlState.Normal);
  28. stopBtn.TouchUpInside += (sender, e) =>
  29. {
  30. urhoSurface.Stop();
  31. game = null;
  32. };
  33. View.AddSubview(stopBtn);
  34. // Spawn button
  35. UIButton spawnBtn = new UIButton(UIButtonType.RoundedRect);
  36. spawnBtn.Frame = new CGRect(135f, 0f, 50, 50f);
  37. spawnBtn.SetTitle("Spawn", UIControlState.Normal);
  38. spawnBtn.TouchUpInside += (sender, e) =>
  39. {
  40. if (game != null)
  41. Urho.Application.InvokeOnMain(() => game?.SpawnRandomShape());
  42. };
  43. View.AddSubview(spawnBtn);
  44. // Pause/Unpause button
  45. UIButton pauseBtn = new UIButton(UIButtonType.RoundedRect);
  46. pauseBtn.Frame = new CGRect(200f, 0f, 80, 50f);
  47. pauseBtn.SetTitle("(Un)pause", UIControlState.Normal);
  48. pauseBtn.TouchUpInside += (sender, e) => urhoSurface.Paused = !urhoSurface.Paused;
  49. View.AddSubview(pauseBtn);
  50. urhoSurface = new UrhoSurface();
  51. urhoSurface.Frame = new CoreGraphics.CGRect(0, 50, View.Bounds.Width, View.Bounds.Height - 50);
  52. urhoSurface.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
  53. View.Add(urhoSurface);
  54. }
  55. public override void DidReceiveMemoryWarning()
  56. {
  57. base.DidReceiveMemoryWarning();
  58. // Release any cached data, images, etc that aren't in use.
  59. }
  60. }
  61. }