{"id":13676665,"url":"https://github.com/madsbangh/EasyButtons","last_synced_at":"2025-04-29T07:33:08.086Z","repository":{"id":39006097,"uuid":"84367128","full_name":"madsbangh/EasyButtons","owner":"madsbangh","description":"Add buttons to your inspector in Unity super easily with this simple attribute","archived":false,"fork":false,"pushed_at":"2023-09-14T19:12:30.000Z","size":203,"stargazers_count":1141,"open_issues_count":12,"forks_count":86,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-08T19:24:16.305Z","etag":null,"topics":["unity","unity-editor","unity3d"],"latest_commit_sha":null,"homepage":null,"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/madsbangh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-03-08T21:19:10.000Z","updated_at":"2025-04-01T23:27:06.000Z","dependencies_parsed_at":"2024-01-06T14:51:57.545Z","dependency_job_id":null,"html_url":"https://github.com/madsbangh/EasyButtons","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madsbangh%2FEasyButtons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madsbangh%2FEasyButtons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madsbangh%2FEasyButtons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madsbangh%2FEasyButtons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madsbangh","download_url":"https://codeload.github.com/madsbangh/EasyButtons/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251456056,"owners_count":21592285,"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":["unity","unity-editor","unity3d"],"created_at":"2024-08-02T13:00:31.188Z","updated_at":"2025-04-29T07:33:03.077Z","avatar_url":"https://github.com/madsbangh.png","language":"C#","funding_links":[],"categories":["Open Source Repositories","C#","三 开源库"],"sub_categories":["Editor"],"readme":"# Easy buttons for the Unity default inspector\n[![openupm](https://img.shields.io/npm/v/com.madsbangh.easybuttons?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.madsbangh.easybuttons/)\n\nThese tiny scripts add the ability to quickly show a button in the inspector for any method.\n\n## Installation\n\n### OpenUPM\n\nOnce you have the OpenUPM cli, run the following command:\n\n```openupm install com.madsbangh.easybuttons```\n\nOr if you don't have it, add the scoped registry to manifest.json with the desired version: \n```json\n  \"scopedRegistries\": [\n    {\n      \"name\": \"package.openupm.com\",\n      \"url\": \"https://package.openupm.com\",\n      \"scopes\": [\n        \"com.madsbangh.easybuttons\",\n        \"com.openupm\"\n      ]\n    }\n  ],\n  \"dependencies\": {\n    \"com.madsbangh.easybuttons\": \"1.4.0\"\n  }\n```\n\n### Git URL\n\nProject supports Unity Package Manager. To install the project as a Git package do the following:\n\n1. In Unity, open **Window** -\u003e **Package Manager**.\n2. Press the **+** button, choose \"**Add package from git URL...**\"\n3. Enter \"https://github.com/madsbangh/EasyButtons.git#upm\" and press **Add**.\n\n### Unity Package\nAlternatively, you can add the code directly to the project:\n\n1. Clone the repo or download the latest release.\n2. Add the EasyButtons folder to your Unity project or import the .unitypackage\n\n## How To Use\n1. Add the Button attribute to a method.\n\n   ```csharp\n   using EasyButtons; // 1. Import the namespace\n   using UnityEngine;\n   \n   public class ButtonsExample : MonoBehaviour\n   {\n       // 2. Add the Button attribute to any method.\n   \t[Button]\n   \tpublic void SayHello()\n       {\n           Debug.Log(\"Hello\");\n       }\n   }\n   ```\n   \n2. You should now see a button at the top of the component with the same name as the method:\n\n   ![Button in the inspector](/Images/inspector.png)\n\n   ![Result](/Images/console.png)\n\n3. Add the Button attribute to a method with parameters.\n\n   ```csharp\n   using EasyButtons;\n   using UnityEngine;\n   \n   public class Test : MonoBehaviour\n   {\n       [Button]\n       public void ButtonWithParameters(string message, int number)\n       {\n           Debug.Log($\"Your message #{number}: '{message}'\");\n       }\n   }\n   ```\n\n4. You can now enter parameter values and invoke the method in the inspector:\n\n   ![Button with parameters](/Images/parameters.png)\n\n## Attribute Options\n\nThe `Button` attribute has different options that allow customizing the button look.\n\n***Mode*** - indicates when the button is enabled. You can choose between the following options:\n\n- AlwaysEnabled - the button is enabled in edit mode and play mode.\n\n- EnabledInPlayMode - the button is only enabled in play mode.\n\n- DisabledInPlayMode - the button is only enabled in edit mode.\n\n***Spacing*** - allows to have some space before or after the button. The following options can be used:\n\n- None - no spacing at all.\n\n- Before - adds space above the button.\n\n- After - adds space below the button.\n\n***Expanded*** - whether to expand the parameters foldout by default. It only works with buttons that have parameters.\n\n## Custom Editors\n\nIf you want to show buttons in a custom editor, you can use the **ButtonsDrawer** class defined in EasyButtons.Editor.\n\nInstantiate ButtonsDrawer in OnEnable if possible, then draw the buttons with help of the DrawButtons method, as in the example:\n\n```csharp\n[CustomEditor(typeof(Example))]\npublic class CustomEditor : ObjectEditor\n{   \n    private ButtonsDrawer _buttonsDrawer;\n\n    private void OnEnable()\n    {\n        _buttonsDrawer = new ButtonsDrawer(target);\n    }\n\n    public override void OnInspectorGUI()\n    {\n        DrawDefaultInspector();\n        _buttonsDrawer.DrawButtons(targets);\n    }\n}\n```\n\nYou can also draw only specific buttons:\n\n```csharp\n// Draw only the button called \"Custom Editor Example\"\n_buttonsDrawers.Buttons.First(button =\u003e button.DisplayName == \"Custom Editor Example\").Draw(targets);\n```\n\nYou can search for a specific button using its ***DisplayName*** or ***Method*** (MethodInfo object the button is attached to.)\n\n## Notes\n- Older versions of Unity might not understand the reference to EasyButtons runtime in the EasyButtons editor assembly definition. If you experience issues, you can re-add the reference, or remove the asmdefs completely.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadsbangh%2FEasyButtons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadsbangh%2FEasyButtons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadsbangh%2FEasyButtons/lists"}