Skip to content

Instantly share code, notes, and snippets.

@Wolfos
Last active February 21, 2017 12:32
Show Gist options
  • Save Wolfos/3eb651879e92cf86c2881243f7f74632 to your computer and use it in GitHub Desktop.
Save Wolfos/3eb651879e92cf86c2881243f7f74632 to your computer and use it in GitHub Desktop.
// Put this file in Assets/Editor/
using UnityEngine;
using UnityEditor;
public class KeywordReplace : UnityEditor.AssetModificationProcessor
{
public static void OnWillCreateAsset(string path)
{
path = path.Replace(".meta", "");
int index = path.LastIndexOf(".");
string file;
try
{
file = path.Substring(index);
}
catch(System.ArgumentOutOfRangeException)
{
return;
}
if (!file.Contains(".cs")) return;
index = Application.dataPath.LastIndexOf("Assets");
path = Application.dataPath.Substring(0, index) + path;
file = System.IO.File.ReadAllText(path);
string[] splitPath = path.Split('/');
string folder = splitPath[splitPath.Length - 2];
file = file.Replace("#NAMESPACE#", folder);
file = file.Replace("#CREATIONDATE#", System.DateTime.Now + "");
file = file.Replace("#PROJECTNAME#", PlayerSettings.productName);
file = file.Replace("#DEVELOPERS#", PlayerSettings.companyName);
System.IO.File.WriteAllText(path, file);
AssetDatabase.Refresh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment