Class Leap::AnchorableBehaviour¶
- class Leap.AnchorableBehaviour : public MonoBehaviour¶
AnchorableBehaviours mix well with InteractionBehaviours you’d like to be able to pick up and place in specific locations, specified by other GameObjects with an Anchor component.
Subclassed by Leap.PhysicalHandsAnchorable
Public Functions
- void Detach ()¶
Detaches this Anchorable object from its anchor. The anchor reference remains unchanged. Call TryAttach() to re-attach to this object’s assigned anchor.
- bool IsValidAnchor (Anchor anchor)¶
Returns whether the argument anchor is an acceptable anchor for this anchorable object; that is, whether the argument Anchor is within this behaviour’s AnchorGroup if it has one, or if this behaviour has no AnchorGroup, returns true.
- bool IsWithinRange (Anchor anchor)¶
Returns whether the specified anchor is within attachment range of this Anchorable object.
- Anchor FindPreferredAnchor ()¶
Attempts to find and return the best anchor for this anchorable object to attach to based on its current configuration. If useTrajectory is enabled, the object will consider anchor proximity as well as its own trajectory towards a particular anchor, and may return null if the object is moving away from all of its possible anchors. Otherwise, the object will simply return the nearest valid anchor, or null if there is no valid anchor nearby.
This method is called every Update() automatically by anchorable objects, and its result is stored in preferredAnchor. Only call this if you need a new calculation.
- List<Anchor> GetNearbyValidAnchors (bool requireAnchorHasSpace = true, bool requireAnchorActiveAndEnabled = true)¶
Returns all anchors within the max anchor range of this anchorable object. If this anchorable object has its anchorGroup property set, only anchors within that AnchorGroup will be returned. By default, this method will only return anchors that have space for an object to attach to it.
Warning: This method checks squared-distance for all anchors in teh scene if this AnchorableBehaviour has no AnchorGroup.
- Anchor GetNearestValidAnchor (bool requireWithinRange = true, bool requireAnchorHasSpace = true, bool requireAnchorActiveAndEnabled = true)¶
Returns the nearest valid anchor to this Anchorable object. If this anchorable object has its anchorGroup property set, all anchors within that AnchorGroup are valid to be this object’s anchor. If there is no valid anchor within range, returns null. By default, this method will only return anchors that are within the max anchor range of this object and that have space for an object to attach to it.
Warning: This method checks squared-distance for all anchors in the scene if this AnchorableBehaviour has no AnchorGroup.
- bool TryAttach (bool ignoreRange = false)¶
Attempts to attach to this Anchorable object’s currently specified anchor. The attempt may fail if this anchor is out of range. Optionally, the range requirement can be ignored.
- bool TryAttachToNearestAnchor ()¶
Attempts to find and attach this anchorable object to the nearest valid anchor, or the most optimal nearby anchor based on proximity and the object’s trajectory if useTrajectory is enabled.
Public Members
- Action OnAttachedToAnchor = () => { }¶
Called when this AnchorableBehaviour attaches to an Anchor.
- Action OnLockedToAnchor = () => { }¶
Called when this AnchorableBehaviour locks to an Anchor.
- Action OnDetachedFromAnchor = () => { }¶
Called when this AnchorableBehaviour detaches from an Anchor.
- Action WhileAttachedToAnchor = () => { }¶
Called during every Update() in which this AnchorableBehaviour is attached to an Anchor.
- Action WhileLockedToAnchor = () => { }¶
Called during every Update() in which this AnchorableBehaviour is locked to an Anchor.
- Action OnPostTryAnchorOnGraspEnd = () => { }¶
Called just after this anchorable behaviour’s InteractionBehaviour OnObjectGraspEnd for this anchor. This callback will never fire if tryAttachAnchorOnGraspEnd is not enabled.
If tryAttachAnchorOnGraspEnd is enabled, the anchor will be attached to an anchor only if its preferredAnchor property is non-null; otherwise, the attempt to anchor failed.
Properties
- Anchor preferredAnchor { get; set; }¶
Gets the anchor this AnchorableBehaviour would most prefer to attach to. This value is refreshed every Update() during which the AnchorableBehaviour has no anchor or is detached from its current anchor.
Public Static Functions
- static float GetAnchorScore (Vector3 anchObjPos, Vector3 anchObjVel, Vector3 anchorPos, float maxDistance, float nonDirectedMaxDistance, float minAngleProduct, float alwaysAttachDistance = 0f)¶
Calculates and returns a score from 0 (non-valid anchor) to 1 (ideal anchor) based on the argument configuration, using an anchorable object’s position and velocity, an anchor position, and distance/angle settings. A score of zero indicates an invalid anchor no matter what; a non-zero score indicates a possible anchor, with more optimal anchors receiving a score closer to 1.