public Gui() { var cache = Application.Current.ResourceCache; statusText = Application.Current.UI.Root.CreateText(); statusText.HorizontalAlignment = HorizontalAlignment.Center; statusText.VerticalAlignment = VerticalAlignment.Center; statusText.SetFont(cache.GetFont("Fonts/OpenSans-Bold.ttf"), 24); debugText = Application.Current.UI.Root.CreateText(); debugText.HorizontalAlignment = HorizontalAlignment.Left; debugText.VerticalAlignment = VerticalAlignment.Bottom; debugText.SetFont(cache.GetFont("Fonts/OpenSans-Light.ttf"), 12); debugHud = Application.Current.Engine.CreateDebugHud(); debugHud.DefaultStyle = cache.GetXmlFile("UI/DefaultStyle.xml"); Application.Current.Input.Enabled = true; Application.Current.Input.KeyDown += (e) => { switch (e.Key) { case Key.F2: debugHud.ToggleAll(); break; } }; }
protected override void Start() { base.Start(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { var child = Scene.CreateChild(); child.SetScale(0.05f); var sphere = child.CreateComponent <Box>(); //sphere.Model = ResourceCache.GetModel("Sphere.mdl"); var mat = Material.FromColor(Randoms.NextColor()); sphere.SetMaterial(mat); child.Position = new Vector3(i * 0.12f, j * 0.12f, 1 + k * 0.12f); } } } Time.FrameEnded += Time_FrameEnded; new MonoDebugHud(this) { FpsOnly = true }.Show(Color.Green, 72); hud = Engine.CreateDebugHud(); hud.ToggleAll(); }
protected override async void Start() { base.Start(); new MonoDebugHud(this) { FpsOnly = true }.Show(Color.Green, 50); debugHud = Engine.CreateDebugHud(); debugHud.ToggleAll(); environmentNode = Scene.CreateChild(); EnableGestureTapped = true; spatMaterial = new Material(); spatMaterial.SetTechnique(0, CoreAssets.Techniques.NoTexture, 1, 1); spatMaterial.SetShaderParameter("MatDiffColor", Color.Cyan); // make sure 'spatialMapping' capabilaty is enabled in the app manifest. var cortanaAllowed = await RegisterCortanaCommands(new Dictionary <string, Action> { { "show results", ShowResults } }); var spatialMappingAllowed = await StartSpatialMapping(new Vector3(50, 50, 50), color : Color.Yellow); }
protected override void Start() { Log.LogLevel = LogLevel.Debug; ResourceCache.AutoReloadResources = true; var xml = ResourceCache.GetXmlFile("UI/DefaultStyle.xml"); console = Engine.CreateConsole(); console.DefaultStyle = xml; console.Background.Opacity = 0.8f; debugHud = Engine.CreateDebugHud(); debugHud.DefaultStyle = xml; var hud = new MonoDebugHud(this); CreateScene(null); Input.KeyDown += OnKeyDown; Input.MouseWheel += OnMouseWheel; Input.MouseMoved += OnMouseMoved; Engine.PostRenderUpdate += args => { if (DrawDebugFrame) { Renderer.DrawDebugGeometry(false); } }; }
void CreateConsoleAndDebugHud() { var xml = cache.GetXmlFile("UI/DefaultStyle.xml"); console = Engine.CreateConsole(); console.DefaultStyle = xml; console.Background.Opacity = 0.8f; debugHud = Engine.CreateDebugHud(); debugHud.DefaultStyle = xml; }
public override void Start() { Context.Input.SetMouseVisible(true); SetupResourcePaths(); Selection = new Engn_Selection(); SetupScene(); SubscribeEvents(); InitializeTcpConnection(); DebugHud debugHud = Engine.CreateDebugHud(); debugHud.Mode = DebugHudMode.DebughudShowAll; RunOnce(); }
/*void HandleUpdate(StringHash eventType, IntPtr eventData) * { * VariantMap map = new VariantMap(eventData); * Console.WriteLine(eventType.Value == StringHash.Calculate("Update")); * Console.WriteLine("UPDATE " + map["TimeStep"].Value.Float + "s"); * * Input input = GetSubsystem<Input>(); * if (input.GetKeyPress(Keys.F2)) * { * DebugHud debugHud = GetSubsystem<DebugHud>(); * debugHud.ToggleAll(); * } * * //GC.Collect(); * }*/ public override void Start() { Log.Write(LogLevel.LOG_INFO, "!!!!!!!!!!!!!!!!!!!!! Start()"); Input input = context_.GetSubsystem <Input>(); //input.SetMouseMode(MouseMode.Free); //input.SetMouseVisible(true); Engine engine = context_.GetSubsystem <Engine>(); DebugHud debugHud = engine.CreateDebugHud(); ResourceCache cache = GetSubsystem <ResourceCache>(); XMLFile xmlFile = cache.GetResource <XMLFile>("UI/DefaultStyle.xml"); debugHud.SetDefaultStyle(xmlFile); debugHud.ToggleAll(); //GC.Collect(); // FOR TEST ONLY CreateLogo(); }
protected override void Start() { base.Start(); Engine.PostRenderUpdate += Engine_PostRenderUpdate; DisplayScene = new PulsarScene("MainScene", this) { InDesign = InDesign }; //create a default plane to work on DisplayScene.CreateWirePlane(); SetViewport(); UI.Cursor = new Cursor(Context) { Visible = true }; _debugHud = new DebugHud(Context); }
public override void Start() { UI ui = Context.GetSubsystem <UI>(); var uiStyle = Context.Cache.GetResource <XMLFile>("UI/DefaultStyle.xml"); ui.Root.SetDefaultStyle(uiStyle); ui.Cursor = new Cursor(Context); ui.Cursor.SetDefaultStyle(uiStyle); var text = new Text(Context); text.SetText("test"); ui.Root.AddChild(text); // Viewport _scene = new Scene(Context); _scene.Name = "_scene"; //_scene.LoadFile("Test/Scenes/ThreeScene.xml"); _scene.CreateComponent <PhysicsWorld>(); _scene.CreateComponent <Octree>(); var zone = _scene.CreateComponent <Zone>(); zone.SetBoundingBox(new BoundingBox(-30, 3200)); zone.FogStart = 200f; zone.FogEnd = 300f; var _c = new Color(43 / 255f, 43 / 255f, 43 / 255f, 0.7f); //zone.AmbientColor = _c; zone.FogColor = _c; _light = _scene.CreateChild("DirectionalLight"); _light.SetWorldPosition(new Vector3(0, 10, -10)); _light.SetDirection(new Vector3(-2, -2, 1)); var light = _light.CreateComponent <Light>(); light.Color = Color.White; light.CastShadows = true; light.ShadowCascade = new CascadeParameters(50, 0, 0, 0, 0.9f); //_light.Brightness = 1; light.SetLightMode(LightMode.LmRealtime); light.LightType = LightType.LightDirectional; #region Character /* * var character = _scene.CreateChild("character"); * _body = character.CreateComponent<RigidBody>(); * _body.CollisionLayer = 1u; * _body.SetKinematic(true); * _body.SetTrigger(true); * _body.SetAngularFactor(Vector3.Zero); * _body.CollisionEventMode = CollisionEventMode.CollisionAlways; * * _shape = character.CreateComponent<CollisionShape>(); * _shape.SetCapsule(0.7f, 1.8f, new Vector3(0.0f, 0.9f, 0.0f)); * * _characterController = character.CreateComponent<KinematicCharacterController>(); */ #endregion _cameraRoot = _scene.CreateChild("Camera Pivot", CreateMode.Replicated); _cameraRoot.Position = new Vector3(0, 0, 0); _camera = _cameraRoot.CreateChild("Main Camera", CreateMode.Replicated); _camera.Position = StartPositionCamera; //_camera.LookAt(new Vector3(6, 0, 6), Vector3.Up); _viewport = new Viewport(Context); _viewport.Scene = _scene; _viewport.Camera = (Camera)_camera.GetOrCreateComponent((StringHash)typeof(Camera).Name); _viewport.Camera.FarClip = 350f; _viewport.Camera.Fov = 45f; _viewport.Camera.NearClip = 0.01f; Context.Renderer.SetViewport(0, _viewport); #region WindowsSystem stateSystem = new StateMachineSystem(); windows = new WindowsSystem(this); #endregion #region Mouse Context.Input.SetMouseVisible(true); Context.Input.SetMouseGrabbed(false); Context.Input.SetMouseMode(MouseMode.MmFree); Context.Input.SetMousePosition(new IntVector2(Context.Graphics.Width / 2, Context.Graphics.Height / 2)); //Context.Input.SetMouseMode(MouseMode.MmRelative, false); #endregion _debugHud = Context.Engine.CreateDebugHud(); _debugHud.Mode = DebugHudMode.DebughudShowAll; windows.SetCamera(_camera, _viewport.Camera); #region InitMap LogInfo("Dirs:"); foreach (string d in Context.Cache.ResourceDirs) { LogInfo(string.Format("Dir: {0}", d)); } var _platforms = new Platforms(EnumPlatform.PC); _ufs = new UniversalFileSystem(_platforms, this); //_material = Context.Cache.GetResource<Material>("n_sector/materials/m_blocks.xml", true); //_material.Name = "blocks"; int blockID = 7; LogInfo($"blockID:{blockID}, value:{blockID % 16}"); //CreateStaticModelBlock(_model, vertexData, indexData, _material, blockID, new BoundingBox(-0.5f, 0.5f)); //var sb = Dump(_scene); LogInfo(sb.ToString()); #endregion _debugRenderer = _scene.CreateComponent <DebugRenderer>(); stateSystem.onSpaceKeyChangeState += OnChangeSpaceKeyState; level = new Level("level1", 10, 10); gridNode = _scene.CreateChild("grid"); gridMaterial = GetCache().GetResource <Material>("UI/Materials/Grid.xml"); //gridMaterial.FillMode = FillMode.FillWireframe; int[] id = { 0, 1, 2, 3, 4, 5 }; float[] vd = { //front 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0, 10, //0 0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 1.0f, 0, 0, //1 10.0f, 0.0f, 10.0f, 0.0f, 0.0f, 1.0f, 10, 0, //2 10.0f, 0.0f, 10.0f, 0.0f, 0.0f, 1.0f, 10, 0, //2 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 10, 10, //3 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0, 10, //0 }; var model = CreateModel(vd, id, new BoundingBox(0, 10)); var staticModel = CreateStaticModel(gridNode, model, gridMaterial); #region Update SubscribeToEvent(E.Update, args => { var timestep = args[E.Update.TimeStep].Float; Debug.Assert(this != null); int xx = (int)_camera.Position.X / 16; int yy = (int)_camera.Position.Z / 16; if (Context.Input.GetKeyDown(Key.KeyEscape)) { Context.Engine.Exit(); } //ShowGrid(); ShowMenu(); if (isShowing) { if (ImGui.Begin("Urho3D.NET")) { ImGui.TextColored(Color.White, $"chunk:{xx}_{yy}\n" + $"pos:{_camera.Position.X},{_camera.Position.Y},{_camera.Position.Z}\n" + $"rotXYZ:{_camera.Rotation.EulerAngles.X},{_camera.Rotation.EulerAngles.Y},{_camera.Rotation.EulerAngles.Z}\n" + $"pos:{ui.CursorPosition.X},{ui.CursorPosition.Y}\n" + $"Frame time: {timestep}, \n"); if (ImGui.Button("Exit")) { Context.Engine.Exit(); } } ImGui.End(); } var isMoving = false; if (Context.Input.GetMouseButtonDown(MouseButton.MousebRight)) { if (!isMoving) { Context.Input.SetMouseVisible(false); Context.Input.SetMouseGrabbed(true); Context.Input.SetMouseMode(MouseMode.MmRelative, true); angleX = _camera.Rotation.EulerAngles.X; angleY = _camera.Rotation.EulerAngles.Y; } isMoving = true; } if (isMoving) { var scaleSpeed = 20f; var mouseSensivity = 20f; Vector3 moveDirection = Vector3.Zero; float moveX = 0; float moveY = 0; if (Context.Input.GetKeyDown(Key.KeyW)) { moveY = 1; } if (Context.Input.GetKeyDown(Key.KeyS)) { moveY = -1; } if (Context.Input.GetKeyDown(Key.KeyA)) { moveX = -1; } if (Context.Input.GetKeyDown(Key.KeyD)) { moveX = 1; } moveDirection = moveX * scaleSpeed * _camera.Right * timestep + moveY * scaleSpeed * _camera.Direction * timestep; _camera.Position += moveDirection; IntVector2 vec = Context.Input.MouseMove; if (timestep > 0.01f) { timestep = 0.01f; } angleY += vec.X * mouseSensivity * timestep; angleX += vec.Y * mouseSensivity * timestep; _camera.Rotation = new Quaternion(new Vector3(angleX, angleY, 0)); /**/ } else { if (Context.Input.IsMouseGrabbed()) { Context.Input.SetMouseGrabbed(false); Context.Input.SetMouseVisible(true); Context.Input.SetMouseMode(MouseMode.MmFree); } } windows.InputUpdate(timestep); }); #endregion } private void OnChangeSpaceKeyState(bool value) { if (value) { isShowing = !isShowing; } } private void ShowMenu() { if (ImGui.BeginMainMenuBar()) { if (ImGui.BeginMenu("File")) { if (ImGui.MenuItem("Open", "Ctrl+O")) /* Do stuff */ } { if (ImGui.MenuItem("Save", "Ctrl+S")) /* Do stuff */ { } if (ImGui.MenuItem("Close", "Ctrl+W")) { isShowing = false; } ImGui.EndMenu(); } if (ImGui.BeginMenu("Create")) { if (ImGui.MenuItem("Terrain", "Ctrl+T")) { // } ImGui.EndMenu(); } ImGui.EndMenuBar(); } }