[英]Adding functionality to an Entity/Component System
I'm attempting to write my own Entity/Component System from scratch in C# and I'm stuck on where/how to implement some functionality. 我试图用C#从头开始编写自己的实体/组件系统,而我却在哪里/如何实现某些功能方面陷入困境。
Edit: I figured out how where I'm going to add functions like Move() and Jump(). 编辑:我想出了如何在其中添加Move()和Jump()之类的函数。
public static class Actions
{
public static void MoveUp(EntityManager entityManager, int EGUID) {}
public static void MoveDown(EntityManager entityManage, int EGUID {}
}
I can add them to a collection like so: 我可以像这样将它们添加到集合中:
KeyboardController kbController = entityManager.GetComponent<KeyboardController(1);
kbController.KeyBindings.Add(Keys.Right, new Dictionary<KeyStateES, Action<EntityManager, int>());
kbController.KeyBindings[Keys.Right].Add(KeyStateES.Held, Actions.MoveUp);
And now I'm able to move the Entity around quite easily with key bindings. 现在,我可以通过键绑定轻松移动Entity了。 However, it's still not quite ideal because: 但是,它仍然不是很理想,因为:
This is a problem because sometimes I'll want a key to perform multiple unrelated tasks and because it seems really silly for my InputManager to be the one passing the arguments for the methods. 这是一个问题,因为有时我想让一个键执行多个不相关的任务,并且因为我的InputManager成为传递方法参数的人似乎很愚蠢。 Ideally, I would like it so that a KeyDown, KeyHeld, or KeyReleased event is fired and only the Controllers with the particular key(s) bound respond to the event and execute their associated Methods. 理想情况下,我希望这样,以便触发KeyDown,KeyHeld或KeyReleased事件,并且只有绑定了特定键的Controller才响应该事件并执行其关联的Method。
After that you changed X
and Y
coordinates o the Entity
using specific component, you just redraw scene, and Entity
will appear into the a new position. 之后,使用特定组件更改了Entity
X
和Y
坐标,只需重绘场景,然后Entity
就会出现在新位置。 Where is actually the problem. 问题出在哪里。 ? ?
You have an Entity
that is transformed in any possible way with (say) PositionComponent
, RotationComponent
, ScalComponent
, TextureComponent
and so on, but have simple Redraw()
method which renders all Entites
on the scene in visible frustrum within a current state of each one. 您拥有一个Entity
,该Entity
可以通过(例如) PositionComponent
, RotationComponent
, ScalComponent
, TextureComponent
等以任何可能的方式进行转换,但具有简单的Redraw()
方法,该方法将场景中的所有Entites
呈现为在每个当前状态下的可见Entites
。
How about a tree of types focused on these high-level behaviors?: ie a Jump class would, given an object, know how to make it jump. 专注于这些高级行为的类型树怎么样?:即,给定一个对象的Jump类将知道如何使其跳转。 Jump might be derived from Move if there is sufficient commonality, etc. More complex behaviors would then be composed of simpler behaviors heirarchically. 如果具有足够的通用性,则跳转可能来自Move。等等。然后,复杂的行为将由层次上更简单的行为组成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.