• 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
0
Question by MediaGiant · Mar 02, 2014 at 05:01 AM · mouseclickgizmoshandlesevent handlershotcontrol

Detect mouseDown & mouseUp events on handles in editor

In my onSceneGUI delegate I can get the mouseDown and mouseUp events for the right mouse button. I can get the mouseDown event for the left mouse button and with a lot of work using GetControlID and GUIUtility.hotControl it is possible to get the mouseUp event for the left mouse button (???). But, NOTHING happens when I click on the handles/gizmos of an object in the scene view.

It is possible to use GUIUtility.hotControl to view the id of the handle controls when they are clicked on but these change depending on how many objects there are, the order of creation or some other reason.

Do I need another delegate to intercept mouse clicks on the handles?

Any help would be very welcome.

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

2 Replies

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

Answer by Zergling103 · Jan 19, 2015 at 10:34 PM

Use GUI.changed.

 bool temp = GUI.changed;
 GUI.changed = false;
 Vector3 modifiedPosition = Handles.PositionHandle(GetPosition(), Quaternion.identity);
 if (GUI.changed)
 {
     Debug.Log("Position was modified!")
     SetPosition(modifiedPosition);
 }
 GUI.changed |= temp;
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
3

Answer by MediaGiant · Mar 02, 2014 at 12:47 PM

It was tricky, but there is an answer, a simple answer, and it does not use reflection.

 string tempString = GUI.GetNameOfFocusedControl();
 if ((tempString == "xAxis" || tempString == "yAxis" || tempString == "zAxis") && GUIUtility.hotControl != 0)
 {
   hotControlFlag = true;  // declared elsewhere
   Debug.Log ("dragging");
 }
             
 if ((tempString == "xAxis" || tempString == "yAxis" || tempString == "zAxis") && hotControlFlag && GUIUtility.hotControl == 0)
 {
   hotControlFlag = false;
   Debug.Log ("released");
 }

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 halfbakedprophet · Jul 25, 2017 at 04:28 AM 0
Share

This solution is much better than the "Best Answer".

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Which custom editor tool to make empty gameobjects selectable in scene view? 1 Answer

Drawing a camera-facing circle like Unity's SphereCollider gizmo 1 Answer

Gizmo equivalent of Handles.DrawSolidArc? 0 Answers

What is the best way to use the Handles class to create custom gizmos. 1 Answer

How to create a control that allows to select position within a line? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges