Beispiel #1
0
        /// <summary>
        /// Initialize the Street
        /// </summary>
        /// <param name="_splinePos">The 4 Locations for the Spline (Start, Tangent 1, Tangent 2, End)</param>
        /// <param name="_startConnection">The Start Connection of the Street Component</param>
        /// <param name="_endConnection">The End Connection of the Street</param>
        /// <param name="_segmentAmount">The Amount of Segments the Street needs</param>
        /// <param name="_needID">Need the Street an ID?</param>
        /// <param name="_updateSpline">Should the Spline be Updated?</param>
        /// <returns>Returns the new Street</returns>
        public Street Init(Vector3[] _splinePos, Connection _startConnection, Connection _endConnection, int _segmentAmount = 10, bool _needID = true, bool _updateSpline = false)
        {
            ID = 0;
            if (_needID)
            {
                base.Init(_needID);
            }
            m_Spline = new Spline(_splinePos[0], _splinePos[1], _splinePos[2], _splinePos[3], _segmentAmount, this);

            m_MeshFilter = GetComponent <MeshFilter>();
            if (m_MeshFilter == null)
            {
                Debug.LogError("No MeshFilter found in: " + ID);
            }
            m_MeshRenderer = GetComponent <MeshRenderer>();
            if (m_MeshRenderer == null)
            {
                Debug.LogError("No MeshRenderer found in: " + ID);
            }

            m_Shape = new StreetShape();
            m_Spline.UpdateOPs();
            MeshGenerator.Extrude(this);
            updateSpline = _updateSpline;

            //Create Start and End Connections
            SetStartConnection(new Connection(null, this, true));
            m_EndConnection = new Connection(null, this, false);

            //If its an finished Street Combine the Connections from the Preview Street
            if (_needID)
            {
                if (_startConnection?.m_OtherConnection != null)                                  //if the preview Street had a connection to something
                {
                    Connection.Combine(GetStartConnection(), _startConnection.m_OtherConnection); //combine the new Street with the preview other connection
                }
                else
                {
                    StreetComponentManager.CreateDeadEnd(this, true); //If there is no Connections to Combine, Create a DeadEnd
                }
                if (_endConnection?.m_OtherConnection != null)
                {
                    Connection.Combine(m_EndConnection, _endConnection.m_OtherConnection);
                }
                else
                {
                    StreetComponentManager.CreateDeadEnd(this, false);
                }
            }

            CreateSegments();

            if (_needID) //if its isnt a Collision Street
            {
                StartCoroutine(PlaceBuildings());
            }

            return(this);
        }
Beispiel #2
0
 public void CreateDeadEnds()
 {
     for (int i = 0; i < m_Connections.Length; i++)
     {
         if (m_Connections[i].m_OtherConnection == null)
         {
             StreetComponentManager.CreateDeadEnd(this, i);
         }
     }
 }