I’ve been trying to figure out a way I could display Materials and or Object Components in a Custom Editor Window, I would like to implement something similar to the way unity has their drag and drop materials / components set up, however I need to create my own for a class project (and for other personal use)…
This is what I have so far, am I going about it the right way?
Renderer renderer = Selection.activeGameObject.GetComponent<Renderer>();
if(renderer != null)
{
objMaterial = renderer.sharedMaterial;
displayMaterial = // Editor GUI Layout of some kind
// if (displayMaterial != objMaterial {SetDisplayMatToObj();}
}
No, you’d better use standard inspectors. Check out in reference source on the githb how inspector window is implemented and do the same.
You can use Editor.CreateEditor to get the editor for the UnityEngine.Object that has been drag n dropped to your window. Then you can call OnInspectorGUI on the editor to draw its GUI.
For the drag n drop you can check for the DragPerform event and get the drag n dropped objects via DragAndDrop.objectReferences.
1 Like
If anyone is currently searching for a similar answer I was able to achieve my result using
public class BasicObjectSpawner : EditorWindow
{
GameObject objToSpawn;
bool allowSceneObjects;
objToSpawn = EditorGUILayout.ObjectField("Prefab To Spawn", objToSpawn, typeof(GameObject), allowSceneObjects) as GameObject;
}
and then later add a function to instantiate the object, currently looking into how to do the same with script and then display the components
1 Like