MainActivity.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Android.App;
  2. using Android.Content.PM;
  3. using Android.Views;
  4. using Android.Widget;
  5. using Android.OS;
  6. using Org.Libsdl.App;
  7. using Urho;
  8. using Urho.Droid;
  9. namespace $safeprojectname$
  10. {
  11. [Activity(Label = "$safeprojectname$", MainLauncher = true,
  12. Icon = "@drawable/icon", Theme = "@android:style/Theme.NoTitleBar.Fullscreen",
  13. ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation,
  14. ScreenOrientation = ScreenOrientation.Landscape)]
  15. public class MainActivity : Activity
  16. {
  17. MyGame myGame;
  18. UrhoSurfacePlaceholder surface;
  19. protected override async void OnCreate(Bundle bundle)
  20. {
  21. base.OnCreate(bundle);
  22. var layout = new FrameLayout(this);
  23. surface = UrhoSurface.CreateSurface(this);
  24. layout.AddView(surface);
  25. SetContentView(layout);
  26. myGame = await surface.Show<MyGame>(new ApplicationOptions("MyData"));
  27. //to stop the game use await surface.Stop().
  28. }
  29. protected override void OnResume()
  30. {
  31. UrhoSurface.OnResume();
  32. base.OnResume();
  33. }
  34. protected override void OnPause()
  35. {
  36. UrhoSurface.OnPause();
  37. base.OnPause();
  38. }
  39. public override void OnLowMemory()
  40. {
  41. UrhoSurface.OnLowMemory();
  42. base.OnLowMemory();
  43. }
  44. protected override void OnDestroy()
  45. {
  46. UrhoSurface.OnDestroy();
  47. base.OnDestroy();
  48. }
  49. public override bool DispatchKeyEvent(KeyEvent e)
  50. {
  51. if (e.KeyCode == Android.Views.Keycode.Back)
  52. {
  53. this.Finish();
  54. return false;
  55. }
  56. return base.DispatchKeyEvent(e);
  57. }
  58. public override void OnWindowFocusChanged(bool hasFocus)
  59. {
  60. UrhoSurface.OnWindowFocusChanged(hasFocus);
  61. base.OnWindowFocusChanged(hasFocus);
  62. }
  63. }
  64. }