- Home /
Multiple Instances of the Same Type of Editor Window
Hi, I am trying to do something similar to Unity's animation curve class. I made a custom property drawer that draws a box, and I have added the ability to detect when the user clicks within the bounds of the box. I have also made it open a custom editor window I have created open when this click happens. Just like Unity's animation curve, I will have the editor window to modify that instance of property in the inspector. But, suppose I want to have multiple editor windows open at once to modify different instances? How can I accomplish this? Also, at the line with the %here% comment, how do I properly get the class back from property?
[CustomPropertyDrawer(typeof(AdvancedAnimationCurve))]
public class AdvancedAnimationCurvePropertyDrawer : PropertyDrawer {
public int height = 50;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
position = new Rect(position.x, position.y, position.width, height);
GUI.backgroundColor = new Color(.45f, .45f, .45f);
GUI.Box(position, property.name);
GetPropertyHeight(property, label);
GUI.backgroundColor = Color.white;
if (Event.current.type == EventType.MouseDown) {
if (Event.current.mousePosition.x > position.x && Event.current.mousePosition.x < position.x + position.width) {
if (Event.current.mousePosition.y > position.y && Event.current.mousePosition.y < position.y + position.height) {
AdvancedAnimationCurveEditorWindow.InspectorPropertyClicked(property as System.Object as AdvancedAnimationCurve);//%here%
}
}
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
return height;
}
}
public class AdvancedAnimationCurveEditorWindow : EditorWindow {
public static AdvancedAnimationCurve c;
public static void InspectorPropertyClicked(AdvancedAnimationCurve c) {
AdvancedAnimationCurveEditorWindow.c = c;
AdvancedAnimationCurveEditorWindow.CreateInstance<AdvancedAnimationCurveEditorWindow>();
EditorWindow.GetWindow(typeof(AdvancedAnimationCurveEditorWindow));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612133004im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PropertyDrawer let's dissapear my INT 0 Answers
How to prevent drawing DecoratorDrawer (like Header or Space) during EditorGUI.PropertyField? 1 Answer
Why does my custom property drawer's DragAndDrop add items twice? 2 Answers
Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers