Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by demonpants · Aug 17, 2012 at 06:08 AM · editormouseeditorwindowevent

How to "paint" objects in the editor?

I've been wasting a lot of time trying to figure out how functionality was made similar to what's in Tidy TileMapper: http://tools.dopplerinteractive.com/search/label/Tidy%20TileMapper%3A%20Videos

I would just buy it, but it doesn't work precisely for my needs, unfortunately. The main thing I can't figure out is how he is able to drag that UI around in the scene. I've made an EditorWindow and I set myself up as a scene GUI delegate like this:

 SceneView.onSceneGUIDelegate += this.OnSceneGUI;

 private void OnSceneGUI( SceneView sceneview ) { //blah }

And I get mouse movements and the like all fine in OnSceneGUI using Event.current.mousePosition etc, which is great. But there are major issues using the mouse, mainly that for no reason I can discern you can only get MousePressed and MouseMoved events. Without a MouseReleased or MouseDragged event there's no real way to do this. Similarly, I can't figure out a way to get the mouse to not behave in its usual way, even with event.Use() being called. If my mouse is within my editable grid, I don't want to be selecting objects and the like.

I'd love to have this work but lots of searching hasn't turned up much. And seeing as the Unity Editor functionality is document so pitifully I'm not sure if I'll ever get this exact solution. Instead, I'm debating just pressing and holding a key button as those events seem to work in entirety, and the mouse position can be update with mouseMoved events.

So any pointers here?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by demonpants · Aug 17, 2012 at 05:21 PM

I did a lot more Googling and found the solution. The issue is that the scene uses the touch before it can get to my OnSceneGUI function. You can have a look at this post:

http://forum.unity3d.com/threads/34137-SOLVED-Custom-Editor-OnSceneGUI-Scripting

Here is my working code:

 private void OnSceneGUI( SceneView sceneview )
 {
     Event e = Event.current;
     
     if ( e.type == EventType.MouseDown )
     {
         //if we're clicking within our desired area, block regular input
         if ( isInArea( e.mousePosition )
         {
             blockingMouseInput = true;
         }
     }
     else if ( e.type == EventType.MouseDrag )
     {
         
     }
     else if ( e.type == EventType.MouseMove )
     {
         
     }
     else if ( e.type == EventType.MouseUp )
     {
         if ( blockingMouseInput )
         {
             e.Use();
         }
         blockingMouseInput = false;
     }
     else if ( e.type == EventType.Layout )
     {
         //somehow this allows e.Use() to actually function and block mouse input
         HandleUtility.AddDefaultControl( GUIUtility.GetControlID( GetHashCode(), FocusType.Passive ) );
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ScroodgeM · Aug 17, 2012 at 06:44 AM

http://docs.unity3d.com/Documentation/ScriptReference/EventType.MouseDown.html http://docs.unity3d.com/Documentation/ScriptReference/EventType.MouseUp.html http://docs.unity3d.com/Documentation/ScriptReference/EventType.MouseMove.html http://docs.unity3d.com/Documentation/ScriptReference/EventType.MouseDrag.html

all these events works nice in GUI, so just try to handle it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image demonpants · Aug 17, 2012 at 05:18 PM 1
Share

Nope, they don't work. Specifically, drag and up do not work.

avatar image
0

Answer by ArthurianRedux · Sep 26, 2014 at 11:27 AM

If you want reliable mouse events then you could use the rawType of the current event. The event's regular type gets filtered out in some contexts e.g. when you move the mouse outside of the Scene Window.

I use this code to manage my custom editor gizmos when the left-mouse button is raised. Best of luck with your system.

 if(Event.current.rawType == EventType.MouseUp && Event.current.button == 0)
 {
     // Your disabling logic for gizmos etc
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Left Click Up Event in Editor 4 Answers

Detect Enter Key Event with GUILayout.TextField Focused 1 Answer

Listen to Keyboard Events on EditorWindow 1 Answer

Correct behavior of the mouse wheel when zooming in a 2D area (Unity Editor) 0 Answers

Tell difference between Undo & Redo on callback 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges