//Connect components to eachother - called in audio engine public void createConnection(CoreComponent input, CoreComponent output, CoreSocketCasing inputSocket, CoreSocketCasing outputSocket) { if (inputSocket is AudioInputSocketCasing && outputSocket is AudioOutputSocketCasing) { AudioSocketComponent inSocComp = audioInputs[inputSocket.getSocketNum()]; AudioSocketComponent outSocComp = output.io.audioOutputs[outputSocket.getSocketNum()]; inSocComp.connect(outSocComp); inSocComp.setSocketNum(inputSocket.getSocketNum()); outSocComp.connect(inSocComp); outSocComp.setSocketNum(outputSocket.getSocketNum()); } else if (inputSocket is DataInputSocketCasing && outputSocket is DataOutputSocketCasing) { DataSocketComponent inSocComp = dataInputs[inputSocket.getSocketNum()]; DataSocketComponent outSocComp = output.io.dataOutputs[outputSocket.getSocketNum()]; DataSocketCasing dataInputSocket = inputSocket as DataSocketCasing; DataSocketCasing dataOutputSocket = outputSocket as DataSocketCasing; inSocComp.connect(outSocComp); inSocComp.setSocketNum(dataInputSocket.getSocketNum()); inSocComp.setControlNum(dataInputSocket.getControlNum()); outSocComp.connect(inSocComp); outSocComp.setSocketNum(dataOutputSocket.getSocketNum()); outSocComp.setControlNum(dataOutputSocket.getControlNum()); } }
//Connect two components sockets together -- Receiving Socket --> Sending Socket public void createConnection(CoreSocketCasing socket1, CoreSocketCasing socket2) { //Interprets the correct way around - input->output CoreComponent input = null, output = null; CoreSocketCasing inSoc = null, outSoc = null; if (socket1 is AudioInputSocketCasing || socket1 is DataInputSocketCasing) { input = socket1.GetComponentInParent <CoreCasing>().getComponent(); output = socket2.GetComponentInParent <CoreCasing>().getComponent(); inSoc = socket1; outSoc = socket2; } else if (socket1 is AudioOutputSocketCasing || socket1 is DataOutputSocketCasing) { input = socket2.GetComponentInParent <CoreCasing>().getComponent(); output = socket1.GetComponentInParent <CoreCasing>().getComponent(); inSoc = socket2; outSoc = socket1; } else { return; } input.io.createConnection(input, output, inSoc, outSoc); socket1.drawCable(socket2); print("Connection made"); }
public void undrawCable() { if (cable != null) { cable.SetPosition(0, Vector3.zero); cable.SetPosition(1, Vector3.zero); cable = null; } if (connectedSocket != null) { connectedSocket.connectedSocket = null; connectedSocket = null; } }
public void startDrawing() { drawing = true; RaycastHit hit; if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, f_interactionDistance, layerMask)) { if (hit.transform.gameObject.layer == LAYER.SOCKET) { CoreSocketCasing socketHit = hit.transform.GetComponent <CoreSocketCasing>(); lineRenderer = this.gameObject.GetComponent <LineRenderer>(); lineRenderer.SetPosition(0, socketHit.transform.position); } } }
//Disconnect sockets public void disconnect(CoreSocketCasing socket) { if (socket is AudioInputSocketCasing) { audioInputs[socket.getSocketNum()].disconnect(); } else if (socket is AudioOutputSocketCasing) { audioOutputs[socket.getSocketNum()].disconnect(); } else if (socket is DataInputSocketCasing) { dataInputs[socket.getSocketNum()].disconnect(); } else if (socket is DataOutputSocketCasing) { dataOutputs[socket.getSocketNum()].disconnect(); } }
public void drawCable(CoreSocketCasing otherSocket) { if (connectedSocket != null) { connectedSocket.undrawCable(); } if (otherSocket.connectedSocket != null) { otherSocket.undrawCable(); } getCable(); //Tell the sockets who they're now connected to connectedSocket = otherSocket; connectedSocket.connectedSocket = this; connectedSocket.cable = cable; //Set the positions cable.SetPosition(0, this.transform.position); cable.SetPosition(1, otherSocket.transform.position); }
private void selectObject() { //Shoot a ray and detect what's in front of the player - Proceed if an interactable was hit if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, f_interactionDistance, layerMask)) { prevItems[prevItemsCounter] = hit.transform.gameObject; //Keep a reference of the object hit print(hit.transform.gameObject.name.ToString()); // Tell us what it was b_objectSelected = true; // An object has been selected layerHit = hit.transform.gameObject.layer; // Take a copy of the object's layer number switch (layerHit) { case LAYER.CONTROL: prevItems[prevItemsCounter].GetComponent <Control>().select(playerCamera.transform.position + playerCamera.transform.forward * 2); break; case LAYER.SOCKET: guideCable.startDrawing(); if (prevItems[0] == null || prevItems[1] == null) { break; } CoreSocketCasing selectedSocket = prevItems[prevItemsCounter].GetComponent <CoreSocketCasing>(); CoreSocketCasing prevSelectedSocket; if (prevItemsCounter == 1) { prevSelectedSocket = prevItems[0].GetComponent <CoreSocketCasing>(); } else { prevSelectedSocket = prevItems[1].GetComponent <CoreSocketCasing>(); } //Cannot connect to other socket in same component if (prevSelectedSocket != null && selectedSocket.GetComponentInParent <CoreCasing>() != prevSelectedSocket.GetComponentInParent <CoreCasing>()) { //If input to output if (((selectedSocket is AudioInputSocketCasing && prevSelectedSocket is AudioOutputSocketCasing) || (selectedSocket is AudioOutputSocketCasing && prevSelectedSocket is AudioInputSocketCasing)) || ((selectedSocket is DataInputSocketCasing && prevSelectedSocket is DataOutputSocketCasing) || (selectedSocket is DataOutputSocketCasing && prevSelectedSocket is DataInputSocketCasing))) { audioEngine.createConnection(selectedSocket, prevSelectedSocket); print("Input/Output audio combo found"); prevItems[0] = null; prevItems[1] = null; guideCable.release(); } } //If same socket is selected twice else if (prevItems[0].GetComponent <CoreSocketCasing>() == prevItems[1].GetComponent <CoreSocketCasing>()) { print("Connection cleared"); audioEngine.destroyConnection(selectedSocket); prevItems[0] = null; prevItems[1] = null; guideCable.release(); } break; case LAYER.CASE: break; } } else { guideCable.release(); } }
public void destroyConnection(CoreSocketCasing socket) { socket.undrawCable(); socket.GetComponentInParent <CoreCasing>().getComponent().io.disconnect(socket); print("Connection unmade"); }