示例#1
0
    public void Setup()
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        if (transform.childCount == 0 || transform.GetChild(0).name != "Points")
        {
            GameObject points = new GameObject("Points");
            points.transform.SetParent(transform, false);
            points.transform.SetAsFirstSibling();
            points.hideFlags = HideFlags.NotEditable;
        }

        if (transform.childCount < 2 || transform.GetChild(1).name != "Objects")
        {
            GameObject objects = new GameObject("Objects");
            objects.transform.SetParent(transform, false);

            if (settings.FindProperty("hideNonEditableChildren").boolValue == true)
            {
                objects.hideFlags = HideFlags.HideInHierarchy;
            }
            else
            {
                objects.hideFlags = HideFlags.NotEditable;
            }
        }

        startPrefab = (GameObject)settings.FindProperty("defaultPrefabLineStartPrefab").objectReferenceValue;
        endPrefab   = (GameObject)settings.FindProperty("defaultPrefabLineEndPrefab").objectReferenceValue;
    }
示例#2
0
    public static void UpdateSettings()
    {
        RoadSystem[] roadSystems = GameObject.FindObjectsOfType <RoadSystem>();
        for (int i = 0; i < roadSystems.Length; i++)
        {
            for (int j = 0; j < roadSystems[i].transform.childCount; j++)
            {
                Transform transform = roadSystems[i].transform.GetChild(j);

                if (transform.GetComponent <RoadCreator>() != null)
                {
                    transform.GetComponent <RoadCreator>().settings = RoadCreatorSettings.GetSerializedSettings();
                }
                else if (transform.GetComponent <RoadSegment>() != null)
                {
                    transform.GetComponent <RoadSegment>().settings = RoadCreatorSettings.GetSerializedSettings();
                }
                else if (transform.GetComponent <PrefabLineCreator>() != null)
                {
                    transform.GetComponent <PrefabLineCreator>().settings = RoadCreatorSettings.GetSerializedSettings();
                }
                else if (transform.GetComponent <Intersection>() != null)
                {
                    transform.GetComponent <Intersection>().settings = RoadCreatorSettings.GetSerializedSettings();
                }
                else if (transform.GetComponent <RoadSystem>() != null)
                {
                    transform.GetComponent <RoadSystem>().settings = RoadCreatorSettings.GetSerializedSettings();
                }
            }
        }
    }
示例#3
0
    public void Setup()
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        gameObject.AddComponent <MeshFilter>();
        gameObject.AddComponent <MeshRenderer>();
        gameObject.AddComponent <MeshCollider>();
        gameObject.GetComponent <MeshFilter>().hideFlags   = HideFlags.NotEditable;
        gameObject.GetComponent <MeshCollider>().hideFlags = HideFlags.NotEditable;
        gameObject.GetComponent <MeshRenderer>().hideFlags = HideFlags.NotEditable;

        GameObject extraMeshes = new GameObject("Extra Meshes");

        extraMeshes.transform.SetParent(transform, false);

        if (settings.FindProperty("hideNonEditableChildren").boolValue == true)
        {
            extraMeshes.hideFlags = HideFlags.HideInHierarchy;
        }
        else
        {
            extraMeshes.hideFlags = HideFlags.NotEditable;
        }

        if (roundaboutMode == true)
        {
            CreateMesh();
        }
    }
示例#4
0
    private void OnEnable()
    {
        roadSystem = (RoadSystem)target;

        if (roadSystem.settings == null)
        {
            roadSystem.settings = RoadCreatorSettings.GetSerializedSettings();
        }

        lastTool      = Tools.current;
        Tools.current = Tool.None;
    }
