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
6
Question by rlbaldi · Jun 23, 2010 at 08:16 PM · editor-scriptinggizmoshandlesonscenegui

Using handles to edit custom classes

Is there a way to override Unity's handles? I mean, I want to use the rotation gizmo to modify a property other than transform.rotation. I've got this so far:

using UnityEditor; using UnityEngine;

[CustomEditor(typeof(Foo))] public class FooEditor : Editor { public override void OnInspectorGUI () { DrawDefaultInspector(); }

 public void OnSceneGUI()
 {
     Foo foo = (Foo)target;

     foo.rotation = Handles.RotationHandle(foo.rotation, foo.transform.position);
 }

}

And my Foo class:

using UnityEngine;

public class Foo : MonoBehaviour { public Vector3 position; public Quaternion rotation; public Vector3 size; }

I want that when the user modify size, position or rotation through one of the Unity's default gizmos, my class get modified and not the current selected transform. If there is no way of doing that, is there a way to disable the rendering of Unity's default gizmos?

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
1

Answer by ckfinite · Nov 30, 2010 at 03:12 AM

I think that your problem is that you are accessing a field that is set in the superclass without a overriding field in your code. What the upshot of this OO-speak is that you need to rename the variable in your class to something like fooRotation, or just changing the capitalization (C# is case sensitive).

You might try

using UnityEngine;

public class Foo : MonoBehaviour { public Vector3 Position; public Quaternion Rotation; public Vector3 Size; }

and calling Foo foo = (Foo)target;

    foo.Rotation= Handles.RotationHandle(foo.Rotation, foo.transform.position);
Comment
Add comment · Show 2 · 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 rlbaldi · Nov 30, 2010 at 03:51 PM 0
Share

Actually what I was trying to achieve is to hide the default gizmo that appears when you select a GameObject on your scene, so the User will feel like he is moving the default Gizmo, but he is actually moving my own/custom/very specific Gizmo.

avatar image ckfinite · Nov 30, 2010 at 06:29 PM 0
Share

You could try something like Handles.ArrowCap to draw your own handle design. Otherwise, you might be able to draw directly into the environment. Not sure how, but I think it can be done.

avatar image
0

Answer by Guessmyname · Jul 21, 2014 at 04:16 PM

I had this pain myself; eventually I tracked it down to the Tools class.

The trick is, in your custom inspector (ie the one that derives from Editor), add this code to the OnEnable() and OnDisable() functions:

 void OnEnable(){
     Tools.hidden = true; //hide default tools when activated
 }
 
 void OnDisable(){
     Tools.hidden = false; //unhide default tools when deactived
 }

Thus you can 'override' the default tools with your own custom handles without the default one getting in the way.

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

1 Person is following this question.

avatar image

Related Questions

Handles.PositionHandle not working anymore in version 2019.3? 0 Answers

Showing Handles in the Game View 1 Answer

There is a way to check if a handle is highlighted? 1 Answer

How to serialize Field Variables on hidden Editor scripts? 0 Answers

How to create a control that allows to select position within a line? 3 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