Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new cord consisting of two connected plugs and a actual cord object. This is the cord that the jack will deploy when the user's controller comes near
        /// </summary>
        private void CreateCord()
        {
            primaryPlugAttach   = CreatePlugAttach("PrimaryPlugAttach");
            secondaryPlugAttach = CreatePlugAttach("SecondaryPlugAttach");

            primaryPlug      = Instantiate(PlugPrefab, PlugStart.position, PlugStart.rotation);
            primaryPlug.name = "Primary";
            primaryPlug.GetComponent <VRTK_TransformFollow>().gameObjectToFollow = primaryPlugAttach;

            secondaryPlug      = Instantiate(PlugPrefab, PlugStart.position, PlugStart.rotation);
            secondaryPlug.name = "Secondary";
            secondaryPlug.GetComponent <VRTK_TransformFollow>().gameObjectToFollow = secondaryPlugAttach;

            cord = Instantiate(CordPrefab).GetComponent <Cord>();
            cord.Connect(secondaryPlug.CordAttachPoint, primaryPlug.CordAttachPoint);

            cord.Flow = 1;

            if (GetComponent <PhysicalDataInput>() != null)
            {
                cord.Flow = -cord.Flow;
            }
            cord.Flowing = true;

            cord.gameObject.SetActive(false);
            primaryPlug.gameObject.SetActive(false);
            secondaryPlug.gameObject.SetActive(false);
        }
Exemplo n.º 3
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);
            });
        }
Exemplo n.º 4
0
 public void Disconnect(Cord connectedCord, Transform plugNodeInCord)
 {
     if (PlugDisconnected != null)
     {
         PlugDisconnected(this, new PhysicalConnectionEventArgs(connectedCord, plugNodeInCord));
     }
 }
Exemplo n.º 5
0
 public void ReplaceCord(Cord toReplace, Cord replacement)
 {
     if (branchNode != null && branchNode.Cord.Equals(toReplace))
     {
         branchNode.Cord = replacement;
     }
     else if (cordJunction != null && cordJunction.A != null && cordJunction.A.Cord.Equals(toReplace))
     {
         cordJunction.A.Cord = replacement;
     }
     else if (cordJunction != null && cordJunction.B != null && cordJunction.B.Cord.Equals(toReplace))
     {
         cordJunction.B.Cord = replacement;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// A BranchHandle exists at the intersection of three cords:
        /// The two cords in the CordJunction that was formed by splitting the source cord as well as the newly created branch cord
        ///
        /// This method takes a cord that is about to collapse as the parameter and merges the other two cords of the handle together.
        /// </summary>
        /// <param name="collapsedCord"></param>
        public void MergeRemainingCords(Cord collapsedCord)
        {
            if (collapsedCord.Equals(branchNode.Cord))
            {
                //If the branch cord has collapsed we merge the junction and end up with the same cord that was split by the BranchHandle
                MergeJunction();
            }
            else
            {
                //Otherwise one side of the junction has collapsed so we merge the branch cord with the other side of the junction
                List <Vector3> mergedPath = new List <Vector3>();
                CordNode       toMerge    = collapsedCord.Equals(cordJunction.A.Cord) ? cordJunction.B : cordJunction.A;

                Transform branchEnd = branchNode.transform.Equals(branchNode.Cord.StartNode) ? branchNode.Cord.EndNode : branchNode.Cord.StartNode;

                if (toMerge.transform.Equals(toMerge.Cord.StartNode))
                {
                    toMerge.Cord.Connect(branchEnd, toMerge.Cord.EndNode);
                    mergedPath.AddRange(branchNode.Cord.Path);
                    mergedPath.AddRange(toMerge.Cord.Path);
                }
                else
                {
                    toMerge.Cord.Connect(toMerge.Cord.StartNode, branchEnd);
                    mergedPath.AddRange(toMerge.Cord.Path);
                    mergedPath.AddRange(branchNode.Cord.Path);
                }

                toMerge.Cord.Path = mergedPath;

                if (branchEnd.GetComponent <BranchHandle>())
                {
                    BranchHandle startHandle = branchEnd.GetComponent <BranchHandle>();
                    startHandle.ReplaceCord(branchNode.Cord, toMerge.Cord);
                }

                branchNode.Cord.DestroyCord();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Splits the cord so that this cord contains the points before splitPoint and splitCord contains the points after splitPoint
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="splitPointIndex"></param>
        /// <param name="splitCord"></param>
        /// <returns></returns>
        public CordJunction SplitByBranchHandle(BranchHandle handle, int splitPointIndex, Cord splitCord)
        {
            //Get the points after the splitPoint and assign them to the splitCord
            List <Vector3> splitPath = new List <Vector3>();

            for (int i = splitPointIndex; i < path.Count; i++)
            {
                splitPath.Add(path[i]);
            }

            splitCord.Color = Color;
            splitCord.Flow  = Flow;
            splitCord.Connect(handle.transform, B);
            if (B.GetComponent <BranchHandle>() != null)
            {
                B.GetComponent <BranchHandle>().ReplaceCord(this, splitCord);
            }

            splitCord.Path = splitPath;
            splitCord.AllowBranching(true);

            int combinedPathLength = path.Count;

            //Exclude the points in the splitCord from this cord
            for (int i = 0; i < combinedPathLength - splitPointIndex; i++)
            {
                path.RemoveAt(path.Count - 1);
            }
            B = handle.transform;

            branchHandles.Remove(handle);
            CreateBranchHandles(handle.TrackedController);
            UpdateBoundingBox();

            CordNode JunctionA = new CordNode(this, handle.transform);
            CordNode JunctionB = new CordNode(splitCord, handle.transform);

            return(new CordJunction(JunctionA, JunctionB, Flow));
        }
Exemplo n.º 8
0
        private CordJunction SplitCord(Cord cord)
        {
            Cord splitCord = Instantiate(CordPrefab).GetComponent <Cord>();

            return(cord.SplitByBranchHandle(this, closestCordPointIndex, splitCord));
        }
Exemplo n.º 9
0
 public CordNode(Cord cord, Transform nodeInCord)
 {
     this.Cord      = cord;
     this.transform = nodeInCord;
 }
Exemplo n.º 10
0
 public void SetCord(Cord c)
 {
     cord = c;
 }
Exemplo n.º 11
0
 public PhysicalConnectionEventArgs(Cord connectedCord, Transform plugEnd)
 {
     this.connectedCord = connectedCord;
     this.plugEnd       = plugEnd;
 }