{"id":14960766,"url":"https://github.com/ichenpipi/unity-code-executor","last_synced_at":"2025-10-08T22:11:20.095Z","repository":{"id":189481119,"uuid":"680753743","full_name":"ichenpipi/unity-code-executor","owner":"ichenpipi","description":"[Unity Editor Tool]  A front-end interface where you can create, edit, save and dynamically execute code snippets.","archived":false,"fork":false,"pushed_at":"2023-10-17T11:18:37.000Z","size":536,"stargazers_count":36,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-20T12:35:42.417Z","etag":null,"topics":["csharp","debug","dynamic-execution","executor","game-development","lua","snippets","unity","unity-editor","xlua"],"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/ichenpipi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-08-20T09:41:32.000Z","updated_at":"2025-04-03T02:44:36.000Z","dependencies_parsed_at":"2023-08-20T11:37:28.016Z","dependency_job_id":"cae33b6a-38fc-47a3-b3ce-b58836b63c1e","html_url":"https://github.com/ichenpipi/unity-code-executor","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"ae2541f0e2abb4aca3039e4852665122749b961c"},"previous_names":["ichenpipi/unity-code-executor"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ichenpipi/unity-code-executor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichenpipi%2Funity-code-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichenpipi%2Funity-code-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichenpipi%2Funity-code-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichenpipi%2Funity-code-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ichenpipi","download_url":"https://codeload.github.com/ichenpipi/unity-code-executor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichenpipi%2Funity-code-executor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000782,"owners_count":26082851,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["csharp","debug","dynamic-execution","executor","game-development","lua","snippets","unity","unity-editor","xlua"],"created_at":"2024-09-24T13:22:56.991Z","updated_at":"2025-10-08T22:11:20.066Z","avatar_url":"https://github.com/ichenpipi.png","language":"C#","readme":"# Code Executor\n\n[中文文档](README_ZH.md)\n\n## Introduction\n\n### What is this project\n\nThis is a Unity editor plugin project.\n\nThis plugin provides a front-end interface where you can create, edit, save, select execution mode and execute code snippets.\n\n![Intro](Screenshots~/intro.png)\n\n### What can it do\n\n1. Dynamically execute code snippets in Edit Mode.\n2. Dynamically execute code snippets in Play Mode.\n\n### Supported programming languages\n\nAlthough the plugin has built-in programming language backend examples for C# and Lua (xLua).\n\nBut the plugin does not impose any restrictions on the programming language backend!\n\nYou can dynamically register (inject) execution modes for any programming language through the API provided by the plugin.\n\nBuilt-in execution mode examples:\n\n- C#: [InjectorCSharp.cs](Editor/Scripts/Examples/CSharp/InjectorCSharp.cs), [ExecutionHelperCSharp.cs](Editor/Scripts/Examples/CSharp/ExecutionHelperCSharp.cs)\n- xLua (Standalone): [InjectorXLua.cs](Editor/Scripts/Examples/XLua/InjectorXLua.cs), [ExecutionHelperXLua.cs](Editor/Scripts/Examples/XLua/ExecutionHelperXLua.cs)\n- xLua (Custom): [InjectorXLuaCustom.cs](Editor/Scripts/Examples/XLua/InjectorXLuaCustom.cs)\n\nThe built-in execution modes are enabled by default, you can disable them in the window's menu.\n\n![Built-in Execution Modes](Screenshots~/window-menu-builtin-exec-mode.png)\n\n### How to register execution modes\n\nThe project provides a `CodeExecutorRegistration` attribute to register execution modes, which has the ability to control the order of registration.\n\n\u003e This attribute essentially uses the `InitializeOnLoadMethod` attribute provided by Unity, so you can also register execution modes directly using the `InitializeOnLoadMethod` attribute, but there is no control over the order of multiple modes.\n\n```csharp\n#if UNITY_EDITOR\nusing ChenPipi.CodeExecutor.Editor;\nusing UnityEditor;\n\npublic static class Example\n{\n\n    [CodeExecutorRegistration]\n    private static void Register()\n    {\n        CodeExecutorManager.RegisterExecMode(new ExecutionMode()\n        {\n            name = \"New ExecMode\",\n            executor = ExecuteCode,\n        });\n    }\n\n    private static object[] ExecuteCode(string code)\n    {\n        // Execute code here\n        return new object[] { };\n    }\n\n}\n#endif\n```\n\nAfter successful registration, the name of the mode will appear in the drop-down list of the Execution Mode menu at the top right of the Code Executor window, and can be used to execute code snippets.\n\n![Execution Modes](Screenshots~/execution-modes.png)\n\n#### Register by reflection\n\nIf you want to avoid directly referencing the `ChenPipi.CodeExecutor.Editor` namespace in your own project code, you can implement the registration through C# reflection.\n\nPlease refer to [ReflectionAPI.cs](Editor/Scripts/Examples/ReflectionAPI.cs) provided within the project.\n\n## Installation\n\n### Install from Package Manager (Recommend)\n\n1. Open the **Package Manager** Window.\n2. Open the **add(+)** menu in the Package Manager's toolbar.\n3. Select **Add package from git URL** from the add menu.\n4. Enter **the Git URL of this project (with `.git` suffix)** in the text box and click **Add** button.\n\nLearn more on [https://docs.unity3d.com/Manual/upm-ui-giturl.html](https://docs.unity3d.com/Manual/upm-ui-giturl.html)\n\n### Manually install\n\nDownload and put the **Whole Project** in your project's Assets folder (or any subfolder would be ok).\n\n## Usage\n\n### Open the window\n\nSelect the `Window \u003e Code Executor` option in the Unity editor menu bar.\n\n### Create Snippet\n\nClicking on the **New** item at the top left of the window switches you to the New state, where you can edit and execute a temporary snippet.\n\nIn addition, you can save the current content as a new snippet and save it in the snippet list by clicking the **Save** button at the top right of the code editing area.\n\n![New](Screenshots~/new.png)\n\n### Execute Snippet\n\n1. Click the **Execute** button below the code editing area to execute the current code snippet\n2. Move your mouse to any item in the snippet list, click the ▶️ button on the right side of the item to execute the snippet\n\n![Execute](Screenshots~/execute.png)\n\n### Edit Snippet\n\nAfter selecting any item in the snippet list, the code editing area will enter the read-only state, then you can view or copy the code text.\n\nIf you need to modify the code of current snippet, click on the **Edit** button at the top right of the code editing area.\n\nSwitching to another snippet will enter the read-only state again.\n\n![Edit](Screenshots~/edit.png)\n\n### Rename Snippet\n\nSelect any item in the snippet list, press the **F2** key to rename the snippet.\n\n![Rename](Screenshots~/rename.png)\n\n### Duplicate Snippet\n\nIf you want to duplicate the current snippet, click the **Duplicate** button at the top right of the code editing area.\n\nThen you will get a copy of the current snippet.\n\n![Duplicate](Screenshots~/duplicate.png)\n\n### Snippet Menu\n\nRight-click on any **snippet** item in the snippet list will display a menu with the following options:\n\n- Execute\n- Edit\n- Rename\n- Duplicate\n- Top\n- Un-top\n- Delete\n\n![Snippet Menu](Screenshots~/snippet-menu.png)\n\n### Category Menu\n\nRight-click on any **category** item in the snippet list will display a menu with the following options:\n\n- Rename\n- Delete\n- Create New Category\n- Copy To Clipboard\n\n![Category Menu](Screenshots~/category-menu.png)\n\n### Context Menu\n\nRight-click on an **empty space** in the snippet list will display a menu with the following options:\n\n- Create New Category\n- Collapse All (Categories)\n- Expand All (Categories)\n- Paste From Clipboard\n\n![Context Menu](Screenshots~/context-menu.png)\n\n### Copy/Paste Snippets\n\n- Press **Ctrl+C** to save the selected snippets in the snippet list to the system clipboard as Json format text.\n- Press **Ctrl+V**, the program will try to parse the content from the system clipboard, and all valid snippets will be saved to the snippet list.\n\nBy this way, you can quickly swap snippets between different Unity editors.\n\n### Reference Snippets\n\nTo make it easier to reuse existing code snippets, the code editor supports a simple import syntax.\n\nSimply add the `@import(\"SnippetName\")` statement to the code, and the plugin will replace the corresponding import statement with the code text of the target snippet before executing the code.\n\nHere is a example~\n\nCurrently, we have a snippet called \"CrazyThursday\" with the following code text:\n\n```csharp\nUnityEngine.Debug.LogError(\"[CodeExecutor] Crazy Thursday\");\n```\n\nThen we import the \"CrazyThursday\" snippet in other code using the import syntax:\n\n```csharp\n@import(\"CrazyThursday\")\nUnityEngine.Debug.LogError(\"[CodeExecutor] V Me 50\");\n```\n\nThe code will be parsed as:\n\n```csharp\nUnityEngine.Debug.LogError(\"[CodeExecutor] Crazy Thursday\");\nUnityEngine.Debug.LogError(\"[CodeExecutor] V Me 50\");\n```\n\nThe import syntax also supports nesting.\n\nBut! Be careful! Circular references will destroy the world!\n\n### Shortcut keys\n\n- `Ctrl+F`: Focus to search field\n- `F2`: Rename the first selected asset\n- `F5`: Reload data and settings\n- `Delete/Backspace`: Delete selected snippets\n- `Ctrl+C`: save the selected snippets in the snippet list to the system clipboard as Json format text\n- `Ctrl+V`: Try parsing the content from the system clipboard, and all valid snippets will be saved to the snippet list.\n- `Ctrl+D`: Duplicate selected snippets.\n\n## Screenshots/Animations\n\nTo be added...\n\n## Compatibility\n\nThis project is compatible with the following versions of the Unity Editor:\n\n- 2020.2 and later\n\n### Testing details\n\n| Unity Version     | Tested | Note |\n|-------------------|--------|------|\n| Unity 2020.2.5f1  | ✔️     |      |\n| Unity 2021.2.16f1 | ✔️     |      |\n| Unity 2021.3.8f1  | ✔️     |      |\n| Unity 2021.3.15f1 | ✔️     |      |\n| Unity 2021.3.22f1 | ✔️     |      |\n| Unity 2021.3.27f1 | ✔️     |      |\n| Unity 2021.3.29f1 | ✔️     |      |\n\n## Dependencies\n\n| Package | Version | Note |\n|---------|---------|------|\n| None    | None    |      |\n\n## License\n\nThis project is licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichenpipi%2Funity-code-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichenpipi%2Funity-code-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichenpipi%2Funity-code-executor/lists"}