{"id":13662414,"url":"https://github.com/SinyavtsevIlya/DOTS-Stats","last_synced_at":"2025-04-25T10:31:18.467Z","repository":{"id":158411819,"uuid":"397158583","full_name":"SinyavtsevIlya/DOTS-Stats","owner":"SinyavtsevIlya","description":"Unity DOTS Stats-system implementation ","archived":false,"fork":false,"pushed_at":"2021-08-23T13:52:12.000Z","size":67,"stargazers_count":34,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-02T05:13:58.883Z","etag":null,"topics":["abilities","buff","burst","dots","ecs","entities","entity-component-system","gamedev","stats","unity"],"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/SinyavtsevIlya.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,"roadmap":null,"authors":null}},"created_at":"2021-08-17T07:48:51.000Z","updated_at":"2024-07-02T04:53:54.000Z","dependencies_parsed_at":"2024-01-26T19:57:04.719Z","dependency_job_id":null,"html_url":"https://github.com/SinyavtsevIlya/DOTS-Stats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-Stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-Stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-Stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-Stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SinyavtsevIlya","download_url":"https://codeload.github.com/SinyavtsevIlya/DOTS-Stats/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223996600,"owners_count":17238335,"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":["abilities","buff","burst","dots","ecs","entities","entity-component-system","gamedev","stats","unity"],"created_at":"2024-08-02T05:01:58.040Z","updated_at":"2024-11-10T18:30:25.430Z","avatar_url":"https://github.com/SinyavtsevIlya.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# DOTS-Stats\n\nDOTS-Stats is a high performance and scalable Stats-System.\n\n# Features\n\n- Maximum flexibility. Thanks to the pure component approach, it allows you to implement abilities, items, buffs, potions and make them work together as one single thing.\n- High performance. Zero GC allocations.\n- 100% ECS-ish. No more complex abstact OOP classes that work here but don't work there.\n- Ready-made base Authoring components for customization in the editor\n- Supports *multiplying* and *additive* stats\n- The minimum amount of boilerplate code.\n- Compatible with burst.\n- Compatible with il2cpp.\n\n# HowTo\n\n## Requirements\n\n`Min. Requirements:` Unity \u003e= 2019.4.18 and entities package \u003e= 0.11.2-preview.1\n\n`Tested on:` Unity 2020.2.3 and entities package 0.17.0-preview.42\n\n## Installation\n\nYou can install the repository using `UPM`:\nJust add this line in Packages/manifest.json:\n\n\"com.nanory.unity.entities.stats\": \"https://github.com/SinyavtsevIlya/DOTS-Stats.git\",\n\n## Usage\nLet's say you want to create an RPG'like stats system. \nWhen the player takes a weapon, his Attack stat grows. When he drops it, the stat returns to default.\n\n### 1) Create a new Stat component you need\n\n``` c#\npublic struct Attack : IComponentData\n{\n    // The only constraint is you must have a float field. \n    public float Value; \n}\n```\n\n### 2) Create an Authoring for this Stat\n\n``` c#\npublic class AttackAuthoring : StatAuthoringBase\u003cAttack\u003e\n{\n    [SerializeField] float _value;\n    // Simply return a new instance of \"Attack\" and set it's value from the serialized field. \n    protected override Attack GetStat() =\u003e new Attack() { Value = _value };\n}\n```\nYou'll get this:\n\n![Authoring](Docs/AuthoringPreview.png)\n\n### 3) Create two gameobject in your scene: \"Sword\" and \"Player\". Add an `AttackAuthoring` on both of them.\nAnd also add a `StatReceiverTagAuthoring` on the Player gameobject, to make him a \"Stat-Reciever\". (means that he able to accumulate stats from other contexts, e.g. items, buffs etc.)\n\u003e Don't forget to add a `ConvertToEntity` on them to enable automatic conversion in a scene.\n\n### 4) And add the test code that triggers sword equipement \n\n```csharp\n// anywhere you want. Say on spacebar hit:\nEntityManager.SetStatsChanged(swordEntity, playerEntity);\n\n// and call this to deequip:\nEntityManager.SetStatsRemoved(swordEntity);\n```\n\n### 5) And finally to make things work, add this system declaration somewhere\n\n```csharp\n    [UpdateInGroup(typeof(StatSystemGroup))]\n    public class CalculateAttackSystem : CalculateStatSystem\u003cAttack\u003e { }\n```\n\n\u003e You also able to add a system in a shorter way:\n\u003e \n\u003e   `DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(_world, typeof(CalculateStatSystem\u003cAttack\u003e))` \n\u003e   \n\u003e This step is recomended to be automated (code-gen, code-snippets, build processors or whatever you like) \n\nThats it! \n\n# FAQ\n\n## Ok. Does it work with Jobs/Burst?\n\nSure. Just use `EnityCommandBuffer` versions of extension methods:\n\n```csharp\nentityCommandBuffer.SetStatsChanged(contextEntity, statReceiverEntity);\nentityCommandBuffer.SetStatsRemoved(contextEntity);\n```\n\n## How to react on Stat change on a stat-receiver-entity?\n\nJust add a `StatRecievedElementEvent` component in your querry. \nHere is an example:\n```csharp\n Entities\n    .ForEach((Entity ownerEntity, DynamicBuffer \u003cStatRecievedElementEvent\u003e statRecievedEvents, StatsWidget widget) =\u003e\n    {\n        for (var idx = 0; idx \u003c statRecievedEvents.Length; idx++)\n        {\n            var statRecievedEvent = statRecievedEvents[idx];\n\n            if (statRecievedEvent.Is\u003cAttack\u003e())\n                widget.SetAttack(EntityManager.GetComponentData\u003cAttack\u003e(ownerEntity).Value);\n\n            if (statRecievedEvent.Is\u003cAttackSpeed\u003e())\n                widget.SetAttackSpeed(EntityManager.GetComponentData\u003cAttackSpeed\u003e(ownerEntity).Value);\n                \n            // more stats here...\n        }\n    });\n```\n\n\u003e Since several stats can change at once during one frame, the event is presented as a `DynamicBuffer` of structs that clears automatically in the end of frame. \n\n# How it works under the hood\n\n![Self-editing Diagram](Docs/Diagram.svg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSinyavtsevIlya%2FDOTS-Stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSinyavtsevIlya%2FDOTS-Stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSinyavtsevIlya%2FDOTS-Stats/lists"}