playMaker

Author Topic: Tip: Custom Action Template  (Read 267 times)

Thore

  • Sr. Member
  • ****
  • Posts: 442
    • View Profile
Tip: Custom Action Template
« on: June 09, 2020, 07:55:05 AM »
I've come across this neat little trick. You know when you create a new script, you have it pre-filled with some standard Unity stuff (using statements, Enter and Update methods). You can customise it (Unity documentation)

Where it's interesting for PlayMaker users: you can make a template for PlayMaker actions (and Scriptable Objects), too.

You have a few options. You can either do this for the entire Unity installation (see link above), or for a particular project, which I am going to show. You can replace the standard C# template with your own, but I am showing how to make a submenu that houses your own templates for some common script types. This keeps the standard as well.

/// HOW TO ///
  • Close Unity (it will take effect only after a restart).
  • under Assets/ make a folder named ScriptTemplates
  • Right click, and open the folder in explorer/finder, not Unity.

In there, you need to place simple txt files with a certain file name. Inside the txt file, you define your template. There's only one parameter and that's #SCRIPTNAME# which will be substituted with the name you give when you make a new file. I have these three:

Code: [Select]
81-New Script__C# Script-NewBehaviourScript.cs
81-New Script__PlayMaker Action-NewPlayMakerAction.cs
81-New Script__Scriptable Object-NewScriptableObject.cs

81 is some Unity voodoo that determines where it's placed in the context menu. New Script is the menu name, then there are TWO underscores and then the name in the submenu to create from that template, and finally the default name of the newly created file.

I attach examples below, which you can customise (at least fill in author name, and namespace, or delete it, if you don't need it).

Oh, and to uninstall/remove this, just delete the file/folder again, and restart.
« Last Edit: June 15, 2020, 12:24:31 PM by Thore »

Rebooter

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Tip: Custom Action Template
« Reply #1 on: June 21, 2020, 08:30:27 PM »
Thanks for this, very nice.