Say I have a script called BevelCube with a public field bevelSize. In this script’s Awake method, a mesh is generated for this cube with the appropriate bevelled edge. Is there a simple way to have this displayed in the editor?
I could use the ExecuteInEditor decorator, but I have been warned to avoid this when possible. As well as this, even if I did use it, the mesh would not update when I change the value of bevelSize.
It seems like there are plenty of situations where you might want to initialize the appearance of a game object in a script, and also see the object in the editor, so I’d be surprised if it was simply not possible.
Sorry in advance if I’m being really stupid and missing something obvious.
I’ve still yet to find a great way to do this, but I have found a decent way. I made an abstract class Previewable : MonoBehaviour with Show and Clear methods. I then added an editor script giving menu options for Show All and Clear All.
All you have to do then is put a Show call in your scripts awake that will initialize the display.
So back to the mesh example. The method BevelCube.Show would update the mesh to be a beveled cube of the right size, and the method BevelCube.Clear would clear the mesh. So now I can use Show All to update this in the editor, and on Awake, I can call it to initialize the mesh.
Hopefully this helps someone, I’ve found it pretty useful so far.
They way I set up my gameobjects that depend on values (also lots of OnGUI tweaking) is to set up the gameobject in runtime (play mode). After I am done, I then copy the component form the little gear in the top right hand corner of the component and stop play mode. Back in Editor mode, I then paste the component values back to the component from the same little gear.