Ejemplo n.º 1
0
        private void OnDisconnectButtonPressed(object sender, ControllerInteractionEventArgs e)
        {
            grabber.ForceRelease();
            GetComponent <VRTK_InteractableObject>().enabled = false;
            GetComponent <MeshRenderer>().enabled            = false;
            GetComponent <Collider>().enabled = false;

            DisconnectBranchFromJunction();

            sourceCord = MergeJunction();
            sourceCord.AllowBranching(false);

            Plug disconnectedPlug = CreatePlug();

            if (branchNode.Cord.StartNode.Equals(branchNode.transform))
            {
                branchNode.Cord.Connect(disconnectedPlug.CordAttachPoint, branchNode.Cord.EndNode);
            }
            else
            {
                branchNode.Cord.Connect(branchNode.Cord.StartNode, disconnectedPlug.CordAttachPoint);
            }

            grabber.ForceGrab(disconnectedPlug.GetComponent <VRTK_InteractableObject>(), () =>
            {
                disconnectedPlug.EnableSnapping();
                sourceCord.AllowBranching(true);
                Destroy(this.gameObject);
            });
        }
Ejemplo n.º 2
0
        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();
                });
            }
        }