コード例 #1
0
        /// <summary>
        /// Create the steet layout
        /// </summary>
        public void CreateStreetLayout(int subDivide)
        {
            if (_startRoadId == null)
            {
                return;
            }

            if (_endRoadId == null)
            {
                return;
            }

            RoadCrossSection rA = _startRoadId;
            ICrossSection    crossSectionStart = _startCrossSection;

            if (crossSectionStart == null)
            {
                crossSectionStart = RoadConstructorHelper.CrossSectionDetails;
            }

            RoadCrossSection rB = _endRoadId;
            ICrossSection    crossSectionEnd = _endCrossSection;

            if (crossSectionEnd == null)
            {
                crossSectionEnd = RoadConstructorHelper.CrossSectionDetails;
            }

            IMaterialFrequency materialFrequency = _materialFrequency;

            if (materialFrequency == null)
            {
                materialFrequency = RoadConstructorHelper.MaterialFrequencySet;
            }

            Vector3 len      = rA.Middle - rB.Middle;
            float   mag      = len.magnitude;
            int     sections = (int)(mag / crossSectionStart.RoadWidthValue);

            RoadCrossSection[] array         = new RoadCrossSection[sections + 1];
            string[]           materialNames = new string[sections + 1];

            float   an    = rB.Angle;
            Vector3 start = rB.Middle;

            if (sections < 2)
            {
                Vector3 another = rB.Middle;
                another = rA.Middle;
                RoadCrossSection rn = new RoadCrossSection(another, an, crossSectionStart, materialFrequency);
                _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(rB, rn), RoadConstructorHelper.GetMainMaterial(materialFrequency), 0); // TODO SubDivide
                return;
            }

            Vector3 gap  = len / sections;
            float   mag2 = gap.magnitude;

            for (int i = 0; i < sections + 1; i++)
            {
                ICrossSection    crossSection = CrossSection.Lerp(crossSectionEnd, crossSectionStart, (mag2 * i) / mag);
                RoadCrossSection rn           = new RoadCrossSection(start, an, crossSection, materialFrequency);
                array[i] = rn;
                start   += gap;
            }

            RoadConstructorHelper.SetMaterialsArray(materialNames, materialFrequency);
            for (int i = 0; i < sections; i++)
            {
                _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(array[i], array[i + 1]), materialNames[i], subDivide);
            }
        }