docs.unity3d.com
    Show / Hide Table of Contents

    Class HierarchicalSphere

    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
    HierarchicalSphere
    Namespace: UnityEditor.Rendering
    Syntax
    public class HierarchicalSphere
    Examples
    class MyComponentEditor : Editor
    {
        static HierarchicalSphere sphere;
        static HierarchicalSphere containedSphere;
    
        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)
            };
            sphere = new HierarchicalSphere(new Color(1f, 1f, 1f, 0.25));
            containedSphere = new HierarchicalSphere(new Color(1f, 0f, 1f, 0.25), container: sphere);
        }
    
        [DrawGizmo(GizmoType.Selected|GizmoType.Active)]
        void DrawGizmo(MyComponent comp, GizmoType gizmoType)
        {
            sphere.center = comp.transform.position;
            sphere.size = comp.transform.scale;
            sphere.DrawHull(gizmoType == GizmoType.Selected);
    
            containedSphere.center = comp.innerposition;
            containedSphere.size = comp.innerScale;
            containedSphere.DrawHull(gizmoType == GizmoType.Selected);
        }
    
        void OnSceneGUI()
        {
            EditorGUI.BeginChangeCheck();
    
            //container sphere must be also set for contained sphere for clamping
            sphere.center = comp.transform.position;
            sphere.size = comp.transform.scale;
            sphere.DrawHandle();
    
            containedSphere.center = comp.innerposition;
            containedSphere.size = comp.innerScale;
            containedSphere.DrawHandle();
    
            if(EditorGUI.EndChangeCheck())
            {
                comp.innerposition = containedSphere.center;
                comp.innersize = containedSphere.size;
            }
        }
    }

    Constructors

    HierarchicalSphere(Color, HierarchicalSphere)

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

    Declaration
    public HierarchicalSphere(Color baseColor, HierarchicalSphere parent = null)
    Parameters
    Type Name Description
    Color baseColor

    The color of filling. All other colors are deduced from it.

    HierarchicalSphere parent

    The HierarchicalSphere containing this sphere. If null, the sphere will not be limited in size.

    Properties

    baseColor

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

    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

    radius

    The size of the box in Handle.matrix space.

    Declaration
    public float radius { get; set; }
    Property Value
    Type Description
    Single

    Methods

    DrawHandle()

    Draw the manipulable handles

    Declaration
    public void DrawHandle()

    DrawHull(Boolean)

    Draw the hull which means the boxes without the handles

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

    If true, also draw the surface of the hull's sphere

    Extension Methods

    ReflectionUtils.Invoke(Object, String, Object[])
    ReflectionUtils.SetField(Object, String, Object)
    ReflectionUtils.GetField(Object, String)
    ReflectionUtils.GetFields(Object)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie 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.
    Generated by DocFX on 18 October 2023