Exemplo n.º 1
0
    private void OnEnable()
    {
        prefabCreator = (PrefabLineCreator)target;

        if (prefabCreator.globalSettings == null)
        {
            prefabCreator.globalSettings = GameObject.FindObjectOfType <GlobalSettings>();
        }

        if (prefabCreator.transform.childCount == 0 || prefabCreator.transform.GetChild(0).name != "Points")
        {
            GameObject points = new GameObject("Points");
            points.transform.SetParent(prefabCreator.transform);
            points.transform.SetAsFirstSibling();
        }

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

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

        Undo.undoRedoPerformed += UndoUpdate;
    }
Exemplo n.º 2
0
    public void CopyPrefabLine(PrefabLineCreator prefabLineToCopy)
    {
        prefab             = prefabLineToCopy.prefab;
        startPrefab        = prefabLineToCopy.startPrefab;
        endPrefab          = prefabLineToCopy.endPrefab;
        yModification      = prefabLineToCopy.yModification;
        terrainCheckHeight = prefabLineToCopy.terrainCheckHeight;

        xScale = prefabLineToCopy.xScale;
        yScale = prefabLineToCopy.yScale;
        zScale = prefabLineToCopy.zScale;

        bendObjects               = prefabLineToCopy.bendObjects;
        fillGap                   = prefabLineToCopy.fillGap;
        spacing                   = prefabLineToCopy.spacing;
        rotateAlongCurve          = prefabLineToCopy.rotateAlongCurve;
        rotationDirection         = prefabLineToCopy.rotationDirection;
        yRotationRandomization    = prefabLineToCopy.yRotationRandomization;
        pointCalculationDivisions = prefabLineToCopy.pointCalculationDivisions;

        bridgeMode      = prefabLineToCopy.bridgeMode;
        bridgeSettings  = prefabLineToCopy.bridgeSettings;
        startWidthLeft  = prefabLineToCopy.startWidthLeft;
        startWidthRight = prefabLineToCopy.startWidthRight;
        endWidthLeft    = prefabLineToCopy.endWidthLeft;
        endWidthRight   = prefabLineToCopy.endWidthRight;

        PlacePrefabs();
    }
Exemplo n.º 3
0
    private void OnEnable()
    {
        prefabCreator = (PrefabLineCreator)target;
        prefabCreator.Setup();

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

        Undo.undoRedoPerformed += prefabCreator.UndoUpdate;
    }
Exemplo n.º 4
0
    private void GenerateBridges(Vector3[] points, Vector3[] nextSegmentPoints, Vector3 previousPoint, Transform previousSegment)
    {
        if (generateSimpleBridge == true || generateCustomBridge == true)
        {
            float startExtraWidthLeft  = bridgeSettings.extraWidth;
            float endExtraWidthLeft    = bridgeSettings.extraWidth;
            float startExtraWidthRight = bridgeSettings.extraWidth;
            float endExtraWidthRight   = bridgeSettings.extraWidth;

            for (int i = 0; i < extraMeshes.Count; i++)
            {
                if (extraMeshes[i].left == true)
                {
                    startExtraWidthLeft += extraMeshes[i].startWidth;
                    endExtraWidthLeft   += extraMeshes[i].endWidth;
                }
                else
                {
                    startExtraWidthRight += extraMeshes[i].startWidth;
                    endExtraWidthRight   += extraMeshes[i].endWidth;
                }
            }

            PrefabLineCreator customBridge = null;

            if (generateSimpleBridge == true)
            {
                BridgeGeneration.GenerateSimpleBridge(points, nextSegmentPoints, previousPoint, this, previousSegment, startExtraWidthLeft, endExtraWidthLeft, startExtraWidthRight, endExtraWidthRight, bridgeSettings.bridgeMaterials, transform.GetChild(0).GetChild(0).transform.position, transform.GetChild(0).GetChild(1).transform.position, transform.GetChild(0).GetChild(2).transform.position);
            }

            if (generateCustomBridge == true)
            {
                customBridge = BridgeGeneration.GenerateCustomBridge(this, startExtraWidthLeft + startRoadWidth, startExtraWidthRight + startRoadWidth, endExtraWidthLeft + endRoadWidth, endExtraWidthRight + endRoadWidth);
            }

            if (placePillars == true)
            {
                if (generateSimpleBridge == true)
                {
                    BridgeGeneration.GeneratePillars(points, transform.GetChild(0).GetChild(0).transform.position, transform.GetChild(0).GetChild(1).transform.position, transform.GetChild(0).GetChild(2).transform.position, this, transform.Find("Bridge").gameObject, true, customBridge, startExtraWidthLeft, startExtraWidthRight, endExtraWidthLeft, endExtraWidthRight);
                }
                else if (generateCustomBridge == true)
                {
                    BridgeGeneration.GeneratePillars(points, transform.GetChild(0).GetChild(0).transform.position, transform.GetChild(0).GetChild(1).transform.position, transform.GetChild(0).GetChild(2).transform.position, this, transform.Find("Custom Bridge").gameObject, false, customBridge, startExtraWidthLeft, startExtraWidthRight, endExtraWidthLeft, endExtraWidthRight);
                }
            }
        }
    }
Exemplo n.º 5
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);
        }
    }
Exemplo n.º 6
0
    public static void GeneratePillars(Vector3[] points, Vector3 startPoint, Vector3 controlPoint, Vector3 endPoint, RoadSegment segment, GameObject bridge, bool simple, PrefabLineCreator customBridge, float startWidthLeft, float startWidthRight, float endWidthLeft, float endWidthRight)
    {
        float   currentDistance   = 0;
        Vector3 lastPosition      = startPoint;
        bool    placedFirstPillar = false;

        if (segment.adaptGapToCustomBridge == true && segment.generateCustomBridge == true)
        {
            PointPackage prefabPoints = customBridge.CalculatePoints();

            for (int i = 0; i < customBridge.transform.GetChild(1).childCount; i++)
            {
                Vector3 currentPosition = Misc.Lerp3CenterHeight(customBridge.transform.GetChild(0).GetChild(0).position, customBridge.transform.GetChild(0).GetChild(1).position, customBridge.transform.GetChild(0).GetChild(2).position, Misc.GetCenter(prefabPoints.startTimes[i], prefabPoints.endTimes[i]));
                // Correct position to extra meshes
                float difference = Mathf.Lerp(startWidthLeft, endWidthLeft, Misc.GetCenter(prefabPoints.startTimes[i], prefabPoints.endTimes[i])) - Mathf.Lerp(startWidthRight, endWidthRight, Misc.GetCenter(prefabPoints.startTimes[i], prefabPoints.endTimes[i]));
                currentPosition += difference * customBridge.transform.GetChild(1).GetChild(i).transform.forward / 2;
                float width = Mathf.Lerp(startWidthLeft + startWidthRight + segment.startRoadWidth * 2, endWidthLeft + endWidthRight + segment.endRoadWidth * 2, Misc.GetCenter(prefabPoints.startTimes[i], prefabPoints.endTimes[i]));
                CreatePillar(bridge.transform, segment.pillarPrefab, currentPosition - new Vector3(0, Mathf.Abs(segment.bridgeSettings.bridgeMesh.GetComponent <MeshFilter>().sharedMesh.bounds.min.y) * segment.bridgeSettings.yScale, 0), segment, -customBridge.transform.GetChild(1).GetChild(i).transform.right, simple, width);
            }
        }
        else
        {
            for (float t = 0; t <= 1; t += 0.01f)
            {
                Vector3 currentPosition = Misc.Lerp3CenterHeight(startPoint, controlPoint, endPoint, t);
                currentDistance = Vector3.Distance(lastPosition, currentPosition);
                Vector3 forward = (currentPosition - lastPosition).normalized;

                if (t == 0)
                {
                    forward = (Misc.Lerp3CenterHeight(startPoint, controlPoint, endPoint, 0.01f) - startPoint).normalized;
                }
                else if (t == 1)
                {
                    forward = (currentPosition - Misc.Lerp3CenterHeight(startPoint, controlPoint, endPoint, 0.99f)).normalized;
                }

                if (placedFirstPillar == false && currentDistance >= segment.pillarPlacementOffset)
                {
                    CreatePillar(bridge.transform, segment.pillarPrefab, currentPosition - new Vector3(0, segment.bridgeSettings.yOffsetFirstStep + segment.bridgeSettings.yOffsetSecondStep, 0), segment, forward, simple, 0);
                    lastPosition      = currentPosition;
                    placedFirstPillar = true;
                }
                else if (placedFirstPillar == true && currentDistance >= segment.pillarGap)
                {
                    CreatePillar(bridge.transform, segment.pillarPrefab, currentPosition - new Vector3(0, segment.bridgeSettings.yOffsetFirstStep + segment.bridgeSettings.yOffsetSecondStep, 0), segment, forward, simple, 0);
                    lastPosition = currentPosition;
                }
            }
        }
    }
Exemplo n.º 7
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);
        }
    }