コード例 #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();
        }
コード例 #2
0
ファイル: CordDispenser.cs プロジェクト: lane-s/ComposeVR
        /// <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);
        }
コード例 #3
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));
        }