{"id":13661733,"url":"https://github.com/cesardeazevedo/Unity-Component-State-Machine","last_synced_at":"2025-04-25T03:31:12.100Z","repository":{"id":30533846,"uuid":"34088446","full_name":"cesardeazevedo/Unity-Component-State-Machine","owner":"cesardeazevedo","description":"Simple Unity State Machine designed with components","archived":false,"fork":false,"pushed_at":"2015-04-24T05:01:33.000Z","size":228,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-15T19:08:52.812Z","etag":null,"topics":[],"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/cesardeazevedo.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}},"created_at":"2015-04-17T00:41:18.000Z","updated_at":"2022-05-10T20:45:07.000Z","dependencies_parsed_at":"2022-09-08T14:50:40.101Z","dependency_job_id":null,"html_url":"https://github.com/cesardeazevedo/Unity-Component-State-Machine","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/cesardeazevedo%2FUnity-Component-State-Machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesardeazevedo%2FUnity-Component-State-Machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesardeazevedo%2FUnity-Component-State-Machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesardeazevedo%2FUnity-Component-State-Machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cesardeazevedo","download_url":"https://codeload.github.com/cesardeazevedo/Unity-Component-State-Machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223979752,"owners_count":17235457,"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":[],"created_at":"2024-08-02T05:01:40.556Z","updated_at":"2024-11-10T16:31:53.096Z","avatar_url":"https://github.com/cesardeazevedo.png","language":"C#","readme":"# Unity-Component-State-Machine\n\nA Simple Unity State Machine designed with components\n\n![screenshot](http://i.cubeupload.com/PXhCZo.png)\n\n#How to use\n\n1. Declare the initial states, and initialize them.\n\n```c#\n///\u003csummary\u003e\n///Player.cs\n///\u003c/summary\u003e\npublic class Player : GameStateMachine\u003cPlayer\u003e\n{\n  /// \u003csummary\u003e\n  /// Make sure that the name of these states are the same name of the script component\n  /// \u003c/summary\u003e\n  public enum States {\n    State1,\n    State2,\n    State3\n  }\n\n  void Awake() {\n      base.Initialize\u003cStates\u003e();\n  }\n  \n  void Start() {\n      ChangeState(State.State2);\n  }\n}\n```\n\n##Components\n\nEach state, is an individual component, and have to be attached to the same GameObject (for now), and they are optional\n\n```c#\n/// \u003csummary\u003e\n/// State1.cs\n/// \u003c/summary\u003e\npublic class State1 : StateComponentBase\u003cPlayer\u003e\n{\n\n  public override void Awake()\n  {\n      base.Awake();\n  }\n  \n  public override void EnterState() { }\n  \n  public override void ExitState()  { }\n  \n}\n```\n\n##Properties\n\n####Behaviour\nThe base component reference.\n\n####NextState\nEnum which represent the next state will come, only in the event `ExitState()`.\n\n####IsActive\nA bool which represent whether the current state is active or not.\n\n```c#\n//State1.cs\nvoid Update() {\n  if(IsActive) {\n  //The State1 is active\n  }\n}\n```\n\n##Events\n\n####EnterState()\n\n- Emitted whenever `ChangeState()` is invoked to current state.\n\n####ExitState()\n\n- Emitted whenever `ChangeState()` is invoked to other state.\n\n##Change States\n\nYou can change the states easily\n\n* From Base Behaviour\n\n```c#\n//Player.cs\npublic void Start() {\n  base.ChangeState(States.State2)\n}\n```\n\n* From Components\n\n```c#\n//State2.cs\npublic void Start() {\n    Behaviour.ChangeState(Player.States.State3);\n}\n```\n\n#Contributing\n1. Fork it!\n2. Create your feature branch: git checkout -b my-new-feature\n3. Commit your changes: git commit -m 'Add some feature'\n4. Push to the branch: git push origin my-new-feature\n5. Submit a pull request :D\n\n#License\n[MIT](./LICENSE)\n","funding_links":[],"categories":["C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesardeazevedo%2FUnity-Component-State-Machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesardeazevedo%2FUnity-Component-State-Machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesardeazevedo%2FUnity-Component-State-Machine/lists"}