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(); } }
private void CancelInteractions() { if (LastHitComponent && LastHitComponent.GetComponent <IMorphInteractiveComponent>() != null) { //Unfocus IMorphComponentFocus focus = LastHitComponent?.GetComponent <IMorphComponentFocus>(); if (focus != null && focus.IsFocused) { focus.Unfocus(); } //Deselect IMorphComponentSelect select = LastHitComponent?.GetComponent <IMorphComponentSelect>(); if (select != null && select.IsSelected) { select.Deselect(); } //Release IMorphComponentGrab grab = LastHitComponent?.GetComponent <IMorphComponentGrab>(); if (grab != null && grab.IsGrabbed) { grab.Release(); } } }
protected void ListenTouchpadClicked(object sender, bool clicked) { if (!LastHitComponent || LastHitComponent.GetComponent <IMorphInteractiveComponent>() == null) { return; } //Select IMorphComponentSelect select = LastHitComponent.GetComponent <IMorphComponentSelect>(); if (select == null) { return; } if (clicked && !select.IsSelected) { select.Select(); } else if (!clicked && select.IsSelected) { select.Deselect(); } }
protected override void AfterUpdate() { base.AfterUpdate(); //Interactions RaycastHit hit; if (Physics.Raycast(Position.Position, Rotation.ForwardDirection, out hit)) { //Move reticle if (Reticle) { Reticle.transform.position = hit.point; Reticle.transform.rotation = Quaternion.LookRotation(hit.normal); Reticle.transform.Translate(Vector3.forward * 0.01f, Space.Self); } //If new component hit if (hit.transform.gameObject != LastHitComponent) { CancelInteractions(); //Store new hit component LastHitComponent = hit.transform.gameObject; //If gameobject is not interactive, ignore it if (LastHitComponent.GetComponent <IMorphInteractiveComponent>() == null) { return; } //Focus var focus = LastHitComponent?.GetComponent <IMorphComponentFocus>(); if (focus != null && !focus.IsFocused) { focus.Focus(); } } } else { CancelInteractions(); LastHitComponent = null; if (Reticle) { Reticle.transform.localPosition = Vector3.zero; Reticle.transform.localRotation = Quaternion.identity; Reticle.transform.Translate(Vector3.forward * 5f, Space.Self); } } //Move line if (LineRenderer.enabled) { LineRenderer.SetPosition(0, Vector3.zero); LineRenderer.SetPosition(1, Reticle.transform.localPosition); } //If component grabbed, update its position var grab = LastHitComponent?.GetComponent <IMorphComponentGrab>(); if (LastHitComponent && grab != null && grab.IsGrabbed) { LastHitComponent.transform.RotateAround(transform.position, Rotation.UpDirection, Rotation.RotationDelta.y); LastHitComponent.transform.RotateAround(transform.position, Rotation.RightDirection, Rotation.RotationDelta.x); LastHitComponent.transform.RotateAround(transform.position, Rotation.ForwardDirection, Rotation.RotationDelta.z); //Look for touchpad delta to move grabbed component closer or farer float verticalDelta = Touchpads.Touchpads[0].VerticalAxisDelta; LastHitComponent.transform.Translate(transform.forward * GrabbedComponentInitialDistance * verticalDelta); } }