feat: added mouse positioner behaviour

This commit is contained in:
2026-01-28 11:20:38 +03:00
parent 9141bb5aa1
commit d71882c8e7
3 changed files with 31 additions and 3 deletions

2
Engine

Submodule Engine updated: 985f898327...ad444decbb

View File

@@ -0,0 +1,21 @@
using Microsoft.Xna.Framework.Input;
using Engine.Core;
using Engine.Integration.MonoGame;
namespace MyUniverse.Shared.Behaviours;
public class MousePositionerBehaviour : Behaviour2D, IUpdate, IFirstFrameUpdate
{
private ICamera2D camera = null!;
public void FirstActiveFrame()
{
camera = Universe.FindRequiredBehaviour<ICamera2D>();
}
public void Update()
{
Transform.Position = camera.ScreenToWorldPosition(Mouse.GetState().Position.ToVector2D());
}
}

View File

@@ -37,8 +37,14 @@ public static class UniverseSource
public static void ApplyUniverse(IUniverse universe) public static void ApplyUniverse(IUniverse universe)
{ {
IUniverseObject exampleObject = universe.InstantiateUniverseObject().SetUniverseObject("Example Object"); universe.InstantiateUniverseObject().SetUniverseObject("Example Object")
ExampleBehaviour exampleBehaviour = exampleObject.BehaviourController.AddBehaviour<ExampleBehaviour>(); .BehaviourController.AddBehaviour<ExampleBehaviour>();
universe.InstantiateUniverseObject().SetUniverseObject("MouseObject")
.BehaviourController.AddBehaviour<Transform2D>()
.BehaviourController.AddBehaviour<LinearRotator>()
.BehaviourController.AddBehaviour<MousePositionerBehaviour>()
.BehaviourController.AddBehaviour<DrawableShape2D>(Shape2D.CreateNgon(4), new ColorRGB(255, 255, 0)).Priority = 10;
universe.InstantiateUniverseObject() universe.InstantiateUniverseObject()
.SetUniverseObject("Rotating Triangle") .SetUniverseObject("Rotating Triangle")
@@ -51,6 +57,7 @@ public static class UniverseSource
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(10f, -6f), scale: Vector2D.One * 5) .BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(10f, -6f), scale: Vector2D.One * 5)
.BehaviourController.AddBehaviour<DrawableShape2D>(Shape2D.Pentagon, new ColorRGB(128, 0, 128)) .BehaviourController.AddBehaviour<DrawableShape2D>(Shape2D.Pentagon, new ColorRGB(128, 0, 128))
.BehaviourController.AddBehaviour<TweenRotator>(); .BehaviourController.AddBehaviour<TweenRotator>();
universe.InstantiateUniverseObject() universe.InstantiateUniverseObject()
.SetUniverseObject("Rotating Triangle") .SetUniverseObject("Rotating Triangle")
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(-10f, 6f), scale: Vector2D.One * 5) .BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(-10f, 6f), scale: Vector2D.One * 5)