/// <summary> /// Disregard whether the plug is grabbed or not- lock it and connect it to the socket /// </summary /// <param name="p"></param> public void ForcePlugLockAndConnect(Plug p) { if (p.AttachLock(this)) { if (p.GetComponent <VRTK_InteractableObject>().IsGrabbed()) { lockedPlugGrabber = p.GetComponent <VRTK_InteractableObject>().GetGrabbingObject().GetComponentInActor <VRTK_InteractGrab>(); } else { lockedPlugGrabber = null; } LockedPlug = p; LockedPlug.GetComponent <VRTK_InteractableObject>().InteractableObjectUngrabbed += OnLockedPlugUngrabbed; LockedPlug.GetComponent <VRTK_InteractableObject>().InteractableObjectGrabbed += OnLockedPlugGrabbed; LockedPlug.ConnectToDataEndpoint(plugReceptacle); } }
protected virtual void TryLockPlug(Plug p) { if (p.GetComponent <VRTK_InteractableObject>().IsGrabbed()) { float flow = p.ConnectedCord.Flow; if (p.CordAttachPoint.Equals(p.ConnectedCord.StartNode)) { flow = -flow; } bool validReceptacleType = (flow > 0 && GetComponent <PhysicalDataInput>() != null) || (flow < 0 && GetComponent <PhysicalDataOutput>() != null) || flow == 0; if (validReceptacleType) { if (p.AttachLock(this)) { lockedPlugGrabber = p.GetComponent <VRTK_InteractableObject>().GetGrabbingObject().GetComponentInActor <VRTK_InteractGrab>(); LockedPlug = p; LockedPlug.GetComponent <VRTK_InteractableObject>().InteractableObjectUngrabbed += OnLockedPlugUngrabbed; LockedPlug.GetComponent <VRTK_InteractableObject>().InteractableObjectGrabbed += OnLockedPlugGrabbed; } } } }