Example #1
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        roadCreator.heightOffset  = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", roadCreator.heightOffset));
        roadCreator.segmentPreset = (Preset)EditorGUILayout.ObjectField("Segment Preset", roadCreator.segmentPreset, typeof(Preset), false);

        if (roadCreator.segmentPreset == null)
        {
            roadCreator.segmentToCopy = (RoadSegment)EditorGUILayout.ObjectField("Segment To Copy", roadCreator.segmentToCopy, typeof(RoadSegment), true);
        }

        roadCreator.resolutionMultiplier = Mathf.Clamp(EditorGUILayout.FloatField("Resoltion Multiplier", roadCreator.resolutionMultiplier), 0.01f, 10f);
        roadCreator.createIntersections  = EditorGUILayout.Toggle("Create Intersections", roadCreator.createIntersections);
        roadCreator.generateCollider     = EditorGUILayout.Toggle("Generate Collider", roadCreator.generateCollider);

        GUIStyle guiStyle = new GUIStyle();

        guiStyle.fontStyle = FontStyle.Bold;

        if (roadCreator.startIntersection != null)
        {
            GUILayout.Space(20);
            GUILayout.Label("Start Intersection Lane Markings", guiStyle);
            roadCreator.startLanes = Mathf.Clamp(EditorGUILayout.IntField("Lanes", roadCreator.startLanes), 0, 10);

            if (roadCreator.startLanes > 0)
            {
                roadCreator.startMarkersScale      = Mathf.Clamp(EditorGUILayout.FloatField("Scale", roadCreator.startMarkersScale), 0.1f, 5f);
                roadCreator.startMarkersRepeations = Mathf.Clamp(EditorGUILayout.IntField("Repeations", roadCreator.startMarkersRepeations), 1, 5);
                roadCreator.startMarkersStartIntersectionOffset = Mathf.Clamp(EditorGUILayout.FloatField("Start Intersection Offset", roadCreator.startMarkersStartIntersectionOffset), 0.7f * roadCreator.startMarkersScale, 5);

                if (roadCreator.startMarkersRepeations > 1)
                {
                    roadCreator.startMarkersContinuousIntersectionOffset = Mathf.Clamp(EditorGUILayout.FloatField("Continuous Offset", roadCreator.startMarkersContinuousIntersectionOffset), 1.4f * roadCreator.startMarkersScale, 25);
                }

                roadCreator.startMarkersYOffset = Mathf.Max(EditorGUILayout.FloatField("Y Offset", roadCreator.startMarkersYOffset), 0f);

                GUILayout.Space(20);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Index");
                GUILayout.Label("Left");
                GUILayout.Label("Forwards");
                GUILayout.Label("Right");
                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < roadCreator.startLanes; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("#" + i);
                    GUILayout.Space(Screen.width / 4 - 20);
                    roadCreator.startLaneMarkers[i].one   = EditorGUILayout.Toggle(roadCreator.startLaneMarkers[i].one);
                    roadCreator.startLaneMarkers[i].two   = EditorGUILayout.Toggle(roadCreator.startLaneMarkers[i].two);
                    roadCreator.startLaneMarkers[i].three = EditorGUILayout.Toggle(roadCreator.startLaneMarkers[i].three);
                    EditorGUILayout.EndHorizontal();
                }

                if (GUILayout.Button("Reset Lane Markers"))
                {
                    for (int i = 0; i < roadCreator.startLanes; i++)
                    {
                        roadCreator.startLaneMarkers[i] = new Vector3Bool(false, true, false);
                    }
                }
            }

            GUILayout.Space(20);
        }

        if (roadCreator.endIntersection != null)
        {
            GUILayout.Space(20);
            GUILayout.Label("End Intersection Lane Markings", guiStyle);
            roadCreator.endLanes = Mathf.Clamp(EditorGUILayout.IntField("Lanes", roadCreator.endLanes), 0, 10);

            if (roadCreator.endLanes > 0)
            {
                roadCreator.endMarkersScale      = Mathf.Clamp(EditorGUILayout.FloatField("Scale", roadCreator.endMarkersScale), 0.1f, 5f);
                roadCreator.endMarkersRepeations = Mathf.Clamp(EditorGUILayout.IntField("Repeations", roadCreator.endMarkersRepeations), 1, 5);
                roadCreator.endMarkersStartIntersectionOffset = Mathf.Clamp(EditorGUILayout.FloatField("Start Intersection Offset", roadCreator.endMarkersStartIntersectionOffset), 0.7f * roadCreator.endMarkersScale, 5);

                if (roadCreator.endMarkersRepeations > 1)
                {
                    roadCreator.endMarkersContinuousIntersectionOffset = Mathf.Clamp(EditorGUILayout.FloatField("Continuous Offset", roadCreator.endMarkersContinuousIntersectionOffset), 1.4f * roadCreator.endMarkersScale, 25);
                }

                roadCreator.endMarkersYOffset = Mathf.Max(EditorGUILayout.FloatField("Y Offset", roadCreator.endMarkersYOffset), 0f);

                GUILayout.Space(20);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Index");
                GUILayout.Label("Left");
                GUILayout.Label("Forwards");
                GUILayout.Label("Right");
                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < roadCreator.endLanes; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("#" + i);
                    GUILayout.Space(Screen.width / 4 - 20);
                    roadCreator.endLaneMarkers[i].one   = EditorGUILayout.Toggle(roadCreator.endLaneMarkers[i].one);
                    roadCreator.endLaneMarkers[i].two   = EditorGUILayout.Toggle(roadCreator.endLaneMarkers[i].two);
                    roadCreator.endLaneMarkers[i].three = EditorGUILayout.Toggle(roadCreator.endLaneMarkers[i].three);
                    EditorGUILayout.EndHorizontal();
                }

                if (GUILayout.Button("Reset Lane Markers"))
                {
                    for (int i = 0; i < roadCreator.endLanes; i++)
                    {
                        roadCreator.endLaneMarkers[i] = new Vector3Bool(false, true, false);
                    }
                }
            }

            GUILayout.Space(20);
        }

        if (EditorGUI.EndChangeCheck() == true)
        {
            roadCreator.CreateMesh();
        }

        if (GUILayout.Button("Flip Road"))
        {
            roadCreator.Flip();
        }

        if (GUILayout.Button("Reset Road"))
        {
            ResetObject();
        }

        if (GUILayout.Button("Generate Road"))
        {
            roadCreator.CreateMesh();
        }
    }