| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Urho;
- using Urho.Gui;
- using Urho.Actions;
- using Urho.Shapes;
- namespace $safeprojectname$
- {
- public class MyGame : Application
- {
- public MyGame() : base(new ApplicationOptions { })
- {
- }
- protected override void Start()
- {
- CreateScene();
- // Subscribe to Esc key:
- Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc) Engine.Exit(); });
- }
- async void CreateScene()
- {
- // UI text
- var helloText = new Text(Context);
- helloText.Value = "Hello World from UrhoSharp";
- helloText.HorizontalAlignment = HorizontalAlignment.Center;
- helloText.VerticalAlignment = VerticalAlignment.Top;
- helloText.SetColor(new Color(r: 0f, g: 1f, b: 1f));
- helloText.SetFont(font: ResourceCache.GetFont("Fonts/Font.ttf"), size: 30);
- UI.Root.AddChild(helloText);
- // 3D scene with Octree
- var scene = new Scene(Context);
- scene.CreateComponent<Octree>();
- // Box
- Node boxNode = scene.CreateChild(name: "Box node");
- boxNode.Position = new Vector3(x: 0, y: 0, z: 5);
- boxNode.SetScale(0f);
- boxNode.Rotation = new Quaternion(x: 60, y: 0, z: 30);
- StaticModel boxModel = boxNode.CreateComponent<StaticModel>();
- boxModel.Model = ResourceCache.GetModel("Models/Box.mdl");
- boxModel.SetMaterial(ResourceCache.GetMaterial("Materials/BoxMaterial.xml"));
-
- // Light
- Node lightNode = scene.CreateChild(name: "light");
- var light = lightNode.CreateComponent<Light>();
- light.Range = 10;
- light.Brightness = 1.5f;
- // Camera
- Node cameraNode = scene.CreateChild(name: "camera");
- Camera camera = cameraNode.CreateComponent<Camera>();
- // Viewport
- Renderer.SetViewport(0, new Viewport(Context, scene, camera, null));
- // Do actions
- await boxNode.RunActionsAsync(new EaseBounceOut(new ScaleTo(duration: 1f, scale: 1)));
- await boxNode.RunActionsAsync(new RepeatForever(
- new RotateBy(duration: 1, deltaAngleX: 90, deltaAngleY: 0, deltaAngleZ: 0)));
- }
- }
- }
|