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.
Inherited Members
Namespace: UnityEditor.Rendering
Assembly: Unity.RenderPipelines.Core.Editor.dll
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 |
---|---|
float |
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 draw the surface of the hull's sphere |