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
0
Question by Lttldude · Apr 21, 2012 at 11:59 PM · editormonobehavioursceneviewextend

Extending editor without script on GameObject?

I wrote this script to extend the Editor with the purpose to hide the cursor when right clicking in scene view. It works; however, I have to be selected on the object with the script first. Is it possible to extend the Editor like this, but have it not be limited to selecting the gameobject with the script every time?

 @CustomEditor (NoRightMouseInScene)
 class NoRightMouseInSceneEditor extends Editor{
 
     function OnSceneGUI ()
     {
         if(Event.current.type == EventType.MouseDown && Event.current.button == 1)
         {
             Screen.showCursor = false;
         }
         else if(Event.current.type == EventType.MouseUp && Event.current.button == 1)
         {
             Screen.showCursor = true;
         }
     }
 }

Thanks.

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

1 Reply

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

Answer by AchillesWF · Apr 22, 2012 at 02:50 AM

You have that code in an inspector, and so it will only run (I think) when the object is selected. Try moving the code into the OnGUI() function of an object.

Comment
Add comment · Show 4 · 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 Lttldude · Apr 22, 2012 at 04:07 AM 0
Share

Thanks for the reply. What do you mean I have the code in an inspector? The code has to be a class in the editor folder because it uses Events. I would like to be able to run a class that extends the editor without having to place a script on any object. Is that even possible?

avatar image AchillesWF · Apr 22, 2012 at 04:12 AM 1
Share

I don't think you need to have an editor class to do this.

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.OnGUI.html?from=Event

Any object can get the Event in its OnGUI() function, regardless of if it is an Editor (ScriptableObject) or $$anonymous$$onoBehavior.

avatar image Lttldude · Apr 22, 2012 at 04:28 AM 0
Share

Thanks, I didn't know that. However it only works in game mode, because OnGUI doesn't run in edit mode, even with @script ExecuteInEdit$$anonymous$$ode. When it does run in game mode, the mouse only disappears over the game window, not the scene window, which is what I would like.

avatar image AchillesWF · Apr 22, 2012 at 04:35 AM 0
Share

Just FYI you can register an object function to be called in the OnSceneGUI() stack.

SceneView.onSceneGUIDelegate += YourFunction;

You can then have your function do the work you are talking about perhaps. Note this is C#, JS has other methods of using delegates.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Intercepting left click in scene view for Custom editor. 1 Answer

Can't move GameObject in Scene view with Unity Components attached 2021.2.2f 0 Answers

What exactly is the purpose of the scene's draw mode Alpha Channel 1 Answer

Handles.ScaleValueHandle and values < 0 0 Answers

Modal Functionality in Custom Editor Window 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