Need help with Editor script

Hey all,

I’m needing to make an editor script which a) starts automatically to init some stuff when I open my project (possible?) b) accepts some input (I know how to make a Wizard, is that the only option?) and c) periodically runs something (like Update, doesn’t have to be every frame though).

Is that all possible?

a) starts automatically to init some stuff when I open my project (possible?)

Yes this is possible:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public static class SomeEditorScript {

    static SomeEditorScript() {
        // Do your stuff here...
    }

}

See: Unity - Manual: Running Editor Script Code on Launch

b) accepts some input (I know how to make a Wizard, is that the only option?)

You can create your own custom interfaces by creating your very own editor windows. As of the time of writing you cannot automatically display a window when your script first loads, but you can add a custom menu item which displays your interface:

using UnityEngine;
using UnityEditor;

public static class SomeEditorWindow : EditorWindow {

    [MenuItem("Your Stuff/Some Editor Window")]
    static void Show() {
        GetWindow<SomeEditorWindow>();
    }

    void OnEnable() {
        title = "My Editor Window";
    }

    void OnGUI() {
        GUILayout.Label("Place your controls here!");

        if (GUILayout.Button("Foo")) {
            // Do something here!
            GUIUtility.ExitGUI();
        }
    }

}

See: Unity - Scripting API: EditorWindow

c) periodically runs something (like Update, doesn’t have to be every frame though).

There are several ways to do this depending upon what you are trying to achieve. The most generic solution is to attach an event handler as demonstrated below. This will frequently invoke your custom event handler. You can manually limit how often your logic is executed using the .NET DateTime class.

void SomeFunctionToInitializeEvent() {
    EditorApplication.update += delegate {
        // Do your stuff here!
    };
}

// or alternatively you can use this syntax:

void SomeFunctionToInitializeEvent() {
    EditorApplication.update += new CallbackFunction(MyEventHandler);
}

void MyEventHandler() {
    // Do your stuff here!
}

See: Unity - Scripting API: EditorApplication.update

The following documentation includes references to other callbacks that may be of use to you: Unity - Scripting API: EditorApplication

It is also worth noting that you can use the Update message in your custom EditorWindow which is called at regular intervals so long as the window is open.

I hope that this is of help to you.