Template C# Script for Unity

Template and placeholder post:
This is the default link in my standard C# script template. It’s planned to change the link inside the class, if there is a detailed description available online. However this is the default text and you read this lines because there was no better description and no matching url for the class you inspected.

Some Background Info:
Every time you create a new C# script in Unity a template file is loaded.
It’s possible to change the template txt file directly on you OS / in your environment – so your default values / codes / script templates are loaded instead of the Unity Standards.

On Windows – you will find the templates here…
C:\Program Files (x86)\unity\Editor\Data\Resources\ScriptTemplates

Mac: /Applications/Unity/Editor/Data/Resources/ScriptTemplates
Mac (since 5.2.1f1): /Applications/Unity/Unity.app/Contents/Resources/ScriptTemplates

The template for the standard C# Class is…
81-C# Script-NewBehaviourScript.cs.txt

Version 1 of my 2018 Template:

#region MegAgeM C# Template Header
* Copyright (c) MegAgeM 2018 - @bgp
* https://www.MegAgeM.net/
* More Info         :   TXT or WWW https://www.megagem.net/2018/02/05/template-c-script-unity/?script=#SCRIPTNAME#
* C# Template Info  :   https://www.megagem.net/2018/02/05/template-c-script-unity/
* bgp - Internal    :   http://www.boegi.com/n2k/?p=6522
* Version           :   #SCRIPTNAME_LOWER#_20180000_0000_0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MegAgeM {
//[RequireComponent(typeof(Rigidbody))] // PlayerScript requires the GameObject to have a Rigidbody component
public class #SCRIPTNAME# : MonoBehaviour {
    #region variables
    //TODO - CLEAN THE TEMPLATE REGION IF NOT NEEDED! It's also available here! https://www.megagem.net/2018/02/05/template-c-script-unity/
    #region template variables
    [Header("Variables for #SCRIPTNAME#")]
    private string tmpInfoPrivate = "Private but editable in the Unity editor";
    [Tooltip("This is a Tooltip for the Unity Editor")]
    private string tmpInfoEditor = "This field has a nice Tooltip in the Unity Editor";
    public string tmpInfoPublicButHidden = "Not visible in the Unity Editor";

    public string myString;

    [TextArea] //https://docs.unity3d.com/ScriptReference/TextAreaAttribute.html
    private string tmpInfoMultilineTextArea = "This is a multiline textarea in the editor";
    public float tmpRangeTemplate = 0.5f;
[MinMaxRange(0, 2)]
    /// <summary>
    /// This XML summary is shown in Visual Studio if you place the mouse over it
    /// </summary>
    private string tmpInfoVisualStudio;
    /* Learn this in 2018 
    Three times / will add the XML summary
    Write for and Tab to get a for Loop from VS
    Use the Book symbol next to standard components to find fast results
[MinMaxRange(0, 2)]
    #endregion template variables
    #endregion variables
    #region methods
    #region template methods
    private void MethodCanBeCalledFromUnityEditor(){
        Debug.Log("YES the method was called!");
    private void InvokeAfterNSeconds(){
        Debug.Log("Invoke was executed...");
    #endregion template methods
    void Start () {
        //if(templateVar == null){ Debug.Log("templateVar was not assigned in the Inspector - Please do or code a find method."); Debug.Break();}
        //Invoke("InvokeAfterNSeconds", 2f);

	void Update () {
    #endregion methods

Additional Links:
Source: https://youtu.be/_g1TyAGk6Lk?list=PLPV2KyIb3jR4dNDPcSiAY-73gAKRIiPk4&t=190

Hidden content detected! Please login.

Enum and State Machines:
Search for PanelHandler.cs and use the TAB key (plus Arrow right) in VisualStudio to get perfect switch case code blocks for the State machine and other Enum related switch case things.

Folder Structure:

–readme.docx (Credits,Screenshots,Links)

Workflow “Asset Extraction” from AssetStorePackages:

In the main project (day2K) create a side folder named “construct”. In here the Asset will be downloaded and the asset needed will be extracted as UnityPackage.
In the main project (day2K) create another side folder “repackage”. In here the UnityPackage will be imported and fixed if needed.
Afterwards the package can be saved! but most important is the import to the new project.

Delegate and Events:
public delegate void ClickActionXYZ();
public static event ClickActionXYZ OnClicked;


Update already in the Editor?
Details see BigXlsX Knowledgebase and there the “Update Already in the Editor?!” Caption.

public virtual void Update() {

Menuitems and other Things for the Unity Editor:
MenuItems und andere Sachen für den Editor: Extract from https://unity3d.com/es/learn/tutorials/topics/tips/unity-tips-tricks-3

using UnityEditor;

In the inspector – add a button to a stringfield. (Reset to default values for example)
Im Inspektor – ein Button auf dem Feld z.B. um DefaultWerte widerherzustellen:
[ContextMenuItem(“Set my string”, “SetString”)]
public string myString;

[ContextMenuItem(“Set my string”, “SetString”)]
public string myString;

[Range(2, 5)]
public float myFloat;

[ContextMenu(“Item added to Context Menu”)]
void TestContextMenu() {
Debug.Log(“Context Menu”);

[MenuItem(“CONTEXT/Rigidbody/Double Mass”)]
static void DoubleMass(MenuCommand command) {
Rigidbody rb = (Rigidbody)command.context;
rb.mass = rb.mass * 2;

[MenuItem(“Tools/3D/Set Mass”)]
static void SetMass() {

Add Pragma Info to get rid of some ErrorMessages 😉

Some values in the current code (see at top – did not work) / They are from a tutorial on ScriptableObjects and only valid with the other settings from this tutorial!