Script generation.

I am thinking of writing an extension for unity Editor. I want to create a ‘setup’ window, which will do some work for me and setup any new project based on settings I choose. For example: I check ‘google play’, ‘save files’ and ‘achievements’ checkboxes and hit ‘Setup’ button. Now, based on these settings the script would generate necessary generic classes for me.

Now for the questions:

  1. How can I store code template files so my extention would read it? What type? Xml? Other?
    the extension needs to save those templates as .cs files
  2. How can I specify what to read? Reading from line X to line Y would be ok., but ideally I need something like this: look for a text “JFHDDI” (for example) → read until you come across this “HFIDDN” → then build a .cs file from what you have read.
  3. Can I edit .cs scripts with another script (not runtime of course)?

Although, I could store my code templates as xml files I still can’t find solution to my second question.

Any help much appreciated.

I did something of this kind, it first depend if you need to have ‘arguments’ of generation or not. I think the best way for what you say is to keep the classes in txt files (online or not), with eventually a file that contain a register of all files, and just use File.Copy(from, to); to generate the files. If you need arguments, it’s getting harder, but you can develop a pseudo programming language for it, like when reading, if you go through a line that start with ~$: it mean it’s a special code line, and you need to see what it mean eg:

public class Foo
public Foo()

Maybe try something like that. If you want, I can help you create a pseudo code like this, i think it’s interesting :wink:

good luck :slight_smile: