void changeSegment(Road road, int distance)
 {
     road.setPoints(roadTemp);
     road.addPoint(road[road.Length - 1] + roadEditorController.directionToVector(selectedDirection).normalized *roadEditorController.offset);
     if (selectedDirection == Direction.N || selectedDirection == Direction.E || selectedDirection == Direction.W || selectedDirection == Direction.S)
     {
         for (int i = 0; i < distance / roadEditorController.offset; i++)
         {
             float f = Mathf.Lerp(roadEditorController.getLastHeight(), roadEditorController.getHeight(), (float)i / (distance / roadEditorController.offset));
             road.addPoint(road[road.Length - 1] + roadEditorController.directionToVector(selectedDirection).normalized *roadEditorController.offset);
             road[road.Length - 1] = new Vector3(road[road.Length - 1].x, f, road[road.Length - 1].z);
         }
     }
     else
     {
         for (int i = 0; i < distance / (roadEditorController.offset * Mathf.Sqrt(2f)); i++)
         {
             float f = Mathf.Lerp(roadEditorController.getLastHeight(), roadEditorController.getHeight(), (float)i / (distance / (roadEditorController.offset * Mathf.Sqrt(2f))));
             road.addPoint(road[road.Length - 1] + roadEditorController.directionToVector(selectedDirection));
             road[road.Length - 1] = new Vector3(road[road.Length - 1].x, f, road[road.Length - 1].z);
         }
     }
 }
Beispiel #2
0
    public bool usage(RaycastHit hit, Extension extension, GameObject road)
    {
        if (currentPhase == Phase.Init)
        {
            roadEditorController          = RoadEditorController.Instance;
            roadEditorController.showGrid = true;


            if (road.GetComponent <Road>().isEmpty())
            {
                dirA    = extension.ExitOrientation;
                dirB    = roadEditorController.getOppositDirection(extension.ExitOrientation);
                anchorA = extension.ExitPos;
                road.GetComponent <Road>().addPoint(anchorA);
                road.GetComponent <Road>().addPoint(roadEditorController.directionToVector(dirA) * magnitudeA + anchorA);
                road.GetComponent <Road>().addPoint(roadEditorController.directionToVector(dirB) * magnitudeB + new Vector3(hit.point.x, roadEditorController.getHeight(), hit.point.z));
                road.GetComponent <Road>().addPoint(new Vector3(hit.point.x, roadEditorController.getHeight(), hit.point.z));
            }
            else
            {
                anchorA = road.GetComponent <Road>()[road.GetComponent <Road>().Length - 4];
            }


            currentPhase = Phase.Streaching;
        }
        else if (currentPhase == Phase.InitStreaching)
        {
            dirA    = roadEditorController.getOppositDirection(dirB);
            dirB    = roadEditorController.getOppositDirection(dirA);
            anchorA = road.GetComponent <Road>()[road.GetComponent <Road>().Length - 1];
            pivotA  = roadEditorController.directionToVector(dirA) * magnitudeA + anchorA;
            pivotB  = roadEditorController.directionToVector(dirB) * magnitudeB + anchorB;
            road.GetComponent <Road>().addPoint(pivotA);
            road.GetComponent <Road>().addPoint(pivotB);
            road.GetComponent <Road>().addPoint(anchorA);
            currentPhase = Phase.Streaching;
        }
        else if (currentPhase == Phase.Streaching)
        {
            anchorB = roadEditorController.SnapPosition(new Vector3(hit.point.x, roadEditorController.getHeight(), hit.point.z), roadEditorController.offset);

            pivotA = roadEditorController.directionToVector(dirA) * magnitudeA + anchorA;
            pivotB = roadEditorController.directionToVector(dirB) * magnitudeB + anchorB;

            road.GetComponent <Road>()[road.GetComponent <Road>().Length - 3] = pivotA;
            road.GetComponent <Road>()[road.GetComponent <Road>().Length - 2] = pivotB;
            road.GetComponent <Road>()[road.GetComponent <Road>().Length - 1] = anchorB;

            if (Input.GetKeyDown(KeyCode.G))
            {
                roadEditorController.showGrid = !roadEditorController.showGrid;
            }

            if (Input.GetKey(KeyCode.A))            //INPUT Slider Left
            {
                magnitudeA = Mathf.Clamp(magnitudeA + .5f, 1f, maxPivot);
            }
            if (Input.GetKey(KeyCode.S))
            {
                magnitudeA = Mathf.Clamp(magnitudeA - .5f, 1f, maxPivot);
            }

            if (Input.GetKey(KeyCode.Z))            //INPUT Slider Right
            {
                magnitudeB = Mathf.Clamp(magnitudeB + .5f, 1f, maxPivot);
            }
            if (Input.GetKey(KeyCode.X))
            {
                magnitudeB = Mathf.Clamp(magnitudeB - .5f, 1f, maxPivot);
            }

            if (Input.GetKey(KeyCode.Keypad8)) //INPUT Pad
            {
                dirB = Direction.N;
            }
            else if (Input.GetKey(KeyCode.Keypad4))
            {
                dirB = Direction.W;
            }
            else if (Input.GetKey(KeyCode.Keypad6))
            {
                dirB = Direction.E;
            }
            else if (Input.GetKey(KeyCode.Keypad2))
            {
                dirB = Direction.S;
            }
            else if (Input.GetKey(KeyCode.Keypad7))
            {
                dirB = Direction.WN;
            }
            else if (Input.GetKey(KeyCode.Keypad9))
            {
                dirB = Direction.NE;
            }
            else if (Input.GetKey(KeyCode.Keypad3))
            {
                dirB = Direction.ES;
            }
            else if (Input.GetKey(KeyCode.Keypad1))
            {
                dirB = Direction.SW;
            }

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                roadEditorController.addHeight();
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                roadEditorController.subHeight();
            }

            updatePreview(road);

            if (Input.GetMouseButtonDown(0))         //Right Pad Click Confirme Length
            {
                roadEditorController.lastHeightConfirm();
                currentPhase = Phase.InitStreaching;
            }
            else if (Input.GetKeyDown(KeyCode.Return))        //Left Click Pad Confirme Path
            {
                currentPhase = Phase.ConfrimeAll;
            }
        }
        else if (currentPhase == Phase.ConfrimeAll)
        {
            road.GetComponent <Road>().rendererExtensions();
            magnitudeA   = 10f;
            magnitudeB   = 10f;
            anchorA      = Vector3.zero;
            anchorB      = Vector3.zero;
            pivotA       = Vector3.zero;
            pivotB       = Vector3.zero;
            currentPhase = Phase.Init;
            roadEditorController.showGrid = false;
            return(true);
        }
        return(false);
    }