docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class HierarchicalBox

    Provide a gizmo/handle representing a box where all face can be moved independently. Also add a contained sub gizmo/handle box if contained is used at creation.

    Inheritance
    object
    HierarchicalBox
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEditor.Rendering
    Assembly: Unity.RenderPipelines.Core.Editor.dll
    Syntax
    public class HierarchicalBox
    Examples
    class MyComponentEditor : Editor
    {
        static HierarchicalBox box;
        static HierarchicalBox containedBox;
    
        static MyComponentEditor()
        {
            Color[] handleColors = new Color[]
            {
                Color.red,
                Color.green,
                Color.Blue,
                new Color(0.5f, 0f, 0f, 1f),
                new Color(0f, 0.5f, 0f, 1f),
                new Color(0f, 0f, 0.5f, 1f)
            };
            box = new HierarchicalBox(new Color(1f, 1f, 1f, 0.25), handleColors);
            containedBox = new HierarchicalBox(new Color(1f, 0f, 1f, 0.25), handleColors, container: box);
        }
    
        [DrawGizmo(GizmoType.Selected|GizmoType.Active)]
        void DrawGizmo(MyComponent comp, GizmoType gizmoType)
        {
            box.center = comp.transform.position;
            box.size = comp.transform.scale;
            box.DrawHull(gizmoType == GizmoType.Selected);
    
            containedBox.center = comp.innerposition;
            containedBox.size = comp.innerScale;
            containedBox.DrawHull(gizmoType == GizmoType.Selected);
        }
    
        void OnSceneGUI()
        {
            EditorGUI.BeginChangeCheck();
    
            //container box must be also set for contained box for clamping
            box.center = comp.transform.position;
            box.size = comp.transform.scale;
            box.DrawHandle();
    
            containedBox.DrawHandle();
            containedBox.center = comp.innerposition;
            containedBox.size = comp.innerScale;
    
            if(EditorGUI.EndChangeCheck())
            {
                comp.innerposition = containedBox.center;
                comp.innersize = containedBox.size;
            }
        }
    }

    Constructors

    HierarchicalBox(Color, Color[], HierarchicalBox)

    Constructor. Used to setup colors and also the container if any.

    Declaration
    public HierarchicalBox(Color baseColor, Color[] polychromeHandleColors = null, HierarchicalBox parent = null)
    Parameters
    Type Name Description
    Color baseColor

    The color of each face of the box. Other colors are deduced from it.

    Color[] polychromeHandleColors

    The color of handle when they are separated. When they are grouped, they use a variation of the faceColor instead.

    HierarchicalBox parent

    The HierarchicalBox containing this box. If null, the box will not be limited in size.

    Properties

    allowNegativeSize

    Allow to switch between the mode where box size can be negative or not.

    Declaration
    public bool allowNegativeSize { get; set; }
    Property Value
    Type Description
    bool

    baseColor

    The baseColor used to fill hull. All other colors are deduced from it except specific handle colors.

    Declaration
    public Color baseColor { get; set; }
    Property Value
    Type Description
    Color

    center

    The position of the center of the box in Handle.matrix space.

    Declaration
    public Vector3 center { get; set; }
    Property Value
    Type Description
    Vector3

    monoHandle

    Allow to switch between the mode where all axis are controlled together or not Note that if there is several handles, they will use the polychrome colors.

    Declaration
    public bool monoHandle { get; set; }
    Property Value
    Type Description
    bool

    size

    The size of the box in Handle.matrix space.

    Declaration
    public Vector3 size { get; set; }
    Property Value
    Type Description
    Vector3

    Methods

    DrawHandle()

    Draw the manipulable handles

    Declaration
    public void DrawHandle()

    DrawHull(bool)

    Draw the hull which means the boxes without the handles

    Declaration
    public void DrawHull(bool filled)
    Parameters
    Type Name Description
    bool filled

    If true, also fill the faces of the hull

    SetBaseColor(Color)

    Set the baseColor used to fill hull. All other colors are deduced from it except specific handle colors. Instead of baseColor set, this will not force the opacity and keep what is provided for the filled faces.

    Declaration
    public void SetBaseColor(Color color)
    Parameters
    Type Name Description
    Color color

    The color to use

    Extension Methods

    ReflectionUtils.GetField(object, string)
    ReflectionUtils.GetFields(object)
    ReflectionUtils.Invoke(object, string, params object[])
    ReflectionUtils.SetField(object, string, object)
    AnalyticsUtils.ToNestedColumnWithDefault<T>(T, T, bool)
    AnalyticsUtils.ToNestedColumn<T>(T, T)
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)