Last active
May 10, 2024 16:41
-
-
Save nicoplv/3e65b261e6d1693db38fea2b67813c8d to your computer and use it in GitHub Desktop.
List of C# Script Templates for Unity 3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List of C# Script Templates for Unity 3D: | |
81-C#__Behavior-NewBehaviour.cs.txt | |
81-C#__BehaviorListed-NewBehaviourListed.cs.txt | |
81-C#__Class-NewClass.cs.txt | |
81-C#__Interface-NewInterface.cs.txt | |
81-C#__ScriptableObject-NewScriptableObject.cs.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace #NAMESPACE# | |
{ | |
public class #SCRIPTNAME# : MonoBehaviour | |
{ | |
#region Variables | |
#endregion | |
#region Unity Methods | |
public void Start() | |
{ | |
} | |
public void Update() | |
{ | |
} | |
#endregion | |
#region Methods | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace #NAMESPACE# | |
{ | |
public class #SCRIPTNAME# : MonoBehaviour | |
{ | |
#region Variables | |
private static List<#SCRIPTNAME#> list = new List<#SCRIPTNAME#>(); | |
public static List<#SCRIPTNAME#> List { get { return list; } } | |
#endregion | |
#region Unity Methods | |
public void OnEnable() | |
{ | |
list.Add(this); | |
} | |
public void Start() | |
{ | |
} | |
public void Update() | |
{ | |
} | |
public void OnDisable() | |
{ | |
list.Remove(this); | |
} | |
#endregion | |
#region Methods | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace #NAMESPACE# | |
{ | |
public class #SCRIPTNAME# | |
{ | |
#region Variables | |
#endregion | |
#region Constructor | |
public #SCRIPTNAME#() | |
{ | |
} | |
#endregion | |
#region Methods | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace #NAMESPACE# | |
{ | |
public interface #SCRIPTNAME# | |
{ | |
#region Methods | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace #NAMESPACE# | |
{ | |
[CreateAssetMenu(fileName = "#SCRIPTNAME#", menuName = "#SCRIPTNAME#")] | |
public class #SCRIPTNAME# : ScriptableObject | |
{ | |
#region Variables | |
#endregion | |
#region Unity Methods | |
public void Start() | |
{ | |
} | |
public void Update() | |
{ | |
} | |
#endregion | |
#region Methods | |
#endregion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
using System.Linq; | |
internal sealed class ScriptKeywordProcessor : UnityEditor.AssetModificationProcessor | |
{ | |
private static char[] spliters = new char[] { '/', '\\', '.' }; | |
private static List<string> wordsToDelete = new List<string>(){ "Extensions", "Scripts", "Editor"}; | |
public static void OnWillCreateAsset(string path) | |
{ | |
path = path.Replace(".meta", ""); | |
int index = path.LastIndexOf("."); | |
if (index < 0) | |
return; | |
string file = path.Substring(index); | |
if (file != ".cs" && file != ".js") | |
return; | |
List<string> namespaces = path.Split(spliters).ToList<string>(); | |
namespaces = namespaces.GetRange(1, namespaces.Count - 3); | |
namespaces = namespaces.Except(wordsToDelete).ToList<string>(); | |
string namespaceString = "Globals"; | |
for (int i = 0; i < namespaces.Count; i++) | |
{ | |
if (i == 0) | |
namespaceString = ""; | |
namespaceString += namespaces[i]; | |
if (i < namespaces.Count - 1) | |
namespaceString += "."; | |
} | |
index = Application.dataPath.LastIndexOf("Assets"); | |
path = Application.dataPath.Substring(0, index) + path; | |
if (!System.IO.File.Exists(path)) | |
return; | |
string fileContent = System.IO.File.ReadAllText(path); | |
fileContent = fileContent.Replace("#NAMESPACE#", namespaceString); | |
System.IO.File.WriteAllText(path, fileContent); | |
AssetDatabase.Refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks mate!!