I'd like to run and editor script as soon as Unity launches. The closest I've been able to come is by using a CustomEditor on type Object, which launches as soon as something is selected.
Is it possible to run an editor script function when the Unity editor launches?
This could help
edit:
new link: Can I auto run a script when editor launches or a project finishes loading? - Questions & Answers - Unity Discussions
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class Autorun
{
static Autorun()
{
Debug.Log("Autorun!");
}
}
or if u want for the scene to be loaded, hook to the editor update callback
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class Autorun
{
static Autorun()
{
EditorApplication.update += RunOnce;
}
static void RunOnce()
{
Debug.Log("RunOnce!");
EditorApplication.update -= RunOnce;
}
}
qJake
2
You could try a couple of different methods with OnEnable() (for example, on a class derived from "Editor", or on a custom editor window, or something like that). The only other way I could think of is to have a script with `Start()` or `Awake()` and have it set to `ExecuteInEditMode`, though I'm not sure if that would work.
I have taken the excellent code from the answer pointed to by vitamine and added it to the Community Wiki at unifycommunity.com .
Cheers!