UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
Loading...
Searching...
No Matches
GWG.UsoUIElements.CustomElements.EllipseMesh Class Reference

A utility class that generates mesh data for rendering elliptical shapes with customizable borders in Unity's UI Elements system. This class creates vertex and index arrays suitable for use with Unity's UI rendering pipeline to draw ellipses or circles. More...

Public Member Functions

 EllipseMesh (int numSteps)
 Initializes a new EllipseMesh with the specified number of steps for curve approximation.
void UpdateMesh ()
 Generates or regenerates the mesh vertex and index data based on current properties. This method only performs work if the mesh is marked as dirty due to property changes.

Properties

float borderSize [get, set]
 Gets or sets the border thickness, defining the difference between outer and inner ellipse radii.
Color color [get, set]
 Gets or sets the color applied to all vertices in the ellipse mesh.
float height [get, set]
 Gets or sets the height (vertical radius) of the ellipse.
ushort[] indices [get, private set]
 Array containing triangle indices that define how vertices are connected to form the ellipse mesh.
bool isDirty [get]
 Gets a value indicating whether the mesh data needs to be regenerated due to property changes.
int numSteps [get, set]
 Gets or sets the number of angular steps used to approximate the ellipse curve.
Vertex[] vertices [get, private set]
 Array containing all vertex data for the ellipse mesh. Each vertex includes position and tint color information.
float width [get, set]
 Gets or sets the width (horizontal radius) of the ellipse.

Private Member Functions

void CompareAndWrite (ref float field, float newValue)
 Compares a field value with a new value and updates the field if they differ, marking the mesh as dirty. This utility method provides epsilon-based floating-point comparison to avoid precision issues.

Private Attributes

float m_BorderSize
 The thickness of the border, defining the difference between outer and inner radii.
Color m_Color
 The color applied to all vertices in the ellipse mesh.
float m_Height
 The height (vertical radius) of the ellipse.
bool m_IsDirty
 Flag indicating whether the mesh data needs to be regenerated due to property changes.
int m_NumSteps
 The number of steps (segments) used to approximate the ellipse curve.
float m_Width
 The width (horizontal radius) of the ellipse.

Detailed Description

A utility class that generates mesh data for rendering elliptical shapes with customizable borders in Unity's UI Elements system. This class creates vertex and index arrays suitable for use with Unity's UI rendering pipeline to draw ellipses or circles.

The mesh is generated as a series of triangular segments forming a ring shape, where the outer edge defines the ellipse boundary and the inner edge creates the border effect. The mesh uses a dirty flag system to optimize regeneration only when properties change. The generated vertices include position data and tint colors compatible with Unity's UI Element rendering system. All angles are calculated in degrees and converted to radians for trigonometric calculations.

Constructor & Destructor Documentation

◆ EllipseMesh()

GWG.UsoUIElements.CustomElements.EllipseMesh.EllipseMesh ( int numSteps)

Initializes a new EllipseMesh with the specified number of steps for curve approximation.

Parameters
numStepsThe number of angular steps to use for approximating the ellipse curve.

The constructor sets the mesh as dirty to ensure initial generation when UpdateMesh is called. Other properties (width, height, color, borderSize) must be set separately before calling UpdateMesh. A higher numSteps value will create a smoother ellipse at the cost of more vertices and triangles.

Member Function Documentation

◆ CompareAndWrite()

void GWG.UsoUIElements.CustomElements.EllipseMesh.CompareAndWrite ( ref float field,
float newValue )
private

Compares a field value with a new value and updates the field if they differ, marking the mesh as dirty. This utility method provides epsilon-based floating-point comparison to avoid precision issues.

Parameters
fieldReference to the field to potentially update.
newValueThe new value to compare against and potentially assign.

This method is used internally by property setters to ensure the mesh is marked dirty only when actual changes occur. The epsilon comparison prevents unnecessary dirty marking due to floating-point precision.

◆ UpdateMesh()

void GWG.UsoUIElements.CustomElements.EllipseMesh.UpdateMesh ( )

Generates or regenerates the mesh vertex and index data based on current properties. This method only performs work if the mesh is marked as dirty due to property changes.

The method creates a ring-shaped mesh by generating pairs of vertices (outer and inner) for each angular step. Each step creates two triangles that connect the current vertex pair with the previous pair, forming segments of the ring. The mesh generation uses trigonometric functions to calculate vertex positions around the ellipse perimeter. Vertex positions are offset by width and height to center the ellipse at the specified position. The method automatically handles array resizing if the number of required vertices or indices changes.

Member Data Documentation

◆ m_BorderSize

float GWG.UsoUIElements.CustomElements.EllipseMesh.m_BorderSize
private

The thickness of the border, defining the difference between outer and inner radii.

This value is subtracted from both width and height to create the inner ellipse boundary. A larger border size creates a thicker ring, while a border size equal to the smallest radius creates a filled ellipse.

◆ m_Color

