protected void ListenTriggerValue(object sender, float value) { if (!LastHitComponent || LastHitComponent.GetComponent <IMorphInteractiveComponent>() == null) { return; } //Grab IMorphComponentGrab grab = LastHitComponent.GetComponent <IMorphComponentGrab>(); if (grab == null) { return; } if (value >= 0.9f && !grab.IsGrabbed) { grab.Grab(); //Store initial distance between object and controller GrabbedComponentInitialDistance = Vector3.Distance(LastHitComponent.transform.position, transform.position); } else if (value < 0.1f && grab.IsGrabbed) { grab.Release(); } }
protected override void BeforeUpdate() { base.BeforeUpdate(); //if no object is hit, no grab if (!Reticle.CurrentRaycastResult.isValid) { return; } //if hit object doesn't have grab component, no grab IMorphComponentGrab grab = Reticle.CurrentRaycastResult.gameObject.GetComponent <IMorphComponentGrab>(); if (grab == null) { return; } //Is begin grab if (Reticle.TriggerDown && !_wasTriggerDownLastFrame) { _wasTriggerDownLastFrame = true; _elapsedTimeWithTriggerDown = 0; } //No trigger pressed, no grab if (!_wasTriggerDownLastFrame) { return; } //User is holding trigger, compute holding time if (Reticle.Triggering) { _elapsedTimeWithTriggerDown += Time.deltaTime; } //If not triggering, release else { _elapsedTimeWithTriggerDown = 0; _wasTriggerDownLastFrame = false; ComponentReleased(this, null); if (grab.IsGrabbed) { grab.Release(); } } //If trigger held and component not yet grabbed, and wait time reached, grab component if (_wasTriggerDownLastFrame && !grab.IsGrabbed && _elapsedTimeWithTriggerDown >= _waitTimeBeforeGrab) { //Store component being grabbed CurrentlyGrabbedComponent = Reticle.CurrentRaycastResult.gameObject; //grab component grab.Grab(); } }