{"id":13662534,"url":"https://github.com/ludaludaed/KECS","last_synced_at":"2025-04-25T10:32:01.013Z","repository":{"id":185453480,"uuid":"339891821","full_name":"ludaludaed/KECS","owner":"ludaludaed","description":"🧁KECS is a fast and easy C# Entity Component System framework for writing your own games.","archived":false,"fork":false,"pushed_at":"2022-10-17T22:03:21.000Z","size":2886,"stargazers_count":36,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-05-21T14:03:18.119Z","etag":null,"topics":["data-oriented","data-oriented-architecture","data-oriented-design","ecs","ecs-framework","ecs-pattern","entity","entity-component-system","filter","frame","framework","game-development","kecs","unity","unity-engine","unityecs","unityengine","unityscript"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ludaludaed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-18T00:24:55.000Z","updated_at":"2024-05-16T08:41:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"bfa9d923-6c3f-45fa-be73-373bd30b7498","html_url":"https://github.com/ludaludaed/KECS","commit_stats":null,"previous_names":["ludaludaed/kecs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ludaludaed%2FKECS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ludaludaed%2FKECS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ludaludaed%2FKECS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ludaludaed%2FKECS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ludaludaed","download_url":"https://codeload.github.com/ludaludaed/KECS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250798273,"owners_count":21489053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-oriented","data-oriented-architecture","data-oriented-design","ecs","ecs-framework","ecs-pattern","entity","entity-component-system","filter","frame","framework","game-development","kecs","unity","unity-engine","unityecs","unityengine","unityscript"],"created_at":"2024-08-02T05:02:01.384Z","updated_at":"2025-04-25T10:32:00.678Z","avatar_url":"https://github.com/ludaludaed.png","language":"C#","readme":"# 🧁KECS\n\nKECS is a fast and easy C# Entity Component System framework for writing your own games.\n\u003e **Important!** KECS is still in development, so its use in projects is only at your own risk.\n\n## Table of Contents\n\n* [About ECS pattern](#about-ecs-pattern)\n    * [World](#-world)\n    * [Component](#-component)\n    * [Entity](#-entity)\n        * [Entity builder](#-entitybuilder)\n    * [System](#-system)\n        * [Events](#-events)\n        * [Query](#-query)\n        * [Data injection](#-data-injection)\n    * [Systems](#-systems)\n* [License](#-license)\n* [Contacts](#-contacts)\n\n## About ECS pattern\n\n### 🌏 World\n\nWorld is a container for all entities and components. The world is created with `Worlds.Create()`. The world can be set\nup with its initial settings using the `WorldConfig` structure.\n\n```csharp\nvar world = Worlds.Create(worldName,\n        new WorldConfig()\n        {\n            ...\n        });\n```\n\nThe world can be retrieved using its name or id `Worlds.Get()`\n\n```csharp\nvar world = Worlds.Get(worldName);\n```\n\nThe world can be destroyed using the `Destroy ()` method of the `World` class.\n\n```csharp\nworld.Destroy();\n```\n\n### 📦 Component\n\nA component is a container only for users data. In KECS, component is only a value type.\n\n```csharp\npublic struct MoveComponent \n{\n    public Vector2 Direction;\n    public float Speed;\n}\n```\n\n### 🤖 Entity\n\nAn entity is a container for components. The entity has methods for adding, removing, and getting components.\n\n```csharp\nEntity entity = _world.CreateEntity();\n\nref var settedSpeedComponent  = ref entity.Set(new SpeedComponent());\nref var gottenSpeedComponent = ref entity.Get\u003cSpeedComponent\u003e();\n\nentity.Remove\u003cSpeedComponent\u003e();\n\nbool has = entity.Has\u003cSpeedComponent\u003e();\n\nentity.Destroy ();\n```\n\n\u003e **Important!** An entity without components will be automatically deleted.\n\n\n#### 🚧 EntityBuilder\n\nEntityBuilder allows you to create entities according to a template you define.\n\n```csharp\nvar builder = new EntityBuilder();\n\nbuilder.Append(new FooComponent())\n    .Append(new BarComponent())\n    .Append(new BazComponent());\n    \nvar entity = builder.Build(World);\n```\nThe `Append()` method allows you to add a component to the entity template.\nThe `Build(world)` method allows you to create an entity from this template in the world.\n\u003e **NOTE:**\nThis way of creating an entity allows you to reduce the number of side archetypes at the initial sequential assignment of entity components.\n### 🕹️ System\n\nThe system processes entities matching the filter.\nThe system must implement the abstract class `SystemBase` or `UpdateSystem`.\n\n```csharp\npublic class SystemTest1 : UpdateSystem\n{\n    public override void Initialize()\n    {\n        // Will be called when the system is initialized.\n    }\n\n    public override void OnUpdate(float deltaTime)\n    {\n        _world.CreateQuery()\n            .ForEach((Entity entity, ref Component comp) =\u003e\n            {\n                comp.Counter++;\n            });\n    }\n\n    public override void OnDestroy()\n    {\n        // Will be called when the system is destroyed.\n    }\n\n    public override void PostDestroy()\n    {\n        //Will be called after the system is destroyed.\n    }\n}\n```\n\n#### 💡 Events\n\nEmitting an event for an entity is set by the `entity.SetEvent\u003c\u003e()` method.\n\n```csharp\npublic struct EventComponent\n{\n    ...\n}\n...\nentity.SetEvent\u003cEventComponent\u003e();\n```\nReceiving an event.\n\n```csharp\npublic class SystemTest1 : UpdateSystem\n{\n    public override void OnUpdate(float deltaTime)\n    {\n        _world.CreateQuery()\n            .ForEach((Entity entity, ref EventComponent event) =\u003e\n            {\n                ...\n            });\n    }\n}\n```\n\u003e **Important!** The event hangs on the entity on exactly one frame, so the event appears only on the next frame and deleted after it.\n\n#### 🎰 Query\n\nTo create a query to the world you need to call the `CreateQuery()` method.\nIn order to include or exclude a set of components from iteration. You can use a method chain for the request, consisting of `With\u003c\u003e()` or `Without\u003c\u003e()`.\nIn order to iterate over this set, you need to call the `Foreach()` method from the request. Components specified in\ndelegate arguments will automatically be considered as included in the selection.\n\n```csharp\npublic class SystemTest1 : UpdateSystem\n{\n    public override void OnUpdate(float deltaTime)\n    {\n        _world.CreateQuery()\n            .With\u003cBarComponent\u003e()\n            .Without\u003cBazComponent\u003e()\n            .ForEach((Entity entity, ref FooComponent fooComp) =\u003e\n            {\n                ...\n            });\n    }\n}\n```\n\n#### 💉 Data injection\n\nAdding shared data to systems is done by calling the `AddShared ()` method of the `Systems` class.\n\n```csharp\npublic class SharedData\n{\n    //Some fields\n}\n...\nvar world = Worlds.Create();\nvar systems = new Systems(world);\nsystems.Add(new SystemTest()).\n        Add(new SystemTest1()).\n        AddShared(new SharedData());\nsystems.Initialize();\n```\n\nShared data for the system is obtained by calling the `GetShared\u003c\u003e()` method.\n```csharp\npublic class SystemTest1 : UpdateSystem\n{\n    public override void OnUpdate(float deltaTime)\n    {\n        var sharedData = _systems.GetShared\u003cSharedData\u003e();\n        _world.CreateQuery()\n            .ForEach((Entity entity, ref FooComponent fooComp) =\u003e\n            {\n                ...\n            });\n    }\n}\n```\n\n### 🎮 Systems\n\nSystems are added using the `Add\u003c\u003e()` method of the `Systems` class.\nAfter adding all systems, you must call the `Intitalize()` method.\n\n```csharp\npublic class StartUp : MonoBehaviour\n{\n    public World _world;\n    public Systems _systems;\n\n    public void Awake()\n    {\n        _world = Worlds.Create();\n        _systems = new Systems(_world);\n        _systems.Add(new SystemTest()).\n                 Add(new SystemTest1()).\n        _systems.Initialize();\n    }\n\n    public void Update()\n    {\n        _world.ExecuteTasks();\n        _systems.OnUpdate(Time.deltaTime);\n    }\n\n    public void OnDestroy()\n    {\n        _systems.OnDestroy();\n        _world.Destroy();\n    }\n}\n```\n\u003e **Important!** After the systems are initialized, you cannot add new systems.\n\n## 📘 License\n📄 [MIT License](LICENSE)\n\n## 💬 Contacts\nTelegram: [ludaludaed](https://t.me/ludaludaed)\n\n\n\n","funding_links":[],"categories":["C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fludaludaed%2FKECS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fludaludaed%2FKECS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fludaludaed%2FKECS/lists"}