Search Unity

Size Handles?

Discussion in 'Immediate Mode GUI (IMGUI)' started by kenlem, Apr 4, 2016.

  1. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    I'm writing a customer editor script where I want to be able resize the item I'm working on by dragging one size at a time. I've looked at the manual but I don't see how to get the green handles like in the image below. I think those are a built in handle type. They show up in the some of documentation but I don't know how to get them in the editor or add them to my customer script.

    Does anybody have any suggestions?
     

    Attached Files:

  2. skalev

    skalev

    Joined:
    Feb 16, 2012
    Posts:
    264
    Yeah. So I wanted to do something similar, and you can't use Unity's internal drawers for it, as they are all inside the InternalEditor namespace, and some classes are marked internal. It is actually quite a hierarchy of classes to get through. (BoxEditor->3dBoxEditor->ColliderEditor->BoxColliderEditor , or something like that).

    You'll have to build this yourself.
     
  3. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Thanks for the reply. I figures I'd have to do them myself but their existence in the documentation made me think it might be possible to use them.
     
  4. skalev

    skalev

    Joined:
    Feb 16, 2012
    Posts:
    264
    The way I worked around it was to use:

    Code (CSharp):
    1.  
    2.                 deltaPos = Handles.Slider(xPos,  Vector3.right, handleSize, new    Handles.DrawCapFunction(Handles.ArrowCap) , snapValue * 2 )- xPos;
    3.                 if (deltaPos != Vector3.zero)
    4.                 {
    5.                     //move the center and pos extents
    6.                     deltaPos *= 0.5f;
    7.                     boundsItem.center += deltaPos;
    8.                     if (!Event.current.shift)
    9.                         boundsItem.extents += deltaPos;
    10.                 }
    11.  
    The Handles.Slider() will give you the ability to drag on an axis. The DrawCapFunction is what creates the button. In my case I used the arrow, but you can use a different function (perhaps even make your own, I didn't have time to when I made my editor) to get the little dot. All you have to do from there is position everything where you want, and edit the proper fields on your object. (This example moves or scales the bounds item I used).