Color GWG.UsoUIElements.CustomElements.EllipseMesh.m_Color
private

The color applied to all vertices in the ellipse mesh.

This color is used as the tint color for all vertices, allowing the ellipse to be rendered in different colors without requiring separate materials or shaders.

◆ m_Height

float GWG.UsoUIElements.CustomElements.EllipseMesh.m_Height
private

The height (vertical radius) of the ellipse.

This represents half the total height of the ellipse and is used in conjunction with cosine calculations to determine the vertical positions of vertices around the ellipse perimeter.

◆ m_IsDirty

bool GWG.UsoUIElements.CustomElements.EllipseMesh.m_IsDirty
private

Flag indicating whether the mesh data needs to be regenerated due to property changes.

This optimization flag prevents unnecessary mesh regeneration when properties haven't changed. It is set to true whenever any property affecting the mesh geometry or appearance is modified.

◆ m_NumSteps

int GWG.UsoUIElements.CustomElements.EllipseMesh.m_NumSteps
private

The number of steps (segments) used to approximate the ellipse curve.

Higher values create smoother ellipses but require more vertices and triangles. This value determines the angular resolution of the ellipse approximation.

◆ m_Width

float GWG.UsoUIElements.CustomElements.EllipseMesh.m_Width
private

The width (horizontal radius) of the ellipse.

This represents half the total width of the ellipse and is used in conjunction with sine calculations to determine the horizontal positions of vertices around the ellipse perimeter.

Property Documentation

◆ borderSize

float GWG.UsoUIElements.CustomElements.EllipseMesh.borderSize
getset

Gets or sets the border thickness, defining the difference between outer and inner ellipse radii.

The border size value that is subtracted from both width and height to create the inner ellipse boundary.

A larger border size creates a thicker ring effect, while a border size equal to or greater than the smallest radius will create a filled ellipse. Changing this value marks the mesh as dirty if the new value differs from the current value using epsilon-based comparison.

◆ color

Color GWG.UsoUIElements.CustomElements.EllipseMesh.color
getset

Gets or sets the color applied to all vertices in the ellipse mesh.

The Color value used as the tint for all vertices in the mesh.

This color is applied to both outer and inner vertices, allowing the entire ellipse to be rendered in the specified color. Changing this value marks the mesh as dirty if the new color differs from the current color.

◆ height

float GWG.UsoUIElements.CustomElements.EllipseMesh.height
getset

Gets or sets the height (vertical radius) of the ellipse.

The height value representing half the total vertical span of the ellipse.

This value is used with cosine calculations to determine vertical vertex positions. Changing this value marks the mesh as dirty if the new value differs from the current value. The comparison uses epsilon-based floating-point comparison to avoid precision issues.

◆ indices

ushort [] GWG.UsoUIElements.CustomElements.EllipseMesh.indices
getprivate set

Array containing triangle indices that define how vertices are connected to form the ellipse mesh.

The array of indices, or null if the mesh hasn't been generated yet. The array length is always numSteps * 6 (two triangles per step, three indices per triangle).

Indices are organized to create two triangles per angular step, forming a ring segment. The triangles connect the current and previous outer/inner vertex pairs to create a continuous ring shape.

◆ isDirty

bool GWG.UsoUIElements.CustomElements.EllipseMesh.isDirty
get

Gets a value indicating whether the mesh data needs to be regenerated due to property changes.

True if any properties affecting the mesh have changed since the last UpdateMesh call; otherwise, false.

This property can be used to determine if calling UpdateMesh will perform any work. The dirty flag is automatically managed by property setters and cleared by UpdateMesh.

◆ numSteps

int GWG.UsoUIElements.CustomElements.EllipseMesh.numSteps
getset

Gets or sets the number of angular steps used to approximate the ellipse curve.

The number of steps, which determines the smoothness of the ellipse approximation. Higher values create smoother curves but require more vertices and triangles.

Changing this value marks the mesh as dirty and will require regeneration. The total number of vertices will be numSteps * 2, and the total number of indices will be numSteps * 6.

◆ vertices

Vertex [] GWG.UsoUIElements.CustomElements.EllipseMesh.vertices
getprivate set

Array containing all vertex data for the ellipse mesh. Each vertex includes position and tint color information.

The array of vertices, or null if the mesh hasn't been generated yet. The array length is always numSteps * 2 (outer and inner vertex for each step).

Vertices are arranged in pairs for each angular step: an outer vertex defining the ellipse boundary and an inner vertex defining the inner border. The vertices are compatible with Unity's UI Element rendering system.

◆ width

float GWG.UsoUIElements.CustomElements.EllipseMesh.width
getset

Gets or sets the width (horizontal radius) of the ellipse.

The width value representing half the total horizontal span of the ellipse.

This value is used with sine calculations to determine horizontal vertex positions. Changing this value marks the mesh as dirty if the new value differs from the current value. The comparison uses epsilon-based floating-point comparison to avoid precision issues.