Example #1
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);
        }
    }
Example #2
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);
        }
    }
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        prefabCreator.pointCalculationDivisions = Mathf.Clamp(EditorGUILayout.FloatField("Point Calculation Divisions", prefabCreator.pointCalculationDivisions), 1, 1000);
        prefabCreator.bendObjects = GUILayout.Toggle(prefabCreator.bendObjects, "Bend Objects");
        prefabCreator.fillGap     = GUILayout.Toggle(prefabCreator.fillGap, "Fill Gap");

        if (prefabCreator.fillGap == false && prefabCreator.bendObjects == false)
        {
            prefabCreator.spacing = Mathf.Max(0.1f, EditorGUILayout.FloatField("Spacing", prefabCreator.spacing));

            if (GUILayout.Button("Calculate Spacing (X)") == true)
            {
                if (prefabCreator.prefab != null)
                {
                    prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.x * 2 * prefabCreator.scale;
                }
            }

            if (GUILayout.Button("Calculate Spacing (Z)") == true)
            {
                if (prefabCreator.prefab != null)
                {
                    prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.z * 2 * prefabCreator.scale;
                }
            }
        }

        prefabCreator.yModification = (PrefabLineCreator.YModification)EditorGUILayout.EnumPopup("Vertex Y Modification", prefabCreator.yModification);

        if (prefabCreator.yModification == PrefabLineCreator.YModification.matchTerrain)
        {
            prefabCreator.terrainCheckHeight = Mathf.Max(0, EditorGUILayout.FloatField("Check Terrain Height", prefabCreator.terrainCheckHeight));
        }

        prefabCreator.prefab           = (GameObject)EditorGUILayout.ObjectField("Prefab", prefabCreator.prefab, typeof(GameObject), false);
        prefabCreator.scale            = Mathf.Clamp(EditorGUILayout.FloatField("Prefab Scale", prefabCreator.scale), 0.1f, 10);
        prefabCreator.rotateAlongCurve = EditorGUILayout.Toggle("Rotate Alongst Curve", prefabCreator.rotateAlongCurve);
        if (prefabCreator.rotateAlongCurve == true)
        {
            prefabCreator.rotationDirection = (PrefabLineCreator.RotationDirection)EditorGUILayout.EnumPopup("Rotation Direction", prefabCreator.rotationDirection);
        }

        if (EditorGUI.EndChangeCheck() == true)
        {
            if (prefabCreator.prefab == null)
            {
                prefabCreator.prefab = Resources.Load("Prefabs/Concrete Barrier") as GameObject;
            }
            else if (prefabCreator.prefab.GetComponent <MeshFilter>() == null)
            {
                prefabCreator.prefab = Resources.Load("Prefabs/Concrete Barrier") as GameObject;
                Debug.Log("Selected prefab must have a mesh filter attached. Prefab has been changed to the concrete barrier");
                return;
            }

            if (prefabCreator.fillGap == true || prefabCreator.bendObjects == true)
            {
                prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.x * 2 * prefabCreator.scale;
            }

            prefabCreator.PlacePrefabs();
        }

        if (prefabCreator.globalSettings.debug == true)
        {
            EditorGUILayout.Toggle("Is Follow Object", prefabCreator.isFollowObject);
        }

        if (prefabCreator.isFollowObject == false)
        {
            GUILayout.Label("");

            if (GUILayout.Button("Reset"))
            {
                for (int i = 1; i >= 0; i--)
                {
                    for (int j = prefabCreator.transform.GetChild(i).childCount - 1; j >= 0; j--)
                    {
                        Undo.DestroyObjectImmediate(prefabCreator.transform.GetChild(i).GetChild(j).gameObject);
                    }
                }
            }

            if (GUILayout.Button("Place Prefabs"))
            {
                prefabCreator.PlacePrefabs();
            }

            if (GUILayout.Button("Convert To Mesh"))
            {
                Misc.ConvertToMesh(prefabCreator.gameObject, "Prefab Line Mesh");
            }
        }
    }
