Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by lancer · Sep 22, 2015 at 07:51 PM · editor-scriptingeditorwindowmouseposition

Rect.contains with mouse position in editorwindow

I have custom editor window, and I'm trying to detect when my mouse is over a GUI texture that I can in the window.

I thought it seemed pretty straightforward, set wantsMouseMove to true, and then get the current event mouse position:

 void Update () {
     this.wantsMouseMove = true;
     Vector2 mouse = Input.mousePosition;
         Debug.Log ("MousePos: " + mouse);
 }

Not so. For the mouse position, it always just prints (0.0,0.0) .

I also tried it this way, which I saw in another answer on here:

 void OnGUI () {
         wantsMouseMove = true;
         EditorGUILayout.LabelField ("Mouse Position: ", Event.current.mousePosition.ToString ());
 }

It sorta works, but it only changes the mouse postion when I click on the title bar of the window, or switch to another window/application and click back on the editorwindow.

alt text

I though this might have been an issue with my version of Unity, so I updated to the latest version (13GB download o_o) but no change.

Any ideas of whats happening here? I just need the get the current mouse position so I can use it in a Rect.Contains() in a GUI texture that's is added to the window when you click the "add building" button.

title-bar.png (10.9 kB)
Comment
Add comment · Show 1
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 lancer · Sep 23, 2015 at 03:49 AM 0
Share

I thought this would be a simple issue that I would get help on fast, but apparently not :P

1 Reply

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

Answer by Yword · Sep 23, 2015 at 04:11 AM

Maybe you should Repaint the window OnInspectorUpdate.

 using UnityEngine;
 using UnityEditor;
 
 public class MyWindow : EditorWindow 
 {
     [MenuItem ("Window/My Window")]
     static void Init() 
     {
         MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
         window.Show();
     }
     
     void OnGUI() 
     {
         Event e = Event.current;
         GUILayout.Label("Mouse pos: " + e.mousePosition);
     }
 
     void OnInspectorUpdate()
     {
         if (EditorWindow.focusedWindow == this &&
             EditorWindow.mouseOverWindow == this)
         {
             this.Repaint();
         }
     }
 }

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 lancer · Sep 23, 2015 at 05:57 PM 0
Share

That worked! Thanks :)

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

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

Related Questions

mouseposition and clicks in editor sceneview 0 Answers

EditorWindow, Utility Popup, not using custom PropertyDrawers 0 Answers

EditorWindow reference to other scripts functions 0 Answers

Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers

Creating Editor 2D Animation Preview 2 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