//compares the current vertices timing and y cordinate to the vertices before and after it to see if its "out of bounds" private void yClamper(out float clampedY, out float clampedTiming) { float siblingY; float siblingTiming; //get the vertex physically higher than the one currently being examined currentVertexManager.getHigherVertex(out siblingY, out siblingTiming); int controllersTiming = (int)currentVertexManager.getVertexTiming(); //if statement to check whether the parent of the vertex is the controller: if (currentVertexManager.gameObject.transform.parent.transform == gameObject.transform) { controllersTiming = GridManager.getClosestTiming(currentVertexManager.gameObject.transform.parent.transform.position.y); } clampedTiming = Mathf.Max(currentVertexManager.getVertexTiming(), siblingTiming); clampedY = GridManager.getYFromTiming((int)clampedTiming); //==== currentVertexManager.getLowerVertex(out siblingY, out siblingTiming); clampedTiming = Mathf.Min(clampedTiming, siblingTiming); clampedY = GridManager.getYFromTiming((int)clampedTiming); if (clampedTiming >= GridManager.getYSegments() - 1) { Debug.LogWarning("Vertex is going below valid timings"); clampedTiming = GridManager.getYSegments() - 1; clampedY = GridManager.getYFromTiming((int)clampedTiming); } }
//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); } } }