Automating / Inheritance

Is there an option to change the script inheritance.Instead to inherit automatically from our script and not MonotBehaviour?
Also,the new template to have our methods and not Start() and Update().

Why would you want to do that?

You can change the default template. This question seems to cover it pretty well.

http://answers.unity3d.com/questions/120957/change-the-default-script-template.html

You can also create script files in your code editor, using whatever templates you choose.

If your game is built on a custom framework within Unity then MonoBehaviour, Start and Update might get a bit annoying. If you have to delete them every single time…

It’s also pretty easy to make a script that copies your own templates, and assign it to the same menu that you create “normal” scripts from. Copied from our project:

public static class CreateScriptHelper {

    [MenuItem("Assets/Create/C# Script Template/Class", false, 0)]
    public static void CreateClass() {
        string path_to_template = ...; //Wherever you've put your template.

        string path_to_new = FindPathToCurrent() + "/NewScript.cs";

        File.Copy(path_to_template, path_to_new);
    }

    //This find the path to the current selected folder.
    private static string FindPathToCurrent() {
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        //Default to assets if the current selection is in the scene, or nothing
        if (path == "") {
            path = "Assets";
        }
        //"if the selected thing is a file, place this next to the file"
        else if (Path.GetExtension(path) != "") {
            path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
        }
        return path;
    }
}

Solving problems like finding a unique file name, and checking that the copying actually works (my version just have the file contents hard-coded in a string) is left as an exercise to the reader.

1 Like