コード例 #1
0
    //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);
        }
    }
コード例 #2
0
    //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);
            }
        }
    }