- Home /
Interaction with scene view in editmode?
Trying to create editor, that capable of drawing texture on my tiled mesh. I can do that in runtime, but completely can't understand editmode. Using Javascript, expect to receive "working" in the console on mousedown in sceneview... How can I do that?
#pragma strict
//using UnityEditor;
//@script ExecuteInEditMode()
class HexMaker extends EditorWindow {
@MenuItem ("Window/HexMaker")
static function ShowWindow () {
EditorWindow.GetWindow (HexMaker);
}
function OnGUI () {
}
function OnSceneGUI () {
if (Event.current.type == EventType.MouseDown){
Debug.Log("working");
// Event.current.Use();
}
}
}
Answer by numberkruncher · May 31, 2013 at 06:06 PM
EditorWindow
's do not support the OnSceneGUI
message.
Instead you will need a custom `Editor` in order to achieve this. Here is a simple example of a custom editor:
#pragma strict
@CustomEditor(MyPlayer)
class MyPlayerEditor extends Editor {
function OnSceneGUI() {
if (Event.current.type == EventType.MouseDown) {
Debug.Log("TEST");
}
}
}
The above example works with a custom MonoBehaviour script called MyPlayer
. This will only work when a game object with "MyPlayer" attached is selected.
Example video: (please excuse my Autocomplete nightmare in MonoDevelop, I don't usually use it for coding!) http://www.youtube.com/watch?v=QG-_sbCP4iA
I have added a simple example to my answer for you with a little clarification.
Also, you may find the following forum thread of use: http://forum.unity3d.com/threads/34137-SOLVED-Custom-Editor-OnSceneGUI-Scripting
Thank you for finding this thread, but i wanna the same in JS. Done two tutorials, from which achieve the desired, but both of them in C#, and for now I can't understand C#. Can't compile your example: $$anonymous$$ Identifier "$$anonymous$$yPlayer". Yes, script is named $$anonymous$$yPlayer. You tell that script working when GO selected? Can't attach script to GO, "script needs to derive from $$anonymous$$onoBehaviour"
Here is the demo video: http://www.youtube.com/watch?v=QG-_sbCP4iA
It's working now! Thank you a lot! So, i need GO $$anonymous$$yPlayer, to add Debug.Log to his custom inspector from editor script... Confusing) Wonder, why I need GO still? Is Rotorz Tile System have to use GridPlane GO as $$anonymous$$yPlayer in your example? btw I excited with Rotorz tile painting tool) Sorry for my English)))
Your answer

Follow this Question
Related Questions
GUI & GUILayout methods no longer work in OnSceneGUI() 1 Answer
Scripting a Click event in the Unity Editor 1 Answer
Adding drag function to a polygon editor 1 Answer
How can you access the Game screen and its properties from an Editor Script? 1 Answer
How to read the current PivotRotation or PivotMode ? 1 Answer