GithubHelp home page GithubHelp logo

edgar.createscript's Introduction

CreateScript

[Unity3D | Editor]

Description

Do you use ReSharper? Do you like code templates? Wish Unity had such a feature? You're in the right place.
CreateScript is a Unity3D editor extension that adds a context menu where you can create a C# script from a template similar to ReSharper script templates in Visual Studio.

Features:

  • Free
  • Create scripts from template
  • Edit default templates
  • Create your own templates
  • Use extended preprocessor tags
  • Create custom preprocessor tags
  • Templates are per-project, share them with your entire team of 1

Tested on Unity3D 2017.3 but should work on other versions too

Installation

Either download the unity package and import it or download (clone for you fancy folk) the project and put Editor/ folder in your own project.

Upgrading

  1. Delete Scripts/ folder inside Editor/Edgar.CreateScript/
  2. Import new package
    โš  Uncheck Templates/ folder if you don't want default templates to be overwritten โš 

Usage

Right click in project view > Create Script and choose the template you wish to create.
Context menu

Other... - opens a window with a list of all templates
New template... - creates a new template
Initialize - creates config and default templates if they don't already exist
note: if default templates are not present then context menu items won't work

Default preprocessor tags

  • #DATE# - current date based on format from Config
  • #TIME# - current time based on format from Config
  • #COMAPNY# - static string, initialized from Application.companyName
  • #PRODUCT# - static string, initialized from Application.productName
  • #NAMESPACE# - static string, initialized from product name but filtered
  • #FILENAME# - name of the script file with extension
  • #SCRIPTNAME# - name of the script file without extension

To edit template contents navigate to Templates/ folder and pick a template you wish to edit. In Inspector view edit the code text area to what you desire. A preprocessor tag must be surrounded with hashsharps #.

To change default tag values navigate to Config file in root of the plugin. If this file does not exist, perform Right click > Create Script > Initialize action to create it.

Config file

Config

  • Date Format - format of the date tag. All this does is convert DateTime.Now to this format
  • Time Format - format of the time tag. -.-
  • Company name - name of the company/developer
  • Product Name - name of the game/app/whatever
  • Namespace - base namespace to be used for all scripts.
  • Namespace autonesting - if enabled, script folders will be automatically appended to namespace. For example creating a script in Scripts/Game/Internal will result in namespace Namespace.Game.Internal
  • Autonesting root folder - the root folder where scripts are stored. For example if you store your scripts in Scripts/ folder, this will be ignored when constructing namespace.
  • Custom Tags - any custom preprocessor tags can be added here

Extending

Context menu items

The easiest way to add context menu items is using EcsCustomDefinitions.cs file.

To add a context menu item, copy and paste this code into the file:

[MenuItem("Assets/Create Script/{NAME}", priority = 19)]
private static void Create{NAME}()
{
    EcsScriptTemplate.CreateScript("{TEMPLATENAME}");
}

Replace {NAME} with the name you want your item to have and {TEMPLATENAME} with the name of the template that will be created.
If you wish your menu to appear above default ones, change priority to 17 or 18. AFAIK Unity does not support dynamic adding/removing of context menus so this is the only way of adding them at this time.
EcsMenuItems.cs contains default context menu items, but editing that file is not recommended.

Additional template tags

Adding more template tags can be done in two ways: either through Config or EcsCustomDefinitions.cs file.
a) Config approach
If your custom tag values are going to be static strings, it is recommended to use Config approach.
Click on Config file in plugin root folder and in Custom Tags field add 1 or more tag. Name of the tag is what you will use in the script and value is what it will be replaced with.
Custom tag example

b) EcsCustomDefinitions.cs approach
If your custom tag needs some sort of dynamic code backing, use ProcessPreProcessor(EcsPreProcessor p) function in EcsCustomDefinitions.cs file. This function is called when a new preprocessor is created, before it preprocesses the code file. Parameter p contains a reference to said preprocessor where you can access its properties.
For example, to add a new tag add this line inside the function:

p.Tags.Add("custom", "put value here");

Screenshots

Context menu
Custom template

edgar.createscript's People

Contributors

edgarsjudovics avatar

Stargazers

Hitarth Doctor avatar Man Sun avatar

Forkers

hitarthdoc

edgar.createscript's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.