I dont want to use an Editor Window or ScriptableObject or MonoBehaviour. I just want to get a callback called every frame without having the user having to click a menu item or something like that.
You can use the InitializeOnLoad attribute combined with static constructors.
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
class MyClass
{
static MyClass ()
{
EditorApplication.update += Update;
}
static void Update ()
{
Debug.Log("Updating");
}
}
@Razgrizzz
You can call any methods you want in your Update() method, but you will need static references to them.
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
class MyClass
{
public static List<MyObject> list;
static MyClass ()
{
EditorApplication.update += Update;
list = new List<MyObject>();
}
public MyClass(){ // regular constructor where we add this to static list
MyClass.list.Add(this);
}
static void Update ()
{
Debug.Log("Updating");
foreach(MyClass mc in list){
mc.AnyPublicMethod();
}
}
public void AnyPublicMethod(){
print("Dude.");
}
}