Editor Scripting

Hi
I have some basic issues just by trying to make some easy script to have to additionnal editor tools.
I want to make a script that open a custom window editor by clicking on a specific game object.
But I simply don’t know how to do as my first tries in script editor didn’t work :

Can someone can help to find a method to do such a tool or give documentation that can help me

thank you

Check out the section of the docs titled ‘Extending the Editor’. If you don’t find what you need there, check out the section of the ‘scripts’ Wiki devoted to editor scripts. If that still doesn’t do it, post your code here with a description of whatever problem you’re running into.

here is my code the purpose is not why I aimed but just testing if an event could make a window pop up
I placed Two C# script in Asset\Editor folder

TestEditorWindow.cs : this allow me to create a window as examples on Unity showed me

using UnityEngine;
using UnityEditor;
using System.Collections;

public class TestEditorWindow : EditorWindow 
{
	string myString = "Hello World";
	bool groupEnabled;
	bool myBool = true;
	float myFloat = 1.23f;

	// Add menu named "My Window" to the Window menu
	[MenuItem ("Window/My Window")]
	public static void Init () 
	{
		// Get existing open window or if none, make a new one:
		TestEditorWindow window = (TestEditorWindow)EditorWindow.GetWindow (typeof (TestEditorWindow));
		window.Show (true);
	}

	void OnGUI () 
	{
		GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
		myString = EditorGUILayout.TextField ("Text Field", myString);

		groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
		myBool = EditorGUILayout.Toggle ("Toggle", myBool);
		myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
		EditorGUILayout.EndToggleGroup ();
	}
}

and TestEditor.cs witch use an event to call a window to “show”

using UnityEngine;
using UnityEditor;
using System.Collections;

// test event pop up window

public class TestEditor : Editor 
{


	void OnSceneGUI(){
		Event e = Event.current;
		if(e.button ==0){
			
			TestEditorWindow.Init();
			}

		
	}
}

but when I click nothing happened but maybe I’m wrong and I am not doing it well
can you help me ?

Can you edit your post and enclose the code in ‘code’ tags rather than ‘quote’ tags?

ok it is done sorry about that I’ve choosen quick reply and so don’t have this option but it’s ok now I think

can someone help me please ?

The Editor class is designed to let you display a custom editor for a particular type of object but the script itself doesn’t get a regular callback in the “background”, so to speak. You can add a regular callback by setting the EditorApplication.update property.

Ok thanks but I still have some problem as It seems that my TestEditor.cs script doesn’t recognize event such as mouse event and I tried to check it out with debug function but still doesn’t work. Can I have more explanations about the use of EditorApplication ? or maybe another solution to make a window pop up ?

I don’t know whether events are available from the ‘update’ callback (they may be - I’ve never tried it). It’s fairly common however to use custom menu commands to open editor windows, and that might be easier than what you’re trying to do. (You can create a keyboard shortcut for the menu command as well.)

ok thanks a lot for the help anyway maybe i’ll focus on custom inspector :slight_smile: