MyGame.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Urho;
  2. namespace $safeprojectname$
  3. {
  4. public class MyGame : Application
  5. {
  6. public MyGame(Context context) : base(context) {}
  7. public override void Start()
  8. {
  9. CreateScene();
  10. // Subscribe to Esc key:
  11. SubscribeToKeyDown(args => { if (args.Key == Key.Esc) Engine.Exit(); });
  12. }
  13. async void CreateScene()
  14. {
  15. // UI text
  16. var helloText = new Text(Context)
  17. {
  18. Value = "Hello World from $safeprojectname$",
  19. HorizontalAlignment = HorizontalAlignment.Center,
  20. VerticalAlignment = VerticalAlignment.Center
  21. };
  22. helloText.SetColor(new Color(0f, 1f, 1f));
  23. helloText.SetFont(font: ResourceCache.GetFont("Fonts/Font.ttf"), size: 30);
  24. UI.Root.AddChild(helloText);
  25. // 3D scene with Octree
  26. var scene = new Scene(Context);
  27. scene.CreateComponent<Octree>();
  28. // Box
  29. Node boxNode = scene.CreateChild();
  30. boxNode.Position = new Vector3(0, 0, 5);
  31. boxNode.SetScale(0f);
  32. boxNode.Rotation = new Quaternion(60, 0, 30);
  33. StaticModel modelObject = boxNode.CreateComponent<StaticModel>();
  34. modelObject.Model = ResourceCache.GetModel("Models/Box.mdl");
  35. // Light
  36. Node lightNode = scene.CreateChild(name: "light");
  37. lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
  38. lightNode.CreateComponent<Light>();
  39. // Camera
  40. Node cameraNode = scene.CreateChild(name: "camera");
  41. Camera camera = cameraNode.CreateComponent<Camera>();
  42. // Viewport
  43. Renderer.SetViewport(0, new Viewport(Context, scene, camera, null));
  44. // Do actions
  45. await boxNode.RunActionsAsync(new EaseBounceOut(new ScaleTo(duration: 1f, scale: 1)));
  46. await boxNode.RunActionsAsync(new RepeatForever(
  47. new RotateBy(duration: 1, deltaAngleX: 90, deltaAngleY: 0, deltaAngleZ: 0)));
  48. }
  49. }
  50. }