├── .gitignore ├── 80-C# Class-MyClass.cs.txt ├── 80-MonoBehaviour-MyBehaviour.cs.txt ├── 80-Scriptable Object-NewScriptableObject.cs.txt ├── 81-Other Scripts__Editor Window-MyEditorWindow.cs.txt ├── 81-Other Scripts__Editor-MyEditor.cs.txt ├── 81-Other Scripts__Playables__Playable Asset-NewPlayableAsset.cs.txt ├── 81-Other Scripts__Playables__Playable Behaviour-NewPlayableBehaviour.cs.txt ├── 81-Other Scripts__State Machines__State Machine Behaviour-NewStateMachineBehaviourScript.cs.txt ├── 81-Other Scripts__State Machines__Sub-State Machine Behaviour-NewSubStateMachineBehaviourScript.cs.txt ├── 85-Shader__Compute Shader-NewComputeShader.compute.txt ├── 85-Shader__Image Effect Shader-NewImageEffectShader.shader.txt ├── 85-Shader__Ray Tracing Shader-NewRayTracingShader.raytrace.txt ├── 85-Shader__Standard Surface Shader-NewSurfaceShader.shader.txt ├── 85-Shader__Unlit Shader-NewUnlitShader.shader.txt ├── 85-Text File__JSON-NewJSONData.json.txt ├── 85-Text File__MarkDown-NewDoc.md.txt ├── 85-Text File__Text-NewDoc.txt.txt ├── 85-Text File__XML-NewXMLData.xml.txt ├── 90-Assembly Definition__Assembly Definition-Domain.Unity.Name.asmdef.txt ├── 90-Assembly Definition__Editor Assembly Definition-Domain.Unity.Name.Editor.asmdef.txt ├── 90-Assembly Definition__Tests Assembly Definition-Domain.Unity.Name.Tests.asmdef.txt ├── README.md └── menu-example.png /.gitignore: -------------------------------------------------------------------------------- 1 | DefaultTemplates/ -------------------------------------------------------------------------------- /80-C# Class-MyClass.cs.txt: -------------------------------------------------------------------------------- 1 | //using UnityEngine; 2 | 3 | #ROOTNAMESPACEBEGIN# 4 | 5 | /// 6 | /// 7 | /// 8 | //[System.Serializable] 9 | public class #SCRIPTNAME# 10 | { 11 | 12 | #region Fields 13 | #endregion 14 | 15 | 16 | #region Lifecycle 17 | 18 | public #SCRIPTNAME#() 19 | { 20 | #NOTRIM# 21 | } 22 | 23 | #endregion 24 | 25 | 26 | #region Public API 27 | #endregion 28 | 29 | } 30 | 31 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /80-MonoBehaviour-MyBehaviour.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | #ROOTNAMESPACEBEGIN# 4 | 5 | /// 6 | /// 7 | /// 8 | //[AddComponentMenu("#SCRIPTNAME#")] 9 | public class #SCRIPTNAME# : MonoBehaviour 10 | { 11 | 12 | #region Fields 13 | #endregion 14 | 15 | 16 | #region Lifecycle 17 | #endregion 18 | 19 | 20 | #region Public API 21 | #endregion 22 | 23 | } 24 | 25 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /80-Scriptable Object-NewScriptableObject.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | #ROOTNAMESPACEBEGIN# 4 | 5 | /// 6 | /// 7 | /// 8 | //[CreateAssetMenu(fileName = "New#SCRIPTNAME#", menuName = "#SCRIPTNAME#")] 9 | public class #SCRIPTNAME# : ScriptableObject 10 | { 11 | 12 | #region Fields 13 | #endregion 14 | 15 | 16 | #region Public API 17 | #endregion 18 | 19 | } 20 | 21 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /81-Other Scripts__Editor Window-MyEditorWindow.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | #ROOTNAMESPACEBEGIN# 5 | 6 | /// 7 | /// 8 | /// 9 | public class #SCRIPTNAME# : EditorWindow 10 | { 11 | 12 | #region Fields 13 | 14 | private const string WINDOW_TITLE = "#SCRIPTNAME#"; 15 | private const string MENU_ITEM = "Tools/" + WINDOW_TITLE; 16 | 17 | #endregion 18 | 19 | 20 | #region Lifecycle 21 | 22 | /// 23 | /// Called when this window is open. 24 | /// 25 | private void OnEnable() 26 | { 27 | #NOTRIM# 28 | } 29 | 30 | #endregion 31 | 32 | 33 | #region Public API 34 | 35 | /// 36 | /// Opens this editor window. 37 | /// 38 | [MenuItem(MENU_ITEM)] 39 | public static #SCRIPTNAME# Open() 40 | { 41 | #SCRIPTNAME# window = GetWindow<#SCRIPTNAME#>(false, WINDOW_TITLE, true); 42 | window.Show(); 43 | return window; 44 | } 45 | 46 | #endregion 47 | 48 | 49 | #region UI 50 | 51 | /// 52 | /// Draws this window GUI on screen. 53 | /// 54 | private void OnGUI() 55 | { 56 | #NOTRIM# 57 | } 58 | 59 | #endregion 60 | 61 | } 62 | 63 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /81-Other Scripts__Editor-MyEditor.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | #ROOTNAMESPACEBEGIN# 5 | 6 | /// 7 | /// Custom editor for objects. 8 | /// 9 | [CustomEditor(typeof(#SCRIPTNAME#))] 10 | public class #SCRIPTNAME# : Editor 11 | { 12 | 13 | #region Fields 14 | #endregion 15 | 16 | 17 | #region Lifecycle 18 | 19 | /// 20 | /// Called when this editor is loaded. 21 | /// 22 | private void OnEnable() 23 | { 24 | #NOTRIM# 25 | } 26 | 27 | #endregion 28 | 29 | 30 | #region UI 31 | 32 | /// 33 | /// Draws the GUI for the edited object(s). 34 | /// 35 | public override void OnInspectorGUI() 36 | { 37 | base.OnInspectorGUI(); 38 | } 39 | 40 | #endregion 41 | 42 | } 43 | 44 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /81-Other Scripts__Playables__Playable Asset-NewPlayableAsset.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Playables; 3 | 4 | #ROOTNAMESPACEBEGIN# 5 | 6 | /// 7 | /// 8 | /// 9 | [System.Serializable] 10 | public class #SCRIPTNAME# : PlayableAsset 11 | { 12 | 13 | /// 14 | /// Factory method that generates a playable based on this asset. 15 | /// 16 | public override Playable CreatePlayable(PlayableGraph graph, GameObject go) 17 | { 18 | return Playable.Create(graph); 19 | } 20 | 21 | } 22 | 23 | #ROOTNAMESPACEEND# 24 | -------------------------------------------------------------------------------- /81-Other Scripts__Playables__Playable Behaviour-NewPlayableBehaviour.cs.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Playables; 3 | 4 | #ROOTNAMESPACEBEGIN# 5 | 6 | /// 7 | /// Behaviour meant to be attached to a Playable object. 8 | /// 9 | public class #SCRIPTNAME# : PlayableBehaviour 10 | { 11 | 12 | /// 13 | /// Called when the owning graph starts playing. 14 | /// 15 | public override void OnGraphStart(Playable playable) 16 | { 17 | #NOTRIM# 18 | } 19 | 20 | /// 21 | /// Called when the owning graph stops playing 22 | /// 23 | public override void OnGraphStop(Playable playable) 24 | { 25 | #NOTRIM# 26 | } 27 | 28 | /// 29 | /// Called when the state of the playable is set to Play. 30 | /// 31 | public override void OnBehaviourPlay(Playable playable, FrameData info) 32 | { 33 | #NOTRIM# 34 | } 35 | 36 | /// 37 | /// Called when the state of the playable is set to Paused. 38 | /// 39 | public override void OnBehaviourPause(Playable playable, FrameData info) 40 | { 41 | #NOTRIM# 42 | } 43 | 44 | /// 45 | /// Called each frame while the state is set to Play. 46 | /// 47 | public override void PrepareFrame(Playable playable, FrameData info) 48 | { 49 | #NOTRIM# 50 | } 51 | 52 | } 53 | 54 | #ROOTNAMESPACEEND# 55 | -------------------------------------------------------------------------------- /81-Other Scripts__State Machines__State Machine Behaviour-NewStateMachineBehaviourScript.cs.txt: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #ROOTNAMESPACEBEGIN# 6 | 7 | /// 8 | /// 9 | /// 10 | public class #SCRIPTNAME# : StateMachineBehaviour 11 | { 12 | 13 | /// 14 | /// Called when a transition starts and the state machine starts to evaluate this state. 15 | /// 16 | override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 17 | { 18 | #NOTRIM# 19 | } 20 | 21 | /// 22 | /// Called on each Update frame between OnStateEnter and OnStateExit callbacks. 23 | /// 24 | override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 25 | { 26 | #NOTRIM# 27 | } 28 | 29 | /// 30 | /// Called when a transition ends and the state machine finishes evaluating this state. 31 | /// 32 | override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 33 | { 34 | #NOTRIM# 35 | } 36 | 37 | /// 38 | /// Called right after .
39 | /// Implements code that processes and affects root motion. 40 | ///
41 | // override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 42 | // { 43 | #NOTRIM# 44 | // } 45 | 46 | /// 47 | /// Called right after .
48 | /// Implements code that sets up animation IK (inverse kinematics). 49 | ///
50 | // override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 51 | // { 52 | #NOTRIM# 53 | // } 54 | } 55 | 56 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /81-Other Scripts__State Machines__Sub-State Machine Behaviour-NewSubStateMachineBehaviourScript.cs.txt: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #ROOTNAMESPACEBEGIN# 6 | 7 | /// 8 | /// 9 | /// 10 | public class #SCRIPTNAME# : StateMachineBehaviour 11 | { 12 | 13 | /// 14 | /// Called before OnStateEnter is called on any state inside this state machine. 15 | /// 16 | override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 17 | { 18 | #NOTRIM# 19 | } 20 | 21 | /// 22 | /// Called before OnStateUpdate is called on any state inside this state machine. 23 | /// 24 | override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 25 | { 26 | #NOTRIM# 27 | } 28 | 29 | /// 30 | /// Called before OnStateExit is called on any state inside this state machine. 31 | /// 32 | override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 33 | { 34 | #NOTRIM# 35 | } 36 | 37 | /// 38 | /// Called before OnStateMove is called on any state inside this state machine. 39 | /// 40 | override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 41 | { 42 | #NOTRIM# 43 | } 44 | 45 | /// 46 | /// Called before is called on any state inside this state machine. 47 | /// 48 | //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 49 | // { 50 | #NOTRIM# 51 | // } 52 | 53 | /// 54 | /// Called when entering a state machine via its Entry Node. 55 | /// 56 | //override public void OnStateMachineEnter(Animator animator, int stateMachinePathHash) 57 | // { 58 | #NOTRIM# 59 | // } 60 | 61 | /// 62 | /// Called when exiting a state machine via its Exit Node. 63 | /// 64 | //override public void OnStateMachineExit(Animator animator, int stateMachinePathHash) 65 | // { 66 | #NOTRIM# 67 | // } 68 | 69 | } 70 | 71 | #ROOTNAMESPACEEND# -------------------------------------------------------------------------------- /85-Shader__Compute Shader-NewComputeShader.compute.txt: -------------------------------------------------------------------------------- 1 | // Each #kernel tells which function to compile; you can have many kernels 2 | #pragma kernel CSMain 3 | 4 | // Create a RenderTexture with enableRandomWrite flag and set it 5 | // with cs.SetTexture 6 | RWTexture2D Result; 7 | 8 | [numthreads(8,8,1)] 9 | void CSMain (uint3 id : SV_DispatchThreadID) 10 | { 11 | // TODO: insert actual code here! 12 | 13 | Result[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0); 14 | } 15 | -------------------------------------------------------------------------------- /85-Shader__Image Effect Shader-NewImageEffectShader.shader.txt: -------------------------------------------------------------------------------- 1 | Shader "Hidden/#NAME#" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | // No culling or depth 10 | Cull Off ZWrite Off ZTest Always 11 | 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vert 16 | #pragma fragment frag 17 | 18 | #include "UnityCG.cginc" 19 | 20 | struct appdata 21 | { 22 | float4 vertex : POSITION; 23 | float2 uv : TEXCOORD0; 24 | }; 25 | 26 | struct v2f 27 | { 28 | float2 uv : TEXCOORD0; 29 | float4 vertex : SV_POSITION; 30 | }; 31 | 32 | v2f vert (appdata v) 33 | { 34 | v2f o; 35 | o.vertex = UnityObjectToClipPos(v.vertex); 36 | o.uv = v.uv; 37 | return o; 38 | } 39 | 40 | sampler2D _MainTex; 41 | 42 | fixed4 frag (v2f i) : SV_Target 43 | { 44 | fixed4 col = tex2D(_MainTex, i.uv); 45 | // just invert the colors 46 | col.rgb = 1 - col.rgb; 47 | return col; 48 | } 49 | ENDCG 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /85-Shader__Ray Tracing Shader-NewRayTracingShader.raytrace.txt: -------------------------------------------------------------------------------- 1 | RWTexture2D RenderTarget; 2 | 3 | #pragma max_recursion_depth 1 4 | 5 | [shader("raygeneration")] 6 | void MyRaygenShader() 7 | { 8 | uint2 dispatchIdx = DispatchRaysIndex().xy; 9 | 10 | RenderTarget[dispatchIdx] = float4(dispatchIdx.x & dispatchIdx.y, (dispatchIdx.x & 15)/15.0, (dispatchIdx.y & 15)/15.0, 0.0); 11 | } 12 | -------------------------------------------------------------------------------- /85-Shader__Standard Surface Shader-NewSurfaceShader.shader.txt: -------------------------------------------------------------------------------- 1 | Shader "Custom/#NAME#" 2 | { 3 | Properties 4 | { 5 | _Color ("Color", Color) = (1,1,1,1) 6 | _MainTex ("Albedo (RGB)", 2D) = "white" {} 7 | _Glossiness ("Smoothness", Range(0,1)) = 0.5 8 | _Metallic ("Metallic", Range(0,1)) = 0.0 9 | } 10 | SubShader 11 | { 12 | Tags { "RenderType"="Opaque" } 13 | LOD 200 14 | 15 | CGPROGRAM 16 | // Physically based Standard lighting model, and enable shadows on all light types 17 | #pragma surface surf Standard fullforwardshadows 18 | 19 | // Use shader model 3.0 target, to get nicer looking lighting 20 | #pragma target 3.0 21 | 22 | sampler2D _MainTex; 23 | 24 | struct Input 25 | { 26 | float2 uv_MainTex; 27 | }; 28 | 29 | half _Glossiness; 30 | half _Metallic; 31 | fixed4 _Color; 32 | 33 | // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. 34 | // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. 35 | // #pragma instancing_options assumeuniformscaling 36 | UNITY_INSTANCING_BUFFER_START(Props) 37 | // put more per-instance properties here 38 | UNITY_INSTANCING_BUFFER_END(Props) 39 | 40 | void surf (Input IN, inout SurfaceOutputStandard o) 41 | { 42 | // Albedo comes from a texture tinted by color 43 | fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; 44 | o.Albedo = c.rgb; 45 | // Metallic and smoothness come from slider variables 46 | o.Metallic = _Metallic; 47 | o.Smoothness = _Glossiness; 48 | o.Alpha = c.a; 49 | } 50 | ENDCG 51 | } 52 | FallBack "Diffuse" 53 | } 54 | -------------------------------------------------------------------------------- /85-Shader__Unlit Shader-NewUnlitShader.shader.txt: -------------------------------------------------------------------------------- 1 | Shader "Unlit/#NAME#" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags { "RenderType"="Opaque" } 10 | LOD 100 11 | 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vert 16 | #pragma fragment frag 17 | // make fog work 18 | #pragma multi_compile_fog 19 | 20 | #include "UnityCG.cginc" 21 | 22 | struct appdata 23 | { 24 | float4 vertex : POSITION; 25 | float2 uv : TEXCOORD0; 26 | }; 27 | 28 | struct v2f 29 | { 30 | float2 uv : TEXCOORD0; 31 | UNITY_FOG_COORDS(1) 32 | float4 vertex : SV_POSITION; 33 | }; 34 | 35 | sampler2D _MainTex; 36 | float4 _MainTex_ST; 37 | 38 | v2f vert (appdata v) 39 | { 40 | v2f o; 41 | o.vertex = UnityObjectToClipPos(v.vertex); 42 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 43 | UNITY_TRANSFER_FOG(o,o.vertex); 44 | return o; 45 | } 46 | 47 | fixed4 frag (v2f i) : SV_Target 48 | { 49 | // sample the texture 50 | fixed4 col = tex2D(_MainTex, i.uv); 51 | // apply fog 52 | UNITY_APPLY_FOG(i.fogCoord, col); 53 | return col; 54 | } 55 | ENDCG 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /85-Text File__JSON-NewJSONData.json.txt: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /85-Text File__MarkDown-NewDoc.md.txt: -------------------------------------------------------------------------------- 1 | # Title 2 | 3 | [Markdown Cheat Sheet](https://www.markdownguide.org/cheat-sheet): https://www.markdownguide.org/cheat-sheet -------------------------------------------------------------------------------- /85-Text File__Text-NewDoc.txt.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /85-Text File__XML-NewXMLData.xml.txt: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /90-Assembly Definition__Assembly Definition-Domain.Unity.Name.asmdef.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "#SCRIPTNAME#" 3 | } 4 | -------------------------------------------------------------------------------- /90-Assembly Definition__Editor Assembly Definition-Domain.Unity.Name.Editor.asmdef.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "#SCRIPTNAME#", 3 | "includePlatforms": [ 4 | "Editor" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /90-Assembly Definition__Tests Assembly Definition-Domain.Unity.Name.Tests.asmdef.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "#SCRIPTNAME#", 3 | "optionalUnityReferences": [ 4 | "TestAssemblies" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Script Templates 2 | 3 | This repository is a bundle of the Script Templates I use in my Unity Projets. 4 | 5 | ## Setup Script templates in Unity 6 | 7 | What I'm calling Script Templates are the scripts generated by Unity when you create a new C# Script for examples. 8 | 9 | They are written in your Unity Installation, in `Editor/Data/Resources/ScriptTemplates`. You can notice a specific file naming, see below for more informations about that. 10 | 11 | To setup my custom Unity script tempates, download or clone this repo into your Unity install folder. If your Unity editor is open when you set these files, close it and reopen it. 12 | 13 | ```bash 14 | git clone https://github.com/DaCookie/unity-script-templates 15 | ``` 16 | 17 | Now, if you try to create a new Asset (by right-clicking in the `Project` view, or from `Assets` menu), you can see some new menus for script creation ! 18 | 19 | ![Create asset menu example](menu-example.png) 20 | 21 | Obviously, you can create your own script templates, or simply adapt mines for your common usage. 22 | 23 | ## Script Templates naming 24 | 25 | You can see that all the template scripts files have a specific naming syntax : 26 | 27 | ``` 28 | 85-Other Scripts__Scriptable Object-MyClass.cs.txt 29 | ``` 30 | 31 | Let's see the composition of that... thing : 32 | 33 | | 85 | Other Scripts | Scriptable Object | MyClass | .cs | 34 | | - | - | - | - | - | 35 | | Menu position | Menu name | Submenu name | Default name of the new created file | Created file extension | 36 | 37 | Note that submenus are facultative, but you can setup as many submenus as you want, by separating elements with "`__`". 38 | 39 | ## Script Template content 40 | 41 | You can make script templates of any text asset you want (it can be C#, JSON, XML, YAML, TXT, or any code or text content). 42 | 43 | Inside these scripts, you can also use `#SCRIPTNAME#` keyword. When Unity generates the new asset, it will replace that keyword by the created file name. It can be useful for automating class name generation. 44 | -------------------------------------------------------------------------------- /menu-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hubertgdev/unity-script-templates/d7c2226c4729f70965ad2632f93ae1c66bdc40a0/menu-example.png --------------------------------------------------------------------------------