- Home /
How to communicate between two editor scripts?
Hello I have two scripts, first:
public class Pathconnect : EditorWindow
{
public bool active = false;
[MenuItem("MyTools/PathConnector")]
public static void ShowWindow()
{
GetWindow<Pathconnect>("PathConnector");
}
private void OnGUI()
{
active = EditorGUILayout.Toggle("Is activated", active);
}
}
and second:
[CustomEditor(typeof(Pathconnect))]
public class Pathconnectscene : Editor
{ public void OnSceneGUI() {
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
{
Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
Collider[] colliders = Physics.OverlapSphere(hit.point, 3);
for(int i=0;i<colliders.Length; i++)
{
Debug.Log(colliders[i].gameObject.name);
}
}
}
}
Editor script not working, should detect all my mouse clicks when active from first script is true, how can I make this work? Of course they are in editor folder. First script works.
Can you explain why you are creating a custom editor (CustomEditor) for an editor window (EditorWindow)?
CustomEditor attribute is used to override the way an object is represented on the editor, and my understanding (which is quite limited on the subject) is that is used to change how the inspector is looking for a specific type (component according to docs) not sure if it is applicable on editor classes. Now you already have an editor window it is redundant to create a second class to handle what the first one is suppose to do. Just implement your logic in the first class.
But OnSceneGUI() not working with EditorWindow class
OnSceneGUI() is and Editor message. As far as I understand, Editor classes are used to create custom Inspectors, while you are trying to create a custom Inspector for and EditorWindow, which makes no sense. I think you need to re-think your approach here or find another function that would work with EditorWindow or find the way of making OnSceneGUI() work with EditorWindow. Nothing comes to my $$anonymous$$d right now, unfortunately.