Skip to content

Instantly share code, notes, and snippets.

@johnsoncodehk
Last active January 18, 2024 10:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnsoncodehk/03d3871a1453d795162a6dbf01f904c3 to your computer and use it in GitHub Desktop.
Save johnsoncodehk/03d3871a1453d795162a6dbf01f904c3 to your computer and use it in GitHub Desktop.
Create script from template in project
// Not support of 2019.1.0f1
static void CreateScriptAsset(string templatePath, string destName) {
#if UNITY_2019_1_OR_NEWER
UnityEditor.ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, destName);
#else
typeof(UnityEditor.ProjectWindowUtil)
.GetMethod("CreateScriptAsset", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
.Invoke(null, new object[] { templatePath, destName });
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment