Last active
July 13, 2021 19:34
-
-
Save UrbanNuke/205ec318426ba8093d46fbbe64628b7f to your computer and use it in GitHub Desktop.
Extend Unity script templates
This file contains 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
/* | |
* #CREATIONDATE# | |
* #PROJECTNAME# created by #COMPANYNAME# | |
*/ | |
using UnityEngine; | |
#ROOTNAMESPACEBEGIN# | |
namespace #PROJECTNAME# | |
{ | |
/// <summary> | |
/// Brief summary of what the class does | |
/// </summary> | |
public class #SCRIPTNAME# : MonoBehaviour | |
{ | |
#region Fields | |
#NOTRIM# | |
#endregion | |
#NOTRIM# | |
#region Properties | |
#NOTRIM# | |
#endregion | |
#NOTRIM# | |
#region LifeCycles | |
private void Awake() | |
{ | |
#NOTRIM# | |
} | |
private void Start() | |
{ | |
#NOTRIM# | |
} | |
private void Update() | |
{ | |
#NOTRIM# | |
} | |
#endregion | |
#NOTRIM# | |
#region PublicMethods | |
#NOTRIM# | |
#endregion | |
#NOTRIM# | |
} | |
} | |
#ROOTNAMESPACEEND# |
This file contains 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 UnityEditor; | |
using System.IO; | |
public class ScriptPreprocessor : UnityEditor.AssetModificationProcessor | |
{ | |
public static void OnWillCreateAsset(string metaFilePath) | |
{ | |
string fileName = Path.GetFileNameWithoutExtension(metaFilePath); | |
if (!fileName.EndsWith(".cs")) | |
return; | |
string actualFilePath = $"{Path.GetDirectoryName(metaFilePath)}{Path.DirectorySeparatorChar}{fileName}"; | |
string content = File.ReadAllText(actualFilePath); | |
string newContent = content.Replace("#PROJECTNAME#", PlayerSettings.productName); | |
newContent = newContent.Replace("#CREATIONDATE#", System.DateTime.Now + ""); | |
newContent = newContent.Replace("#COMPANYNAME#", PlayerSettings.companyName); | |
if (content == newContent) | |
return; | |
File.WriteAllText(actualFilePath, newContent); | |
AssetDatabase.Refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment