{"id":14961076,"url":"https://github.com/amazedevil/pixie","last_synced_at":"2025-10-24T20:31:03.156Z","repository":{"id":40895491,"uuid":"231553576","full_name":"amazedevil/Pixie","owner":"amazedevil","description":"Lightweight socket server framework for talking with Unity game engine project","archived":false,"fork":false,"pushed_at":"2022-12-08T23:30:18.000Z","size":172,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T04:02:18.908Z","etag":null,"topics":["framework","multiplayer","socket-server","unity","unity-game-engine"],"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/amazedevil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-03T09:18:35.000Z","updated_at":"2023-07-02T23:45:19.000Z","dependencies_parsed_at":"2023-01-25T15:16:31.768Z","dependency_job_id":null,"html_url":"https://github.com/amazedevil/Pixie","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/amazedevil%2FPixie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazedevil%2FPixie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazedevil%2FPixie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazedevil%2FPixie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amazedevil","download_url":"https://codeload.github.com/amazedevil/Pixie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238030288,"owners_count":19404859,"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":["framework","multiplayer","socket-server","unity","unity-game-engine"],"created_at":"2024-09-24T13:23:46.195Z","updated_at":"2025-10-24T20:30:57.760Z","avatar_url":"https://github.com/amazedevil.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pixie is a lightweight framework for building server side for Unity game engine project. It's not intended for real time multiplayer, but rather for message exchange in some kind of match making system, or turn based multiplayer.\n\nThe main idea of this project, is to build ready-to-use infrastructure, similar to HTTP frameworks, like \"Ruby on Rails\", \"Laravel\" or \"ASP.NET MVC\" for building socket-based applications, talking to Unity clients.\n\n## Quick start\n\nLet's assume you have Unity project, that wants to connect to some server, and send message to other clients connected to it. Some kind of simple chat if you wish. First of all, we should build library with messages, that will be shared between Unity project code base and server code base. Messages may look like this:\n\n```csharp\n//Message sent from client to server\npublic struct ServerMessageSaySomething {\n    public string Content;\n}\n\n//Message sent from server to client\npublic struct ClientMessageSaySomething {\n    public string Content;\n    public string Author;\n}\n```\n\nAfter that, let's inherit PXServer by some new class:\n\n```csharp\nclass MyServer : PXServer\n{    \n    //Here we should create service provider (we'll look at ones later)\n    protected override IPXServiceProvider[] GetServiceProviders() {\n        return new IPXServiceProvider[] {\n            new MyServiceProvider(),\n        };\n    }\n}\n```\n\nService providers, are classes that should fill our system with logic, in our case - register message handler class:\n\n```csharp\nclass MyServiceProvider : IPXServiceProvider\n{\n    //OnRegister of every service provider is called in the very beginning\n    public void OnRegister(IContainer container) {\n        //we want socket server to run on port 7777\n        container.Endpoints().RegisterSockerServer(\"0.0.0.0\", 7777)\n    \n        //we'll write MessageHandlerSaySomething class later\n        container.Handlers().Register(\n            PXHandlerService.MessageHandlerItem.CreateWithMessageHandlerType\u003cMessageHandlerSaySomething\u003e()\n        );\n    }\n\n    //after every provider OnRegister method executed, OnInitialize method of every SP should be called,\n    //so we can be sure that in OnInitialize every service is registered already\n    public void OnInitialize(IContainer container) {}\n}\n```\n\nLet's see what MessageHandlerSaySomething consists of:\n\n```csharp\nclass MessageHandlerSaySomething : PXMessageHandlerBase\u003cServerMessageSaySomething\u003e\n{\n    public override void Handle(ServerMessageSaySomething data) {\n        //this.context is current message handling scoped central DryIoc container,\n        //you're about to take all needed services from it.\n        //Here we use some extension shortcuts to Sender and Client,\n        //you can make your own, or use pure DryIoc Resolve\n        var sender = this.context.Sender();\n        var client = this.context.Client();\n        \n        sender.Send(\n            sender.GetClientIds(),\n            new ClientMessageSaySomething() { Content = data.Content, Author = client.Id }\n        );\n    }\n}\n```\n\nAt last, we can start our server, e.g. from Main:\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        (new MyServer()).StartSync();\n    }\n}\n```\n\nSo what about Unity side, first of all we should import package [PixieUnity.unitypackage](https://github.com/amazedevil/PixieUnity/releases/) (or install client code somehow else, see [link](https://github.com/amazedevil/PixieUnity#installation) for details).\n\nNow we're adding PXUnityClient component to some game object. It has fields to be configured:\n\n- serverHost: hostname or ip of our server\n- serverPort: port our server is listening to\n- eventKeepers: here we should add all game objects containing message handler components\n\nAt this point, shared messages library should be imported to Unity project, as we remember, it contains ClientMessageSaySomething structure, that is to be received from server. To make it happen, we should create message handler component:\n\n```csharp\npublic class ClientSaySomethingMessageHandler : PXUnityMessageHandlerBase\u003cClientMessageSaySomething\u003e\n{\n    [Serializable]\n    public class MessageReceivedEvent : UnityEvent\u003cClientMessageSaySomething\u003e { }\n\n    //this field name is requred to be \"messageReceivedEvent\", as it called over reflection\n    [SerializeField]\n    public MessageReceivedEvent messageReceivedEvent;\n}\n```\n\nAs you can guess, messageReceivedEvent event is called on receiving ClientMessageSaySomething, so we need to attach some method to that event:\n\n```csharp\npublic class SaySomethingLogicBehaviour : MonoBehaviour\n{\n    public void OnSaySomething(ClientMessageSaySomething message) {\n        Debug.Log($\"{message.Author}: {message.Content}\");\n    }\n}\n```\n\nAnd, in the end we're about to make message sending from client, we can organize method calling in any way we want, but sending itself is going to be something like this:\n\n```csharp\npublic class SenderBehaviour : MonoBehaviour\n{\n    [SerializeField]\n    private PXUnityClient client; //here we should attach our PXUnityClient, mentioned above\n\n    public void SendMessage(string message) {\n        client.SendMessage(new ServerMessageSaySomething() { Content = message });\n    }\n}\n```\n\nThat's it! We've made a simple chat with Pixie framework. If you're going to dive into some more topics, we'll talk about:\n\n- making command line interface (CLI) commands to be able to interact with our running server (guide in development)\n- scheduling jobs, to handle some heavy tasks in background, or just tasks, fireing not at the time of some message handling (e.g. cron scheduled) (guide in development)\n- working with database over entity framework core, how link it with Pixie based server using middlewares and how to deal with middlewares in general (guide in development)\n\n## Contacts\n\nIf you have any question, suggestion, or just anything to say about project, please open an [issue](https://github.com/amazedevil/Pixie/issues), also if you wish to have some more friendly way of communicating (e.g. spectrum chat community), please also open an issue with suitable description. I'll appreciate any kind of feedback :)\n\n## Dependencies\n\n- [DryIoc](https://github.com/dadhi/DryIoc) - used as dependency injection mechanism, framework is based on.\n- [Newtonsoft.Json](https://www.newtonsoft.com/) - used for message encoding/decoding + environment parameters reading.\n- [Quartz](https://www.quartz-scheduler.net/) - used for jobs scheduling.\n\n## License\n\nPixie is open-sourced software licensed under the [MIT license](https://github.com/amazedevil/Pixie/blob/master/LICENSE.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazedevil%2Fpixie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famazedevil%2Fpixie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazedevil%2Fpixie/lists"}