{"id":17644954,"url":"https://github.com/khiemgluong/polity-manager","last_synced_at":"2026-05-24T23:04:36.188Z","repository":{"id":254057275,"uuid":"828503242","full_name":"khiemgluong/Polity-Manager","owner":"khiemgluong","description":"An editor based tool for Unity designed to manage political relations within a matrix.","archived":false,"fork":false,"pushed_at":"2025-05-12T02:15:19.000Z","size":1286,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T03:27:38.270Z","etag":null,"topics":["editor","matrix","unity","utility"],"latest_commit_sha":null,"homepage":"https://assetstore.unity.com/packages/tools/visual-scripting/polity-manager-manage-factions-families-290633","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/khiemgluong.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-14T10:57:38.000Z","updated_at":"2025-05-12T02:15:23.000Z","dependencies_parsed_at":"2025-05-12T03:23:10.310Z","dependency_job_id":null,"html_url":"https://github.com/khiemgluong/Polity-Manager","commit_stats":null,"previous_names":["khiemgluong/polity-manager"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/khiemgluong/Polity-Manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiemgluong%2FPolity-Manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiemgluong%2FPolity-Manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiemgluong%2FPolity-Manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiemgluong%2FPolity-Manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khiemgluong","download_url":"https://codeload.github.com/khiemgluong/Polity-Manager/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiemgluong%2FPolity-Manager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264749032,"owners_count":23658125,"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":["editor","matrix","unity","utility"],"created_at":"2024-10-23T10:43:57.991Z","updated_at":"2026-05-19T03:32:04.314Z","avatar_url":"https://github.com/khiemgluong.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Polity Manager - Manage Factions \u0026 Formations**\n\n_Pride leads to destruction, and arrogance to downfall._ - DoodleBob\n\n- [Description](#description)\n- [Quickstart](#quickstart)\n  - [Video Tutorial](#video-tutorial)\n- [Public APIs](#public-apis)\n  - [Polity.Manager](#politymanager)\n    - [ChangeRelation()](#changerelation)\n    - [CheckRelation()](#checkrelation)\n    - [SerializeRelationMatrix()](#serializerelationmatrix)\n    - [DeserializeRelationMatrix()](#deserializerelationmatrix)\n    - [RandomFactionIndex()](#randomfactionindex)\n    - [Events](#events)\n      - [OnRelationChange](#onrelationchange)\n    - [Context Menus](#context-menus)\n      - [Reset Relation Matrix](#reset-relation-matrix)\n      - [Load Relation Matrix](#load-relation-matrix)\n  - [Polity.Faction](#polityfaction)\n    - [Set()](#set)\n    - [Events](#events-1)\n      - [OnNameChange](#onnamechange)\n  - [Polity.Leader](#polityleader)\n    - [TransferLeader()](#transferleader)\n    - [AddMember()](#addmember)\n    - [RemoveMember()](#removemember)\n- [Credits](#credits)\n\n## Description\n\nPolity Manager is an editor based tool designed to manage relations between polities.\n\nThe PolityManager singleton (PM) contains a _Faction Relation Matrix_, a matrix table that displays the relation of one polity to another based on their position, similar to the Unity physics collision matrix.\n\n![Faction Relation Matrix](./Assets/Documentation/Faction%20Relation%20Matrix.png)\n\n\u003eThe Red Team is neutral to the Blue Team and allied to the Empire, but the Blue Team are enemies to the Empire and allied to the Shogunate.\n\nTo retrieve these factions from an object, you can attach the `Polity.Member` monobehaviour or have a class implement the `IMember` interface (the latter is recommended). This will provide you with a dropdown field listing all the factions that you have created in the Manager.\n\nThese utilizes the [Faction](#polityfaction) class which is the main way GameObjects can communicate with Polity Manager. You can utilize this class to build your own classes with this as a field.\n\nIntroduced in 3.0.0. The [Leader](#polityleader) class can be used to group related `IMember` together and organize them in a `Formation`. The method for which it gets members is up to you to implement.\n\nPolity Manager is suited for games that needs to manage various groups of NPCs, especially when these relationships are a bit more complex, such as when one NPC needs to react to an enemy of one or more allied NPCs. However, it can also be applicable to simple teams.\n\nIt is also designed to be very bare bones so that you can modify it more easily to suit your game's specific needs. It's less of a all encompassing solution and more of a framework.\n\n## Quickstart\n\n### [Video Tutorial](https://www.youtube.com/watch?v=f2wm8g-1v8A)\n\nThis should demonstrate a very basic implementation of how the PolityManager can control NavMeshAgents with a PolityMember that can react to relationship changes based on their current polity.\n\nYou can open the `PolityNPC.cs` class inside of Example/Scripts to get a better idea of how the class subscribes to events and how it calls public PolityManager methods.\n\n## Public APIs\n\nAll classes in this package is under the `Polity` namespace.\n\n### Polity.Manager\n\nAll public methods can be called from this PolityManager Singleton, referenced as `PM`, for example PM.ModifyPolityRelation();\n\n#### ChangeRelation()\n\nSets a new relationship status between two polities based on their names, adjusting their relation to either Neutral, Allies, or Enemies.\nIf the polities matched, the `OnRelationChange` event will be invoked to notify all subscribers of the relation change.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `polityMember`     | `PolityMember`   | The member of the polity initiating the relationship change. |\n| `theirPolityName`  | `string`         | The name of the polity that is targeted for the relationship change, retrieved from `polityName` in `PolityMember`. |\n| `factionRelation`  | `Polity.Relation` | The new relation to set; can be `Neutral`, `Allies`, or `Enemies`.|\n\n#### CheckRelation()\n\nCompares the PolityRelation of the polityName to the second polityName and returns the enum that indicates their PolityRelation if found.\nThe overload method replaces the PolityMember parameters as strings representing the polityName.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `polityMember`     | `PolityMember`   | The member of the polity initiating the relationship comparison. |\n| `theirPolityMember`  | `PolityMember`         | The name of the polity that is targeted for comparison, retrieved from `polityName` in `PolityMember`. |\n\n**Returns**\nThe `Polity.Relation` enum value, which can be `Neutral`, `Allies` or `Enemies`.\n\n#### SerializeRelationMatrix()\n\nSerializes the `PolityRelation[,]` matrix and sets the serialized `polityRelationMatrixString` to its return value.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `RelationMatrix`     | `Polity.Relation[,]`   | The 2D PolityRelation matrix. This can be omitted which will use the Singleton's `RelationMatrix`. |\n\n**Returns**\nThe `string` of that serialized matrix.\n\n#### DeserializeRelationMatrix()\n\nDeserializes a string representing the `PolityRelation[,]` matrix.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `json`     | `string`   | This can be omitted which will then use the Singleton's `relationMatrixString`. |\n\n**Returns**\nThe `Polity.Relation[,]` matrix which was deserialized from the string.\n\n#### RandomFactionIndex()\n\n**Returns**\nA random index within the Polity Manager's factions.\n\n#### Events\n\n##### OnRelationChange\n\nInvoked whenever 2 factions change their `Relation`.\n\n#### Context Menus\n\n##### Reset Relation Matrix\n\nReset every relation to `Neutral`.\n\n##### Load Relation Matrix\n\nIf in some case the serialized polity relation matrix did not load, this can manually deserialize \u0026 load it.\n\n### Polity.Faction\n\n#### Set()\n\nSets a new name for the faction. Can be an int representing the index of the faction in the Polity Manager, or a string of that faction name, as long as one exists.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `factionIndex` or `factionName`   | `int` or `string`   |  |\n\n#### Events\n\n##### OnNameChange\n\nInvoked whenever the `Name` property of Faction is changed\n\n### Polity.Leader\n\n#### TransferLeader()\n\nFinds the nearest IMember from the members list and assigns it as the new leader, transferring all its members to it as well. If a Leader parameter is given, then it will be transferred to that Leader.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| none or `newLeader`     | `Leader`   | Sets the new leader for the current Leader. Called automatically when the leader is destroyed. |\n\n#### AddMember()\n\nAdds a member to the leader members list.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `member` (optional: `overrideFaction`)    | `IMember` (optional: bool)   | Can use the `enforceFaction` bool to ensure that the member has a matching faction before being added, otherwise it will just override its faction to the one the leader has and add it.|\n\n#### RemoveMember()\n\nRemoves a member from the leader members list.\n\n| Parameter          | Type             | Description |\n|--------------------|------------------|-------------|\n| `member`    | `IMember` | |\n\n## Credits\n\nPBR Sand054 texture\n[ambientcg.com](https://ambientcg.com) - CC0 License\n\n**Polity Manager** was developed by Khiem Luong ([github.com/khiemgluong](https://github.com/khiemgluong))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhiemgluong%2Fpolity-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhiemgluong%2Fpolity-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhiemgluong%2Fpolity-manager/lists"}