-
-
Save JohannesMP/74d2b5b58dc89aee03d8515c551943ac to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
public class ScriptAssetProcessor : UnityEditor.AssetModificationProcessor | |
{ | |
public static void OnWillCreateAsset(string path) | |
{ | |
string filePath = GetAbsoluteFilePath(path.Replace(".meta", "")); | |
if(!FileIsScript(filePath)) return; | |
// Add a demo comment to the top of scripts | |
string fileContent = System.IO.File.ReadAllText(filePath); | |
fileContent = "// Demo!" + System.Environment.NewLine + fileContent; | |
System.IO.File.WriteAllText(filePath, fileContent); | |
AssetDatabase.Refresh(); // Force a script recompile | |
} | |
static bool FileIsScript(string filePath) | |
{ | |
var extension = System.IO.Path.GetExtension(filePath); | |
return (extension == ".cs" || extension == ".js" || extension == ".boo"); | |
} | |
static string GetAbsoluteFilePath(string path) | |
{ | |
var index = Application.dataPath.LastIndexOf("Assets"); | |
return Application.dataPath.Substring(0, index) + path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment