简体   繁体   English

向实体/组件系统添加功能

[英]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: 但是,它仍然不是很理想,因为:

  • I can't bind more than one Method to a Key. 我不能将多个方法绑定到一个键。
  • I'm forced to pass the Method Arguments in the InputManager class. 我被迫在InputManager类中传递方法参数。

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 XY坐标,只需重绘场景,然后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可以通过(例如) PositionComponentRotationComponentScalComponentTextureComponent等以任何可能的方式进行转换,但具有简单的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.

相关问题 实体框架向属性添加功能 - Entity Framework adding functionality to Properties 向我的Entity Framework POCO类添加功能 - Adding functionality to my Entity Framework POCO classes 将实体添加到数据库实体框架会生成异常&#39;System.Data.Entity.Infrastructure.DbUpdateException - Adding an entity to a database entity framework generates an exception 'System.Data.Entity.Infrastructure.DbUpdateException 将带有子实体的实体添加到Redis服务器会导致System.StackOverflowException - Adding Entity with child entities to Redis server resulting System.StackOverflowException 将数据添加到数据库(错误:System.Data.Entity.Infrastructure.DbUpdateException) - Adding Data to Database (Error: System.Data.Entity.Infrastructure.DbUpdateException) 使用 MVC 的实体框架代码优先:添加过滤功能 (OrderBy) 会破坏 ViewBag 上下文 - Entity Framework Code First with MVC : Adding filtering functionality (OrderBy) disrupts ViewBag context 向我的 Xamarin 应用聊天添加实时功能会抛出 System.InvalidOperationException - Adding real time functionality to my Xamarin app chat is throwing System.InvalidOperationException 向 ItemsControl 添加缩放功能? - Adding a zoom functionality to an ItemsControl? 向 gridview 中的 imageButton 添加功能 - adding functionality to an imageButton in a gridview 向任何TextReader添加功能 - Adding functionality to any TextReader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM