Skip to content

Commit

Permalink
Merge pull request #157 from Tryibion/script-templates
Browse files Browse the repository at this point in the history
Add docs about creating script templates.
  • Loading branch information
mafiesto4 authored Sep 9, 2024
2 parents 62ae8e6 + 4331f56 commit 74aa4d0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions manual/scripting/advanced/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## In this section

* [Script Templates](templates.md)
* [Raw Data Asset](raw-data-asset.md)
* [Custom Editor Options](custom-editor-options.md)
* [Curve](curve.md)
Expand Down
70 changes: 70 additions & 0 deletions manual/scripting/advanced/templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Script Templates

Script templates can be used to allow users to create a new script based on a template.

## Create a script template

Create a text document anywhere in the **Content** folder and create the template that you desire. It is recommended the use .cs or .h/.cpp for the file extension for the template files.

### The available identifiers

Use the following identifiers to replace certain parts of your template with information upon creation by the user.

| Identifier | Description |
|--------|--------|
| **%copyright%** | Replaced with the copyright comment |
| **%class%** | Replaced with the class name. This is a modified version of the file name. |
| **%filename%** | C++ Template only. Replaced with the file name. |
| **%module%** | C++ Template only. Replaced with the module name. |
| **%namespace%** | C# Template only. Replaced with the module name. |

## Create a new template proxy

New C# template proxy:

```cs
[ContentContextMenu("New/C#/My new template")]
public class TestingCSharpProxy : CSharpProxy
{
public override string Name => "My new template";

protected override void GetTemplatePath(out string path)
{
// Can use `Globals` class to get specific project folders
path = "path to new .cs template";
}
}
```

New C++ template proxy:

```cs
[ContentContextMenu("New/C++/My new template")]
public class TestingCppProxy : CppProxy
{
public override string Name => "My new template";

protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
{
// Can use `Globals` class to get specific project folders
headerTemplate = "path to new .h template";
sourceTemplate = "path to new .cpp template";
}
}
```

Add the new proxy to the **ContentDatabase** using an **EditorPlugin**

```cs
public class TestEditorPlugin : EditorPlugin
{
public override void InitializeEditor()
{
base.InitializeEditor();

Editor.ContentDatabase.AddProxy(new TestingCSharpProxy());
Editor.ContentDatabase.AddProxy(new TestingCppProxy());
Editor.ContentDatabase.Rebuild(true);
}
}
```
1 change: 1 addition & 0 deletions manual/scripting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ To start visual scripting see the related documentation [here](visual/index.md).
* [Plugins Window](plugins/plugins-window.md)
* [Plugin Project](plugins/plugin-project.md)
* [Advanced](advanced/index.md)
* [Script Templates](advanced/templates.md)
* [Raw Data Asset](advanced/raw-data-asset.md)
* [Custom Editor Options](advanced/custom-editor-options.md)
* [Curve](advanced/curve.md)
Expand Down
1 change: 1 addition & 0 deletions manual/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
### [Plugins Window](scripting/plugins/plugins-window.md)
### [Plugin Project](scripting/plugins/plugin-project.md)
## [Advanced](scripting/advanced/index.md)
### [Script Templates](scripting/advanced/templates.md)
### [Raw Data Asset](scripting/advanced/raw-data-asset.md)
### [Custom Editor Options](scripting/advanced/custom-editor-options.md)
### [Curve](scripting/advanced/curve.md)
Expand Down

0 comments on commit 74aa4d0

Please sign in to comment.