Method Anchored
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Anchored(Transform?, Camera?, Vector2?, bool, bool, LayerMask?, float?, string?, string?, string?, FiberElementProps?, StyleOverrides?, Func<VisualElement, Action>?, VNode?[]?, string?, string?, string?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?)
Screen-space element that tracks a 3D scene Transform's projected position every frame (the
default screen-space projection mode). This is ordinary 2D UI with no
inherent scene depth (unlike WorldSpace(Vector3, Quaternion?, Vector2?, VNode?[]?, string?, PanelFocusOrder), which renders content INTO the 3D scene and
is occluded by it for free) — occlude opts into an explicit physics stand-in for
that test. Forces position: absolute inline (dynamic left/top positioning has no other way
to work; see AnchoredDriver.Attach) — pass layout classes for everything else.
public static ElementNode Anchored(Transform? target, Camera? camera = null, Vector2? offset = null, bool hideWhenBehindCamera = true, bool occlude = false, LayerMask? occludeLayerMask = null, float? distanceFactor = null, string? className = null, string? key = null, string? name = null, FiberElementProps? props = null, StyleOverrides? styles = null, Func<VisualElement, Action>? refCallback = null, VNode?[]? children = null, string? whileHoverClass = null, string? whileTapClass = null, string? whileFocusClass = null, IReadOnlyDictionary<string, string>? data = null, IReadOnlyDictionary<string, string>? aria = null)
Parameters
targetTransformThe Transform this element's screen position tracks. Null (or a Transform destroyed later) mounts an inert, hidden (display: none) element until a live target is supplied — matching SceneView(Camera?, string?, string?, string?, float, StyleOverrides?, Func<VisualElement, Action>?, string?, string?, string?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?)/Particles(ParticleSystem?, string?, string?, string?, PlayTrigger, float, StyleOverrides?, Func<VisualElement, Action>?, string?, string?, string?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?)'s own null-tolerant convention, since a component holding a Transform in state can have it destroyed by unrelated game logic between renders.
cameraCameraThe camera to project through. Null resolves to UnityEngine.Camera.main on every tick, so a scene's active camera can change without re-supplying this.
offsetVector2?Pixel offset applied after projection (e.g. to center a label on the point).
hideWhenBehindCameraboolWhen true (default), the element is hidden (display: none) while
targetis behind the camera rather than jumping to a wrong on-screen spot.occludeboolWhen true, a solid (non-trigger) collider between the camera and
targethides the element — an extra physics query every tick, so it is off by default rather than a standing cost every consumer pays. A target whose own collider sits onoccludeLayerMaskwill typically occlude itself; scope the mask to scene geometry that excludes it.occludeLayerMaskLayerMask?Which colliders count as occluders when
occludeis true. Null (default) resolves to UnityEngine.Physics.DefaultRaycastLayers.distanceFactorfloat?When set, scales the element by this value divided by its current distance to the camera, faking perspective size falloff for otherwise-flat screen-space content. Null (default) leaves the element unscaled and never touches
style.scale, so it composes with ascale-*class or a Motion scale variant on the same element; a non-null value OWNS that style slot every tick instead and will fight either of those for it. Must be positive when supplied.classNamestringkeystringnamestringpropsFiberElementPropsstylesStyleOverridesrefCallbackFunc<VisualElement, Action>childrenVNode[]whileHoverClassstringwhileTapClassstringwhileFocusClassstringdataIReadOnlyDictionary<string, string>ariaIReadOnlyDictionary<string, string>
Returns
- ElementNode
The created ElementNode.
Exceptions
- ArgumentOutOfRangeException
distanceFactoris <= 0, NaN, or positive infinity.