Skip to content

Game.Tools.ControlPoint

Assembly:
Assembly-CSharp

Namespace:
Game.Tools

Type:
public struct

Base:
System.ValueType, implements System.IEquatable

Summary:
Represents a control point used by in-game tools (e.g., placement/selection/editing tools). Stores both exact hit data from a raycast (positions and hit directions), editing-oriented data (direction, rotation, elevation, curve position), a reference to the original entity the raycast hit, and indexing/snap priority information. Provides two equality checks: a strict Equals and a tolerance-based EqualsIgnoreHit for approximate comparison of floating-point data. Also supplies a combined hash code implementation.


Fields

  • public Unity.Mathematics.float3 m_Position
    World-space position of the control point (primary logical position).

  • public Unity.Mathematics.float3 m_HitPosition
    Exact hit position returned by the raycast (may differ from m_Position when snapping or projection is applied).

  • public Unity.Mathematics.float2 m_Direction
    Tool-level 2D direction vector used for editing/snap direction. Defaulted to float2.zero unless set elsewhere.

  • public Unity.Mathematics.float3 m_HitDirection
    3D direction reported by the raycast hit.

  • public Unity.Mathematics.quaternion m_Rotation
    Orientation of the control point. Default is quaternion.identity when constructed with the provided constructor.

  • public Unity.Entities.Entity m_OriginalEntity
    Reference to the entity that was hit by the raycast that produced this control point.

  • public Unity.Mathematics.float2 m_SnapPriority
    Snap priority values used by snapping logic (two-component priority).

  • public Unity.Mathematics.int2 m_ElementIndex
    Index of the element/cell the hit belongs to (copied from RaycastHit.m_CellIndex).

  • public float m_CurvePosition
    Position along a curve (0..1 typically) if the point lies on a spline/curve.

  • public float m_Elevation
    Elevation/height value for the control point. Default initialized to 0f in the provided constructor.

Properties

  • This type exposes no public properties. It is a plain data struct with public fields.

Constructors

  • public ControlPoint(Unity.Entities.Entity raycastEntity, Game.Common.RaycastHit raycastHit)
    Creates a control point from a raycast result. Copies m_Position, m_HitPosition, m_HitDirection, m_ElementIndex, and m_CurvePosition from the provided RaycastHit and sets:
  • m_Rotation = quaternion.identity
  • m_Direction = default(float2)
  • m_SnapPriority = default(float2)
  • m_OriginalEntity = raycastEntity
  • m_Elevation = 0f

This constructor is typically used right after performing a raycast to build an editable control point.

Methods

  • public bool Equals(ControlPoint other)
    Performs a strict equality check between this instance and another ControlPoint. Uses the Equals methods on float3/float2/quaternion/Entity/ int2 and direct equality for floats (m_CurvePosition and m_Elevation). All fields must match exactly for this to return true. Suitable when exact bitwise or value equality is required.

  • public bool EqualsIgnoreHit(ControlPoint other)
    Performs an approximate equality check that ignores small floating-point differences and hit-specific fields. Comparison details:

  • Compares m_Position, m_Direction and m_Rotation.value using math.abs difference < 0.001f for each component (math.all).
  • Compares m_CurvePosition and m_Elevation using absolute difference < 0.001f.
  • Compares m_OriginalEntity with Entity.Equals.
  • If those checks pass, compares m_ElementIndex exactly. This is useful when comparing control points produced by separate raycasts or when small floating precision differences should be tolerated. Note: this method intentionally ignores m_HitPosition and m_HitDirection.

  • public override int GetHashCode()
    Computes a combined hash code using all fields: m_Position, m_HitPosition, m_Direction, m_HitDirection, m_Rotation, m_OriginalEntity, m_SnapPriority, m_ElementIndex, m_CurvePosition, and m_Elevation. The hash uses repeated multiplications by 31 and additions of field hash codes. Important: GetHashCode is consistent with the strict Equals method but not with EqualsIgnoreHit (since that method uses tolerance), so using hash-based containers together with EqualsIgnoreHit can lead to surprising results.

Usage Example

// Example: create a ControlPoint from a raycast result and compare approximately
using Unity.Entities;
using Unity.Mathematics;
using Game.Tools;
using Game.Common;

// raycastEntity and raycastHit would normally come from your raycasting system
Entity raycastEntity = someEntity;
RaycastHit hit = PerformRaycast(...); // hypothetical API

ControlPoint cp = new ControlPoint(raycastEntity, hit);

// later, compare to another control point with tolerance (ignore tiny FP differences)
ControlPoint cp2 = GetAnotherControlPoint();
if (cp.EqualsIgnoreHit(cp2))
{
    // treat as the same logical control point for editing/snap purposes
}