//function for letting go of a vertex public void letGo() { if (!currentRigidBody) { return; } else { if (!currentGameObject.active) { //don't bother letting go if currentRigidBody is already been deactivated (aka removed) return; } else { currentGameObject.transform.parent = currentVertexManager.getBaseLineParent(); currentVertexManager.setIsSelected(false); Vector3 yToSnap = snap(); currentVertexManager.moveTo(yToSnap); currentVertexManager.onPutDown(); resetVariables(); } } }
//method used to check if the current held vertex is going too low, too far from center, or too close to center. private void outOfBoundsCheck() { bool outOfBounds = false; int r = 4; Vector3 pos = transform.position; float currentX = pos.x; float currentY = pos.y; float currentZ = pos.z; VertexManager tempVertexManager = currentVertexManager; if (currentY <= 0.1) { //pos.Set(pos.x, 0.15f, pos.z); //letGo(); //currentVertexManager.moveTo(pos); outOfBounds = true; } else if (Mathf.Sqrt(Mathf.Pow(currentX, 2) + Mathf.Pow(currentZ, 2)) > r) { float m = (currentZ / currentX); float newX = ((r - 0.01f) / (Mathf.Sqrt(Mathf.Pow(m, 2) + 1))); float newZ = newX * m; pos.Set(newX, currentY, newZ); //letGo(); tempVertexManager.moveTo(pos); outOfBounds = true; //return; } else if (checkSiblingHeights() != transform.position.y) { pos.y = checkSiblingHeights(); tempVertexManager.moveTo(pos); outOfBounds = true; } if (!outOfBounds) { Vector3 tempPos = transform.position; tempVertexManager.moveTo(tempPos); } }
//method that is called when the controller should pick up the nearest rigid body public void pickUp() { currentRigidBody = GetNearestRigidBody(); if (!currentRigidBody) { return; } else { //if statement checking the id of the vertex: if (currentRigidBody.GetComponent <VertexManager>().getBaseLineParent().GetComponent <LineManager>().getNumberOfVertices() - 1 == currentRigidBody.GetComponent <VertexManager>().getVertexID()) { //if the id is the last in the line, cycle the voice of the line currentRigidBody.GetComponent <VertexManager>().getParentsLineManager().cycleVoices(); resetVariables(); } else { //set current-XYZ variables currentGameObject = currentRigidBody.gameObject; currentVertexManager = currentRigidBody.GetComponent <VertexManager>(); currentVertexManager.setIsSelected(true); Vector3 oldPos = currentGameObject.transform.position; //set the rigidBody parent and position to the controller holding it. currentRigidBody.transform.parent = gameObject.transform; currentRigidBody.transform.position = transform.position; fixedJoint.connectedBody = currentRigidBody; currentVertexManager.onPickUp(); //if statement to check whether the id of the vertex is editable, if it isn't, act as if a new vertex should be made: if (!isEditable(currentVertexManager.getVertexID(), currentVertexManager.getBaseLineParent().gameObject)) { VertexManager newlyCreatedVertexManager = addNewVertex().GetComponent <VertexManager>(); newlyCreatedVertexManager.moveTo(oldPos); } } } }
//simple method for changing a hovered over vertices timing and y cordindate public void moveVertexDown() { GameObject nearestVertex = hoverOverVertex(); if (nearestVertex) { VertexManager nearestVertexManager = nearestVertex.GetComponent <VertexManager>(); float nearestVertexTiming = nearestVertexManager.getVertexTiming(); float lowerSiblingY; float lowerSiblingTiming; nearestVertexManager.getLowerVertex(out lowerSiblingY, out lowerSiblingTiming); if (nearestVertexTiming <= GridManager.getYSegments() - 1 && nearestVertexTiming < lowerSiblingTiming) { Vector3 currentPos = nearestVertex.transform.position; Vector3 newPos = new Vector3(currentPos.x, GridManager.getYFromTiming((int)nearestVertexTiming + 1), currentPos.z); nearestVertexManager.moveTo(newPos); } } }
//simple method for changing a hovered over vertices timing and y cordindate public void moveVertexUp() { GameObject nearestVertex = hoverOverVertex(); if (nearestVertex) { VertexManager nearestVertexManager = nearestVertex.GetComponent <VertexManager>(); float nearestVertexTiming = nearestVertexManager.getVertexTiming(); float higherSiblingY; float higherSiblingTiming; nearestVertexManager.getHigherVertex(out higherSiblingY, out higherSiblingTiming); if (nearestVertexTiming != 0 && nearestVertexTiming > higherSiblingTiming) { Vector3 currentPos = nearestVertex.transform.position; Vector3 newPos = new Vector3(currentPos.x, GridManager.getYFromTiming((int)nearestVertexTiming - 1), currentPos.z); nearestVertexManager.moveTo(newPos); } } }