Exemple #1
0
    private static void DrawRoadGuidelines(RoadGuideline guidelines, int child, RoadSegment roadSegment, Vector3 mousePosition, GameObject objectToMove, GameObject extraObjectToMove)
    {
        if (roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings == null)
        {
            roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings = RoadCreatorSettings.GetSerializedSettings();
        }

        if (child == 1)
        {
            Handles.color = roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings.FindProperty("roadControlGuidelinesColour").colorValue;
        }
        else
        {
            Handles.color = roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings.FindProperty("roadGuidelinesColour").colorValue;
        }

        if (guidelines != null && roadSegment.transform.GetChild(0).GetChild(child).gameObject != objectToMove && roadSegment.transform.GetChild(0).GetChild(child).gameObject != extraObjectToMove)
        {
            Vector2 mousePositionXZ = new Vector3(mousePosition.x, mousePosition.z);
            Vector2 nereastPoint    = Misc.FindNearestPointOnLine(new Vector2(guidelines.startPoint.x, guidelines.startPoint.z), new Vector2(guidelines.endPoint.x, guidelines.endPoint.z), mousePositionXZ);

            if (Vector2.Distance(mousePositionXZ, nereastPoint) < roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings.FindProperty("roadGuidelinesDistance").floatValue)
            {
                Handles.DrawLine(guidelines.centerPoint, guidelines.startPoint);
                Handles.DrawLine(guidelines.centerPoint, guidelines.endPoint);
                Handles.DrawSolidDisc(guidelines.centerPoint, Vector3.up, roadSegment.transform.parent.parent.GetComponent <RoadCreator>().settings.FindProperty("pointSize").floatValue * 0.75f);

                Vector3 left = CalculateLeft(guidelines.startPoint, guidelines.endPoint);
                Handles.DrawLine(guidelines.startPoint - left * 0.5f, guidelines.startPoint + left * 0.5f);
                Handles.DrawLine(guidelines.endPoint - left * 0.5f, guidelines.endPoint + left * 0.5f);
            }
        }
    }
Exemple #2
0
    private void SetGuidelines(Vector3[] currentPoints, Vector3[] nextPoints, bool first)
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        // Start Guidelines
        Vector3 left;
        float   roadGuidelinesLength = settings.FindProperty("roadGuidelinesLength").floatValue;

        if (roadGuidelinesLength > 0)
        {
            if (first == true)
            {
                left = Misc.CalculateLeft(currentPoints[0], currentPoints[1]);
                startGuidelinePoints = new RoadGuideline(transform.GetChild(0).GetChild(0).position + left * roadGuidelinesLength, transform.GetChild(0).GetChild(0).position, transform.GetChild(0).GetChild(0).position - left * roadGuidelinesLength);
            }

            // Center Guidelines
            if (currentPoints.Length > 3)
            {
                left = Misc.CalculateLeft(currentPoints[(currentPoints.Length + 1) / 2], currentPoints[(currentPoints.Length + 1) / 2 + 1]);
                centerGuidelinePoints = new RoadGuideline(transform.GetChild(0).GetChild(1).position + left * roadGuidelinesLength, transform.GetChild(0).GetChild(1).position, transform.GetChild(0).GetChild(1).position - left * roadGuidelinesLength);
            }

            // End guidelines
            if (nextPoints == null)
            {
                left = Misc.CalculateLeft(currentPoints[currentPoints.Length - 2], currentPoints[currentPoints.Length - 1]);
            }
            else if (nextPoints.Length > 1)
            {
                left = Misc.CalculateLeft(currentPoints[currentPoints.Length - 1], nextPoints[1]);
            }
            else
            {
                endGuidelinePoints = null;
                return;
            }

            endGuidelinePoints = new RoadGuideline(transform.GetChild(0).GetChild(2).position + left * roadGuidelinesLength, transform.GetChild(0).GetChild(2).position, transform.GetChild(0).GetChild(2).position - left * roadGuidelinesLength);
        }
        else
        {
            startGuidelinePoints  = null;
            centerGuidelinePoints = null;
            endGuidelinePoints    = null;
        }
    }
Exemple #3
0
    public static Vector3 GetNearestGuidelinePoint(Vector3 hitPosition)
    {
        RoadSegment[] roadSegments    = GameObject.FindObjectsOfType <RoadSegment>();
        Vector3       nearest         = MaxVector3;
        float         nearestDistance = float.MaxValue;
        Vector2       mousePosition   = new Vector3(hitPosition.x, hitPosition.z);

        for (int i = 0; i < roadSegments.Length; i++)
        {
            RoadGuideline roadGuideline = roadSegments[i].startGuidelinePoints;

            if (roadGuideline != null)
            {
                Vector3 nearestOnLine = CheckGuideline(nearestDistance, mousePosition, roadGuideline, roadSegments[i].transform.parent.parent.GetComponent <RoadCreator>().settings);
                if (nearestOnLine != MaxVector3)
                {
                    nearest         = nearestOnLine;
                    nearestDistance = Vector2.Distance(mousePosition, new Vector2(nearestOnLine.x, nearestOnLine.z));
                }
            }

            roadGuideline = roadSegments[i].centerGuidelinePoints;
            if (roadGuideline != null)
            {
                Vector3 nearestOnLine = CheckGuideline(nearestDistance, mousePosition, roadGuideline, roadSegments[i].transform.parent.parent.GetComponent <RoadCreator>().settings);
                if (nearestOnLine != MaxVector3)
                {
                    nearest         = nearestOnLine;
                    nearestDistance = Vector2.Distance(mousePosition, new Vector2(nearestOnLine.x, nearestOnLine.z));
                }
            }

            roadGuideline = roadSegments[i].endGuidelinePoints;
            if (roadGuideline != null)
            {
                Vector3 nearestOnLine = CheckGuideline(nearestDistance, mousePosition, roadGuideline, roadSegments[i].transform.parent.parent.GetComponent <RoadCreator>().settings);
                if (nearestOnLine != MaxVector3)
                {
                    nearest         = nearestOnLine;
                    nearestDistance = Vector2.Distance(mousePosition, new Vector2(nearestOnLine.x, nearestOnLine.z));
                }
            }
        }

        return(nearest);
    }
Exemple #4
0
    private static Vector3 CheckGuideline(float nearestDistance, Vector3 mousePosition, RoadGuideline roadGuideline, SerializedObject settings)
    {
        Vector3 nearestLinePoint = Misc.FindNearestPointOnLine(new Vector2(roadGuideline.startPoint.x, roadGuideline.startPoint.z), new Vector2(roadGuideline.endPoint.x, roadGuideline.endPoint.z), mousePosition);
        float   distance         = Vector2.Distance(mousePosition, nearestLinePoint);

        if (distance < nearestDistance && distance < settings.FindProperty("roadGuidelinesSnapDistance").floatValue)
        {
            nearestDistance = distance;
            return(new Vector3(nearestLinePoint.x, roadGuideline.centerPoint.y, nearestLinePoint.y));
        }

        return(MaxVector3);
    }