示例#5
0
    public void CreateMesh(bool fromRoad = false)
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        for (int i = 0; i < connections.Count; i++)
        {
            if (connections[i].road == null)
            {
                connections.RemoveAt(i);
            }
        }

        if (connections.Count < 2 && roundaboutMode == false)
        {
            RemoveIntersection();
        }
        else
        {
            CheckMaterialsAndPrefabs();

            if (resetCurvePointsOnUpdate == true)
            {
                ResetCurvePointPositions();
            }

            if (roundaboutMode == true)
            {
                Roundabout.GenerateRoundabout(this);
            }
            else
            {
                if (outerExtraMeshesAsRoads == true)
                {
                    ResetExtraMeshes();
                    CreateExtraMeshesFromRoads();
                }

                GenerateMesh();
            }
        }

        if (fromRoad == false)
        {
            for (int i = 0; i < connections.Count; i++)
            {
                RoadCreator roadCreator = connections[i].road.transform.parent.parent.parent.parent.GetComponent <RoadCreator>();
                roadCreator.CreateMesh(true);
            }
        }
    }
示例#6
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;
        }
    }
示例#7
0
    private void CheckMaterialsAndPrefabs()
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        if (baseRoadMaterial == null)
        {
            baseRoadMaterial = (Material)settings.FindProperty("defaultBaseMaterial").objectReferenceValue;
        }

        if (bridgeSettings.bridgeMaterials == null || bridgeSettings.bridgeMaterials.Length == 0 || bridgeSettings.bridgeMaterials[0] == null)
        {
            Material[] materials = new Material[settings.FindProperty("defaultSimpleBridgeMaterials").arraySize];
            for (int i = 0; i < settings.FindProperty("defaultSimpleBridgeMaterials").arraySize; i++)
            {
                materials[i] = (Material)settings.FindProperty("defaultSimpleBridgeMaterials").GetArrayElementAtIndex(i).objectReferenceValue;
            }

            bridgeSettings.bridgeMaterials = materials;
        }

        if (pillarPrefab == null || pillarPrefab.GetComponent <MeshFilter>() == null)
        {
            pillarPrefab = (GameObject)settings.FindProperty("defaultPillarPrefab").objectReferenceValue;
        }

        if (bridgeSettings.bridgeMesh == null || bridgeSettings.bridgeMesh.GetComponent <MeshFilter>() == null)
        {
            bridgeSettings.bridgeMesh = (GameObject)settings.FindProperty("defaultCustomBridgePrefab").objectReferenceValue;
        }

        for (int i = 0; i < extraMeshes.Count; i++)
        {
            if (extraMeshes[i].baseMaterial == null)
            {
                extraMeshes[i].baseMaterial = (Material)settings.FindProperty("defaultBaseMaterial").objectReferenceValue;
            }
        }

        for (int i = 0; i < extraMeshes.Count; i++)
        {
            if (extraMeshes[i].overlayMaterial == null)
            {
                extraMeshes[i].overlayMaterial = (Material)settings.FindProperty("defaultExtraMeshOverlayMaterial").objectReferenceValue;
            }
        }
    }
示例#8
0
    public static RoadCreatorSettings GetOrCreateSettings()
    {
        RoadCreatorSettings settings = AssetDatabase.LoadAssetAtPath <RoadCreatorSettings>("Assets/Editor/RoadCreatorSettings.asset");

        if (settings == null)
        {
            if (Directory.Exists("Assets/Editor") == false)
            {
                Directory.CreateDirectory("Assets/Editor");
            }

            settings = ScriptableObject.CreateInstance <RoadCreatorSettings>();
            AssetDatabase.CreateAsset(settings, "Assets/Editor/RoadCreatorSettings.asset");
            AssetDatabase.SaveAssets();
        }

        return(settings);
    }
示例#9
0
    public void OnEnable()
    {
        if (intersection == null)
        {
            intersection = (Intersection)target;
        }

        if (intersection.settings == null)
        {
            intersection.settings = RoadCreatorSettings.GetSerializedSettings();
        }

        lastTool      = Tools.current;
        Tools.current = Tool.None;

        intersection.FixConnectionReferences();
        intersection.CreateCurvePoints();
    }
示例#10
0
    public void CreateMesh(bool fromRoad = false)
    {
        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        for (int i = 0; i < connections.Count; i++)
        {
            if (connections[i].road == null)
            {
                connections.RemoveAt(i);
            }
        }

        if (connections.Count < 2 && roundaboutMode == false)
        {
            RemoveIntersection();
        }
        else
        {
            CheckMaterialsAndPrefabs();

            if (roundaboutMode == true)
            {
                Roundabout.GenerateRoundabout(this);
            }
            else
            {
                GenerateNormalMesh();
            }
        }

        if (fromRoad == false)
        {
            for (int i = 0; i < connections.Count; i++)
            {
                connections[i].road.transform.parent.parent.parent.parent.GetComponent <RoadCreator>().CreateMesh(true);
            }
        }
    }
