- Home /
Creating a new code template
Hi, I have done a ton of searching and still can't find an answer to this. I have created a fairly complex framework that I want everyone to easily customize and use. In order to write scripts using this framework, one needs to do all sorts of small stuff, including using different namespaces and overriding functions. I saw that it was possible to change the default code template, so When you hit 'Project>Create>New Language Script' it has all of your regions and such that you normally use. I was wondering if it were possible to create an entirely new code template that could be used like 'Project>Create>New Language Automation' for instance.
In case you are wondering why on earth I would want to do this, right now users can create their own cellular automations by inheriting from a class, but they also have to override all of the methods of that class. I also wanted to remove the 'using UnityEngine' part, since it's multithreaded and I didn't want users to accidentally use Unity stuff in there.
Is it possible to do something like this? Thanks in advance!
Answer by DiegoSLTS · Jul 08, 2015 at 02:54 AM
You can extend the Unity editor with a script that adds an option to almost any menu. That option could create the new file with the default code you want. I don't have a lot of experience with editor scripts, but I'm sure you can do this, lots of plugins create new script files with custom code inside after choosing an option.
Thanks! I don't know why I didn't think of that... But that means I could have it generated from a custom editor, too, which would be nice. This is exactly what I was looking for!
Answer by Itinerant · Jul 07, 2015 at 07:05 PM
I did a bit of searching through the forums, and came across this article. It should help you do what you want:
That just changes the default template for the script you make with 'New C# script' or 'New Javascript'. I was wondering if it were possible to create another one, not the default, that would be set up to use my framework. That way, you could still easily create normal scripts, as well as automator scripts. I don't want to rewrite the original, I want to make a new one that is set up for a different purpose.