I need to make a script that waits until EditorApplication.isCompiling and EditorApplication.isUpdating are both false, so everything is refreshed and ready to go, and then applys a shader. I BELIEVE what I am supposed to use is a coroutine with an IEnumerable, but I wouldnt know how to go about this. I’m fairly new to c# in the regard of coroutines. If someone can point me in the right direction, and/or solve my problem of applying a shader to a material RIGHT AFTER importing the shader, then that would be great. The problem is that since the shader is “new” to the project, it takes a while for unityeditor to realize theres a shader, so it fails to find the shader using Shader.Find and therefore doesnt do anything.
Yeah, using a coroutine for that would probably work. What do you have so far?
Here’s some pseudocode of what I imagine it’d look like for starters.
IEnumerator WaitForShader()
{
while (EditorApplication.isCompiling || EditorApplication.isUpdating)
yield return new WaitForSeconds(1);
// do your thing here
}
I don’t really know where to go from there to be honest.
This is basically what I have so far:
using System;
using UnityEngine;
using UnityEditor;
public class TestClass : MonoBehaviour
{
private static IEnumerator coroutine;
[MenuItem("applyShader"), false, 1]
private static void applyShader(){
Material temp = (Material)AssetDatabase.LoadAssetAtPath(someMaterial, typeof(Material));
coroutine = WaitForShader(temp);
StartCoroutine(coroutine);[/INDENT]
}
private static IEnumerator WaitForShader(Material temp)
{
while (EditorApplication.isCompiling || EditorApplication.isUpdating)
yield return new WaitForSeconds(1);
temp.shader = Shader.Find("test/newshader");
}[/INDENT]
}
Does this look okay to you? The problem I’m getting is that it’s telling me that I cannot have a static IEnumerator or something. I’m not sure how else to accomplish it.
That’s quite a bit old, yeah. However, this listens for the compiling and does something while it is compiling, but i need to apply a shader to a material after EditorApplication.isCompiling() and isUpdating() are both false… as well as I need to run this type of coroutine in a static method, so im not exactly sure how to go about this.