예제 #1
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);
                }
            }
        }
    }
예제 #2
0
    public void CreateRoadMesh(Vector3[] points, Vector3[] nextSegmentPoints, Vector3 previousPoint, Vector3[] previousVertices, float heightOffset, Transform segment, Transform previousSegment, int smoothnessAmount, RoadCreator roadCreator)
    {
        if (baseRoadMaterial == null)
        {
            baseRoadMaterial = Resources.Load("Materials/Low Poly/Roads/2 Lane Roads/2L Road") as Material;
        }

        if (bridgeMaterials == null || bridgeMaterials.Length == 0 || bridgeMaterials[0] == null)
        {
            bridgeMaterials = new Material[] { Resources.Load("Materials/Low Poly/Concrete") as Material };
        }

        if (pillarPrefab == null || pillarPrefab.GetComponent <MeshFilter>() == null)
        {
            pillarPrefab = Resources.Load("Prefabs/Low Poly/Bridges/Oval Bridge Pillar") as GameObject;
        }

        for (int i = 0; i < extraMeshOpen.Count; i++)
        {
            if (extraMeshMaterial[i] == null)
            {
                extraMeshMaterial[i] = Resources.Load("Materials/Low Poly/Asphalt") as Material;
            }
        }

        if (segment.GetSiblingIndex() == 0)
        {
            SetGuidelines(points, nextSegmentPoints, true);
        }
        else
        {
            SetGuidelines(points, nextSegmentPoints, false);
        }

        GenerateMesh(points, nextSegmentPoints, previousPoint, previousVertices, heightOffset, segment, previousSegment, transform.GetChild(1).GetChild(0), "Road", baseRoadMaterial, overlayRoadMaterial, smoothnessAmount, roadCreator, roadPhysicsMaterial);

        for (int i = 0; i < extraMeshOpen.Count; i++)
        {
            float leftYOffset = extraMeshYOffset[i];
            float xOffset     = 0;
            float yOffset     = heightOffset;
            if (i > 0)
            {
                bool foundLast = false;
                for (int j = i - 1; j > -1; j -= 1)
                {
                    if (extraMeshLeft[j] == extraMeshLeft[i] && j != i)
                    {
                        if (foundLast == false)
                        {
                            leftYOffset = extraMeshYOffset[j];
                            foundLast   = true;
                        }

                        xOffset += extraMeshWidth[j];
                        yOffset += extraMeshYOffset[j];
                    }
                }
            }

            float currentHeight = heightOffset;
            for (int j = i - 1; j > -1; j -= 1)
            {
                if (extraMeshLeft[j] == extraMeshLeft[i] && j != i)
                {
                    currentHeight += extraMeshYOffset[j];
                }
            }

            GenerateMesh(points, nextSegmentPoints, previousPoint, previousVertices, heightOffset, segment, previousSegment, transform.GetChild(1).GetChild(i + 1), "Extra Mesh", extraMeshMaterial[i], null, smoothnessAmount, roadCreator, extraMeshPhysicMaterial[i], xOffset, extraMeshWidth[i], currentHeight + extraMeshYOffset[i], currentHeight, extraMeshLeft[i]);
        }

        if (transform.childCount == 3)
        {
            DestroyImmediate(transform.GetChild(2).gameObject);
        }

        if (bridgeGenerator == BridgeGenerator.simple)
        {
            float extraWidthLeft  = 0;
            float extraWidthRight = 0;

            for (int i = 0; i < extraMeshLeft.Count; i++)
            {
                if (extraMeshLeft[i] == true)
                {
                    extraWidthLeft += extraMeshWidth[i];
                }
                else
                {
                    extraWidthRight += extraMeshWidth[i];
                }
            }

            extraWidthLeft  += extraWidth;
            extraWidthRight += extraWidth;

            BridgeGeneration.GenerateSimpleBridge(points, nextSegmentPoints, previousPoint, this, extraWidthLeft, extraWidthRight, bridgeMaterials);
        }
    }