private void OnMergeButtonPressed(object sender, ControllerInteractionEventArgs e) { VRTK_InteractGrab grabbingController = e.controllerReference.actual.GetComponentInChildren <VRTK_InteractGrab>(); Plug grabbedPlug = grabbingController.GetGrabbedObject().GetComponent <Plug>(); Cord connectedCord = grabbedPlug.ConnectedCord; bool replaceCordStart = connectedCord.StartNode.Equals(grabbedPlug.CordAttachPoint); if (replaceCordStart) { connectedCord.Connect(transform, connectedCord.EndNode); if (connectedCord.EndNode.GetComponent <BranchHandle>() != null) { connectedCord.Flow = -1; } } else { connectedCord.Connect(connectedCord.StartNode, transform); if (connectedCord.StartNode.GetComponent <BranchHandle>() != null) { connectedCord.Flow = 1; } } branchNode = new CordNode(connectedCord, transform); grabbingController.ForceRelease(); grabbedPlug.DestroyPlug(); cordJunction = SplitCord(sourceCord); StopMovementAlongCord(); ConnectBranchToJunction(); }
private void OnGrabbed(object sender, InteractableObjectEventArgs e) { grabber = e.interactingObject.GetComponent <VRTK_InteractGrab>(); if (branchNode != null) { VRTK_ControllerEvents controllerEvents = e.interactingObject.GetComponent <VRTK_ControllerEvents>(); controllerEvents.ButtonOnePressed += OnDisconnectButtonPressed; } else { //Force the controller to let go of the branch handle grabber.ForceRelease(); GetComponent <VRTK_InteractableObject>().isGrabbable = false; Plug branchPlug = CreatePlug(); Cord branchCord; //Create a cord between the plug and the branch handle branchCord = Instantiate(CordPrefab).GetComponent <Cord>(); branchCord.Color = sourceCord.Color; branchCord.Connect(transform, branchPlug.CordAttachPoint); branchCord.Flow = 0; branchNode = new CordNode(branchCord, transform); cordJunction = SplitCord(sourceCord); StopMovementAlongCord(); grabber.ForceGrab(branchPlug.GetComponent <VRTK_InteractableObject>(), () => { GetComponent <VRTK_InteractableObject>().isGrabbable = true; branchPlug.EnableSnapping(); }); } }