Example #4
0
    public override void OnInspectorGUI()
    {
        if (prefabCreator.spacing == -1)
        {
            if (prefabCreator.prefab == null)
            {
                prefabCreator.prefab = (GameObject)prefabCreator.settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue;
            }

            prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.x * 2 * prefabCreator.xScale;
        }

        EditorGUI.BeginChangeCheck();
        prefabCreator.pointCalculationDivisions = Mathf.Clamp(EditorGUILayout.FloatField("Point Calculation Divisions", prefabCreator.pointCalculationDivisions), 1, 1000);
        prefabCreator.rotateAlongCurve          = EditorGUILayout.Toggle("Rotate Alongst Curve", prefabCreator.rotateAlongCurve);
        if (prefabCreator.rotateAlongCurve == true)
        {
            prefabCreator.rotationDirection = (PrefabLineCreator.RotationDirection)EditorGUILayout.EnumPopup("Rotation Direction", prefabCreator.rotationDirection);

            if (prefabCreator.fillGap == false)
            {
                prefabCreator.yRotationRandomization = Mathf.Clamp(EditorGUILayout.FloatField("Y Rotation Randomization", prefabCreator.yRotationRandomization), 0, 360);
            }
            else
            {
                prefabCreator.yRotationRandomization = 0;
            }

            prefabCreator.bendObjects = GUILayout.Toggle(prefabCreator.bendObjects, "Bend Objects");
        }
        else if (prefabCreator.bendObjects == true)
        {
            Debug.Log("Rotate alongst curve has to be true to be able to use bend objects");
            prefabCreator.bendObjects = false;
        }

        if (prefabCreator.rotateAlongCurve == true)
        {
            prefabCreator.fillGap = GUILayout.Toggle(prefabCreator.fillGap, "Fill Gap");
        }
        else if (prefabCreator.fillGap == true)
        {
            Debug.Log("Rotate alongst curve has to be true to be able to use fill gap");
            prefabCreator.fillGap = false;
        }

        if (prefabCreator.fillGap == false && prefabCreator.bendObjects == false)
        {
            prefabCreator.spacing = Mathf.Max(0.1f, EditorGUILayout.FloatField("Spacing", prefabCreator.spacing));

            if (GUILayout.Button("Calculate Spacing (X)") == true)
            {
                prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.x * 2 * prefabCreator.xScale;
            }

            if (GUILayout.Button("Calculate Spacing (Z)") == true)
            {
                if (prefabCreator.prefab != null)
                {
                    prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.z * 2 * prefabCreator.zScale;
                }
            }
        }

        prefabCreator.yModification = (PrefabLineCreator.YModification)EditorGUILayout.EnumPopup("Vertex Y Modification", prefabCreator.yModification);

        if (prefabCreator.yModification == PrefabLineCreator.YModification.matchTerrain)
        {
            prefabCreator.terrainCheckHeight = Mathf.Max(0, EditorGUILayout.FloatField("Check Terrain Height", prefabCreator.terrainCheckHeight));
        }

        GUIStyle guiStyle = new GUIStyle();

        guiStyle.fontStyle = FontStyle.Bold;

        GUILayout.Space(20);
        GUILayout.Label("Prefabs", guiStyle);
        prefabCreator.prefab      = (GameObject)EditorGUILayout.ObjectField("Prefab", prefabCreator.prefab, typeof(GameObject), false);
        prefabCreator.startPrefab = (GameObject)EditorGUILayout.ObjectField("Start Prefab", prefabCreator.startPrefab, typeof(GameObject), false);
        prefabCreator.endPrefab   = (GameObject)EditorGUILayout.ObjectField("End Prefab", prefabCreator.endPrefab, typeof(GameObject), false);

        GUILayout.Space(20);
        GUILayout.Label("Scaling", guiStyle);
        prefabCreator.xScale = Mathf.Clamp(EditorGUILayout.FloatField("Prefab X Scale", prefabCreator.xScale), 0.1f, 10);
        prefabCreator.yScale = Mathf.Clamp(EditorGUILayout.FloatField("Prefab Y Scale", prefabCreator.yScale), 0.1f, 10);
        prefabCreator.zScale = Mathf.Clamp(EditorGUILayout.FloatField("Prefab Z Scale", prefabCreator.zScale), 0.1f, 10);

        if (EditorGUI.EndChangeCheck() == true)
        {
            if (prefabCreator.prefab == null)
            {
                prefabCreator.prefab = (GameObject)prefabCreator.settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue;
            }
            else if (prefabCreator.prefab.GetComponent <MeshFilter>() == null)
            {
                prefabCreator.prefab = (GameObject)prefabCreator.settings.FindProperty("defaultPrefabLinePrefab").objectReferenceValue;
                Debug.Log("Selected prefab must have a mesh filter attached. Prefab has been changed to the concrete barrier");
                return;
            }

            if (prefabCreator.fillGap == true || prefabCreator.bendObjects == true)
            {
                prefabCreator.spacing = prefabCreator.prefab.GetComponent <MeshFilter>().sharedMesh.bounds.extents.x * 2 * prefabCreator.xScale;
            }

            prefabCreator.PlacePrefabs();
        }

        GUILayout.Space(20);

        if (GUILayout.Button("Reset"))
        {
            for (int i = 1; i >= 0; i--)
            {
                for (int j = prefabCreator.transform.GetChild(i).childCount - 1; j >= 0; j--)
                {
                    Undo.DestroyObjectImmediate(prefabCreator.transform.GetChild(i).GetChild(j).gameObject);
                }
            }
        }

        if (GUILayout.Button("Place Prefabs"))
        {
            prefabCreator.PlacePrefabs();
        }
    }