示例#11
0
    private void OnEnable()
    {
        for (int i = 0; i < targets.Length; i++)
        {
            RoadSegment roadSegment = (RoadSegment)targets[i];
            if (roadSegment.settings == null)
            {
                roadSegment.settings = RoadCreatorSettings.GetSerializedSettings();
            }

            if (roadSegment.transform.parent != null)
            {
                if (roadSegment.transform.parent.parent.GetComponent <RoadCreator>().startIntersection != null)
                {
                    roadSegment.transform.parent.parent.GetComponent <RoadCreator>().startIntersection.FixConnectionReferences();
                }

                if (roadSegment.transform.parent.parent.GetComponent <RoadCreator>().endIntersection != null)
                {
                    roadSegment.transform.parent.parent.GetComponent <RoadCreator>().endIntersection.FixConnectionReferences();
                }
            }
        }
    }
示例#12
0
    public static SettingsProvider CreateSettingsProvider()
    {
        SettingsProvider settingsProvider = new SettingsProvider("Project/RoadCreator", SettingsScope.Project)
        {
            label = "Road Creator",

            guiHandler = (searchContext) =>
            {
                SerializedObject settings = RoadCreatorSettings.GetSerializedSettings();

                EditorGUI.BeginChangeCheck();
                settings.FindProperty("pointSize").floatValue = Mathf.Max(0.1f, EditorGUILayout.FloatField("Point Size", settings.FindProperty("pointSize").floatValue));
                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    Transform[] objects = GameObject.FindObjectsOfType <Transform>();

                    for (int i = 0; i < objects.Length; i++)
                    {
                        if (objects[i].name.Contains("Connection Point") || objects[i].name == "Start Point" || objects[i].name == "Control Point" || objects[i].name == "End Point")
                        {
                            objects[i].GetComponent <BoxCollider>().size = new Vector3(settings.FindProperty("pointSize").floatValue, settings.FindProperty("pointSize").floatValue, settings.FindProperty("pointSize").floatValue);
                        }
                    }

                    UpdateSettings();
                }

                EditorGUI.BeginChangeCheck();
                settings.FindProperty("resolution").floatValue = Mathf.Clamp(EditorGUILayout.FloatField("Resolution", settings.FindProperty("resolution").floatValue), 0.01f, 2f);

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();

                    RoadCreator[] roads = GameObject.FindObjectsOfType <RoadCreator>();
                    for (int i = 0; i < roads.Length; i++)
                    {
                        roads[i].CreateMesh();
                    }

                    Intersection[] intersections = GameObject.FindObjectsOfType <Intersection>();
                    for (int i = 0; i < intersections.Length; i++)
                    {
                        intersections[i].CreateMesh();
                    }
                }

                EditorGUI.BeginChangeCheck();
                settings.FindProperty("hideNonEditableChildren").boolValue = EditorGUILayout.Toggle("Hide Non-editable Children", settings.FindProperty("hideNonEditableChildren").boolValue);

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();
                }

                EditorGUI.BeginChangeCheck();
                settings.FindProperty("roundaboutConnectionIndexOffset").intValue = Mathf.Clamp(EditorGUILayout.IntField("Roundabout Connection Index Offset", settings.FindProperty("roundaboutConnectionIndexOffset").intValue), 0, 10);

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();

                    Intersection[] intersections = GameObject.FindObjectsOfType <Intersection>();
                    for (int i = 0; i < intersections.Length; i++)
                    {
                        if (intersections[i].roundaboutMode == true)
                        {
                            intersections[i].CreateMesh();
                        }
                    }
                }

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(settings.FindProperty("pointShape"));

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();
                }

                GUIStyle guiStyle = new GUIStyle();
                guiStyle.fontStyle = FontStyle.Bold;

                EditorGUI.BeginChangeCheck();
                GUILayout.Space(20);
                GUILayout.Label("Road Guidelines", guiStyle);
                settings.FindProperty("roadGuidelinesLength").floatValue       = Mathf.Clamp(EditorGUILayout.FloatField("Road Guidelines Length (each side)", settings.FindProperty("roadGuidelinesLength").floatValue), 0, 15);
                settings.FindProperty("roadGuidelinesDistance").floatValue     = Mathf.Clamp(EditorGUILayout.FloatField("Road Guidelines Display Distance", settings.FindProperty("roadGuidelinesDistance").floatValue), 1, 50);
                settings.FindProperty("roadGuidelinesSnapDistance").floatValue = Mathf.Clamp(EditorGUILayout.FloatField("Road Guidelines Snap Distance", settings.FindProperty("roadGuidelinesSnapDistance").floatValue), 0.1f, 5);

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();
                    RoadCreatorSettings.UpdateRoadGuidelines();
                }

                EditorGUI.BeginChangeCheck();
                GUILayout.Space(20);
                GUILayout.Label("Defaults", guiStyle);
                settings.FindProperty("defaultLanes").intValue = Mathf.Clamp(EditorGUILayout.IntField("Default Lanes", settings.FindProperty("defaultLanes").intValue), 0, 10);
                settings.FindProperty("defaultBaseMaterial").objectReferenceValue                         = (Material)EditorGUILayout.ObjectField("Default Base Material", settings.FindProperty("defaultBaseMaterial").objectReferenceValue, typeof(Material), false);
                settings.FindProperty("defaultRoadOverlayMaterial").objectReferenceValue                  = (Material)EditorGUILayout.ObjectField("Default Road Overlay Material", settings.FindProperty("defaultRoadOverlayMaterial").objectReferenceValue, typeof(Material), false);
                settings.FindProperty("defaultExtraMeshOverlayMaterial").objectReferenceValue             = (Material)EditorGUILayout.ObjectField("Default Extra Mesh Overlay Material", settings.FindProperty("defaultExtraMeshOverlayMaterial").objectReferenceValue, typeof(Material), false);
                settings.FindProperty("defaultIntersectionOverlayMaterial").objectReferenceValue          = (Material)EditorGUILayout.ObjectField("Default Intersection Overlay Material", settings.FindProperty("defaultIntersectionOverlayMaterial").objectReferenceValue, typeof(Material), false);
                settings.FindProperty("defaultRoundaboutConnectionSectionsMaterial").objectReferenceValue = (Material)EditorGUILayout.ObjectField("Default Roundabout Connection Sections Material", settings.FindProperty("defaultRoundaboutConnectionSectionsMaterial").objectReferenceValue, typeof(Material), false);
                EditorGUILayout.PropertyField(settings.FindProperty("defaultSimpleBridgeMaterials"), true);
                settings.FindProperty("defaultPillarPrefab").objectReferenceValue          = (GameObject)EditorGUILayout.ObjectField("Default Pillar Prefab", settings.FindProperty("defaultPillarPrefab").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("defaultBridgePillarPrefab").objectReferenceValue    = (GameObject)EditorGUILayout.ObjectField("Default Bridge Pillar Prefab", settings.FindProperty("defaultBridgePillarPrefab").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("defaultCustomBridgePrefab").objectReferenceValue    = (GameObject)EditorGUILayout.ObjectField("Default Custom Bridge Prefab", settings.FindProperty("defaultCustomBridgePrefab").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue      = (GameObject)EditorGUILayout.ObjectField("Default Prefab Line Prefab", settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("defaultPrefabLineStartPrefab").objectReferenceValue = (GameObject)EditorGUILayout.ObjectField("Default Prefab Line Start Prefab", settings.FindProperty("defaultPrefabLineStartPrefab").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("defaultPrefabLineEndPrefab").objectReferenceValue   = (GameObject)EditorGUILayout.ObjectField("Default Prefab Line End Prefab", settings.FindProperty("defaultPrefabLineEndPrefab").objectReferenceValue, typeof(GameObject), false);

                if (GUILayout.Button("Reset Default Values"))
                {
                    settings.FindProperty("defaultLanes").intValue = 2;
                    settings.FindProperty("defaultBaseMaterial").objectReferenceValue                         = null;
                    settings.FindProperty("defaultRoadOverlayMaterial").objectReferenceValue                  = null;
                    settings.FindProperty("defaultExtraMeshOverlayMaterial").objectReferenceValue             = null;
                    settings.FindProperty("defaultIntersectionOverlayMaterial").objectReferenceValue          = null;
                    settings.FindProperty("defaultRoundaboutConnectionSectionsMaterial").objectReferenceValue = null;
                    settings.FindProperty("defaultSimpleBridgeMaterials").ClearArray();
                    settings.FindProperty("defaultPillarPrefab").objectReferenceValue          = null;
                    settings.FindProperty("defaultBridgePillarPrefab").objectReferenceValue    = null;
                    settings.FindProperty("defaultCustomBridgePrefab").objectReferenceValue    = null;
                    settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue      = null;
                    settings.FindProperty("defaultPrefabLineStartPrefab").objectReferenceValue = null;
                    settings.FindProperty("defaultPrefabLineEndPrefab").objectReferenceValue   = null;
                }

                GUILayout.Space(20);
                GUILayout.Label("Turn Markings", guiStyle);
                settings.FindProperty("leftTurnMarking").objectReferenceValue             = (GameObject)EditorGUILayout.ObjectField("Left Turn Marking", settings.FindProperty("leftTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("forwardTurnMarking").objectReferenceValue          = (GameObject)EditorGUILayout.ObjectField("Forward Turn Marking", settings.FindProperty("forwardTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("rightTurnMarking").objectReferenceValue            = (GameObject)EditorGUILayout.ObjectField("Right Turn Marking", settings.FindProperty("rightTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("leftForwardTurnMarking").objectReferenceValue      = (GameObject)EditorGUILayout.ObjectField("Left And Forward Turn Marking", settings.FindProperty("leftForwardTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("rightForwardTurnMarking").objectReferenceValue     = (GameObject)EditorGUILayout.ObjectField("Right And Forward Turn Marking", settings.FindProperty("rightForwardTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("leftRightTurnMarking").objectReferenceValue        = (GameObject)EditorGUILayout.ObjectField("Left And Right Turn Marking", settings.FindProperty("leftRightTurnMarking").objectReferenceValue, typeof(GameObject), false);
                settings.FindProperty("leftRightForwardTurnMarking").objectReferenceValue = (GameObject)EditorGUILayout.ObjectField("Left, Right And Forward Turn Marking", settings.FindProperty("leftRightForwardTurnMarking").objectReferenceValue, typeof(GameObject), false);

                if (GUILayout.Button("Reset Turn Markings"))
                {
                    settings.FindProperty("leftTurnMarking").objectReferenceValue             = null;
                    settings.FindProperty("forwardTurnMarking").objectReferenceValue          = null;
                    settings.FindProperty("rightTurnMarking").objectReferenceValue            = null;
                    settings.FindProperty("leftForwardTurnMarking").objectReferenceValue      = null;
                    settings.FindProperty("rightForwardTurnMarking").objectReferenceValue     = null;
                    settings.FindProperty("leftRightTurnMarking").objectReferenceValue        = null;
                    settings.FindProperty("leftRightForwardTurnMarking").objectReferenceValue = null;
                }

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    RoadCreatorSettings.GetOrCreateSettings().CheckDefaults();
                    UpdateSettings();
                }

                EditorGUI.BeginChangeCheck();
                GUILayout.Space(20);
                GUILayout.Label("Colours", guiStyle);
                settings.FindProperty("pointColour").colorValue                 = EditorGUILayout.ColorField("Point Colour", settings.FindProperty("pointColour").colorValue);
                settings.FindProperty("controlPointColour").colorValue          = EditorGUILayout.ColorField("Control Point Colour", settings.FindProperty("controlPointColour").colorValue);
                settings.FindProperty("intersectionColour").colorValue          = EditorGUILayout.ColorField("Intersection Point Colour", settings.FindProperty("intersectionColour").colorValue);
                settings.FindProperty("cursorColour").colorValue                = EditorGUILayout.ColorField("Cursor Colour", settings.FindProperty("cursorColour").colorValue);
                settings.FindProperty("roadGuidelinesColour").colorValue        = EditorGUILayout.ColorField("Road Guidelines Colour", settings.FindProperty("roadGuidelinesColour").colorValue);
                settings.FindProperty("roadControlGuidelinesColour").colorValue = EditorGUILayout.ColorField("Road Control Guidelines Colour", settings.FindProperty("roadControlGuidelinesColour").colorValue);

                if (GUILayout.Button("Reset Colours"))
                {
                    Color color = Color.red;
                    color.a = 0.75f;
                    settings.FindProperty("pointColour").colorValue = color;

                    color   = Color.yellow;
                    color.a = 0.75f;
                    settings.FindProperty("controlPointColour").colorValue = color;

                    color   = Color.green;
                    color.a = 0.75f;
                    settings.FindProperty("intersectionColour").colorValue = color;

                    color   = Color.blue;
                    color.a = 0.75f;
                    settings.FindProperty("cursorColour").colorValue = color;

                    settings.FindProperty("roadGuidelinesColour").colorValue        = Misc.lightGreen;
                    settings.FindProperty("roadControlGuidelinesColour").colorValue = Misc.darkGreen;
                }

                if (EditorGUI.EndChangeCheck() == true)
                {
                    settings.ApplyModifiedPropertiesWithoutUndo();
                    UpdateSettings();
                }
            }
        };

        return(settingsProvider);
    }
示例#13
0
    public void ShowCreationButtons(bool passiveControl = true)
    {
        if (passiveControl == true)
        {
            HandleUtility.nearestControl = GUIUtility.GetControlID(FocusType.Passive);
        }

        if (settings == null)
        {
            settings = RoadCreatorSettings.GetSerializedSettings();
        }

        if (largeBoldText == null)
        {
            largeBoldText           = new GUIStyle();
            largeBoldText.fontStyle = FontStyle.Bold;
            largeBoldText.fontSize  = 15;
        }

        if (createRoad == null)
        {
            createRoad         = Resources.Load("Textures/Ui/createroad") as Texture;
            createRoundabout   = Resources.Load("Textures/Ui/createroundabout") as Texture;
            createPrefabLine   = Resources.Load("Textures/Ui/createprefabline") as Texture;
            createTrafficLight = Resources.Load("Textures/Ui/createtrafficlight") as Texture;

            straightRoad = Resources.Load("Textures/Ui/straightroad") as Texture;
            curvedRoad   = Resources.Load("Textures/Ui/curvedroad") as Texture;

            roadGuidelinesOn  = Resources.Load("Textures/Ui/roadguidelineson") as Texture;
            roadGuidelinesOff = Resources.Load("Textures/Ui/roadguidelinesoff") as Texture;
        }

        Rect windowRect = new Rect(SceneView.lastActiveSceneView.position.width - 170, SceneView.lastActiveSceneView.position.height - 85, 160, 75);

        windowRect = GUILayout.Window(0, windowRect, DrawWindow, "", (Resources.Load("Textures/Ui/Object Creator Gui Skin") as GUISkin).window);

        // Detect click
        if (ClickedButton((int)(SceneView.lastActiveSceneView.position.width - 80), (int)(SceneView.lastActiveSceneView.position.height - 95)))
        {
            if (settings.FindProperty("roadCurved").boolValue == true)
            {
                settings.FindProperty("roadCurved").boolValue = false;
            }
            else
            {
                settings.FindProperty("roadCurved").boolValue = true;
            }

            settings.ApplyModifiedPropertiesWithoutUndo();
            RoadCreatorProjectSettings.UpdateSettings();
        }

        if (ClickedButton((int)(SceneView.lastActiveSceneView.position.width - 45), (int)(SceneView.lastActiveSceneView.position.height - 95)))
        {
            if (settings.FindProperty("roadGuidelinesLength").floatValue > 0)
            {
                settings.FindProperty("oldRoadGuidelinesLength").floatValue = settings.FindProperty("roadGuidelinesLength").floatValue;
                settings.FindProperty("roadGuidelinesLength").floatValue    = 0;
            }
            else
            {
                settings.FindProperty("roadGuidelinesLength").floatValue = settings.FindProperty("oldRoadGuidelinesLength").floatValue;
            }

            settings.ApplyModifiedPropertiesWithoutUndo();
            RoadCreatorSettings.UpdateRoadGuidelines();
        }

        if (ClickedButton(0) == true)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent <RoadCreator>();
            gameObject.name = "Road";
            gameObject.transform.SetParent(transform);
            gameObject.GetComponent <RoadCreator>().startLanes = settings.FindProperty("defaultLanes").intValue;
            gameObject.GetComponent <RoadCreator>().endLanes   = settings.FindProperty("defaultLanes").intValue;
            Selection.activeGameObject = gameObject;
            Undo.RegisterCreatedObjectUndo(gameObject, "Create Road");
        }
        else if (ClickedButton(1) == true)
        {
            GameObject gameObject = new GameObject();
            gameObject.layer = LayerMask.NameToLayer("Intersection");
            gameObject.AddComponent <Intersection>();
            gameObject.GetComponent <Intersection>().roundaboutMode = true;
            gameObject.GetComponent <Intersection>().Setup();
            gameObject.transform.hideFlags = HideFlags.None;
            gameObject.GetComponent <Intersection>().generateBridge            = false;
            gameObject.GetComponent <Intersection>().placePillars              = false;
            gameObject.GetComponent <Intersection>().overlayMaterial           = (Material)settings.FindProperty("defaultRoadOverlayMaterial").objectReferenceValue;
            gameObject.GetComponent <Intersection>().connectionOverlayMaterial = (Material)settings.FindProperty("defaultIntersectionOverlayMaterial").objectReferenceValue;
            gameObject.GetComponent <Intersection>().placePillars              = true;
            gameObject.GetComponent <Intersection>().CreateMesh();

            gameObject.name = "Roundabout";
            gameObject.transform.SetParent(transform);
            SetPosition(gameObject);
            gameObject.transform.localRotation = Quaternion.identity;

            Selection.activeGameObject = gameObject;
            Undo.RegisterCreatedObjectUndo(gameObject, "Create Roundabout");
        }
        else if (ClickedButton(2) == true)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent <PrefabLineCreator>();
            gameObject.name = "Prefab Line";
            gameObject.transform.SetParent(transform);
            Selection.activeGameObject = gameObject;
            Undo.RegisterCreatedObjectUndo(gameObject, "Create Prefab Line");
        }
        else if (ClickedButton(3) == true)
        {
            GameObject gameObject = Instantiate(Resources.Load("Prefabs/Traffic Light") as GameObject);
            gameObject.name = "Traffic Light";
            gameObject.transform.SetParent(transform);
            Selection.activeGameObject = gameObject;
            SetPosition(gameObject);
            Undo.RegisterCreatedObjectUndo(gameObject, "Create Traffic Light");
        }
    }
示例#14
0
    private void OnSceneGUI()
    {
        Point             point       = (Point)target;
        RoadCreator       roadCreator = null;
        PrefabLineCreator prefabLine  = null;

        if (point.roadPoint == true)
        {
            roadCreator = point.transform.parent.parent.parent.parent.GetComponent <RoadCreator>();

            if (roadCreator.settings == null)
            {
                roadCreator.settings = RoadCreatorSettings.GetSerializedSettings();
            }
        }
        else
        {
            prefabLine = point.transform.parent.parent.GetComponent <PrefabLineCreator>();

            if (prefabLine.settings == null)
            {
                prefabLine.settings = RoadCreatorSettings.GetSerializedSettings();
            }
        }

        if (point.transform.hasChanged == true)
        {
            point.transform.rotation   = Quaternion.identity;
            point.transform.localScale = Vector3.one;

            if (point.roadPoint == true)
            {
                if (point.name == "Control Point")
                {
                    point.transform.parent.parent.GetComponent <RoadSegment>().curved = true;
                }
                else
                {
                    if (point.transform.parent.parent.GetComponent <RoadSegment>().curved == false)
                    {
                        point.transform.parent.GetChild(1).position = Misc.GetCenter(point.transform.parent.GetChild(0).position, point.transform.parent.GetChild(2).position);
                    }

                    if (point.name == "Start Point" && point.transform.parent.parent.GetSiblingIndex() > 0)
                    {
                        point.transform.parent.parent.parent.GetChild(point.transform.parent.parent.GetSiblingIndex() - 1).GetChild(0).GetChild(2).position = point.transform.position;
                    }
                    else if (point.name == "End Point" && point.transform.parent.parent.GetSiblingIndex() < point.transform.parent.parent.parent.childCount - 1)
                    {
                        point.transform.parent.parent.parent.GetChild(point.transform.parent.parent.GetSiblingIndex() + 1).GetChild(0).GetChild(0).position = point.transform.position;
                    }
                }

                roadCreator.CreateMesh();
            }
            else if (prefabLine != null)
            {
                prefabLine.PlacePrefabs();
            }

            point.transform.hasChanged = false;
        }

        // Draw points
        if (point.roadPoint == true)
        {
            if (point.name == "Control Point")
            {
                Handles.color = roadCreator.settings.FindProperty("controlPointColour").colorValue;
            }
            else
            {
                Handles.color = roadCreator.settings.FindProperty("pointColour").colorValue;
            }

            Misc.DrawPoint((RoadCreatorSettings.PointShape)roadCreator.settings.FindProperty("pointShape").intValue, point.transform.position, roadCreator.settings.FindProperty("pointSize").floatValue);
        }
        else
        {
            if (point.name == "Control Point")
            {
                Handles.color = prefabLine.settings.FindProperty("controlPointColour").colorValue;
            }
            else
            {
                Handles.color = prefabLine.settings.FindProperty("pointColour").colorValue;
            }

            Misc.DrawPoint((RoadCreatorSettings.PointShape)prefabLine.settings.FindProperty("pointShape").intValue, point.transform.position, prefabLine.settings.FindProperty("pointSize").floatValue);
        }
    }
示例#15
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);
            }
        }
    }
示例#16
0
    private void OnSceneGUI()
    {
        Point             point       = (Point)target;
        RoadCreator       roadCreator = null;
        PrefabLineCreator prefabLine  = null;

        if (point.roadPoint == true)
        {
            roadCreator = point.transform.parent.parent.parent.parent.GetComponent <RoadCreator>();

            if (roadCreator.settings == null)
            {
                roadCreator.settings = RoadCreatorSettings.GetSerializedSettings();
            }
        }
        else
        {
            prefabLine = point.transform.parent.parent.GetComponent <PrefabLineCreator>();

            if (prefabLine.settings == null)
            {
                prefabLine.settings = RoadCreatorSettings.GetSerializedSettings();
            }
        }

        if (point.transform.hasChanged == true)
        {
            if (point.roadPoint == true)
            {
                if (roadCreator != null)
                {
                    roadCreator.CreateMesh();
                }
            }
            else if (prefabLine != null)
            {
                prefabLine.PlacePrefabs();
            }

            point.transform.hasChanged = false;
        }

        // Draw points
        if (point.roadPoint == true)
        {
            if (point.name == "Control Point")
            {
                Handles.color = roadCreator.settings.FindProperty("controlPointColour").colorValue;
            }
            else
            {
                Handles.color = roadCreator.settings.FindProperty("pointColour").colorValue;
            }

            Handles.CylinderHandleCap(0, point.transform.position, Quaternion.Euler(90, 0, 0), roadCreator.settings.FindProperty("pointSize").floatValue, EventType.Repaint);
        }
        else
        {
            if (point.name == "Control Point")
            {
                Handles.color = prefabLine.settings.FindProperty("controlPointColour").colorValue;
            }
            else
            {
                Handles.color = prefabLine.settings.FindProperty("pointColour").colorValue;
            }

            Handles.CylinderHandleCap(0, point.transform.position, Quaternion.Euler(90, 0, 0), prefabLine.settings.FindProperty("pointSize").floatValue, EventType.Repaint);
        }
    }