예제 #1
0
        /// <summary>
        /// Initialize the DeadEnd
        /// </summary>
        /// <param name="_comp">The Street the Dead End is connected to</param>
        /// <param name="_isStart">Is it the Start of the Street?</param>
        /// <param name="_op">The OrientedPoint of the DeadEnd</param>
        /// <returns>The new Dead End</returns>
        public DeadEnd Init(Street _comp, bool _isStart, OrientedPoint _op)
        {
            base.Init(false);
            ID      = -2;
            m_Shape = new DeadEndShape();
            SetStartConnection(new Connection(null, this, true));
            if (_isStart)
            {
                //Move the Start Point half the width of the Street | Street width is 2
                Vector3 start = _op.Position + (_op.Rotation * -Vector3.right) * 0.5f;
                //Move the Tangent 1 up above the start Point
                Vector3 tangent1 = start - _op.Rotation * Vector3.forward * 0.8f;
                //Move the End Point half the width of the Street | Street width is 2
                Vector3 end = _op.Position + (_op.Rotation * Vector3.right) * 0.5f;
                //Move the Tangent 2 up above the end Point
                Vector3 tangent2 = end - _op.Rotation * Vector3.forward * 0.8f;
                m_Spline = new Spline(
                    start, tangent1, tangent2, end, 10, this
                    );
                Connection.Combine(GetStartConnection(), _comp.GetStartConnection());
            }
            else
            {
                //Move the Start Point half the width of the Street | Street width is 2
                Vector3 start = _op.Position + (_op.Rotation * Vector3.right) * 0.5f;
                //Move the Tangent 1 up above the start Point
                Vector3 tangent1 = start + _op.Rotation * Vector3.forward * 0.8f;
                //Move the End Point half the width of the Street | Street width is 2
                Vector3 end = _op.Position + (_op.Rotation * -Vector3.right) * 0.5f;
                //Move the Tangent 2 up above the end Point
                Vector3 tangent2 = end + _op.Rotation * Vector3.forward * 0.8f;
                m_Spline = new Spline(
                    start, tangent1, tangent2, end, 10, this
                    );
                Connection.Combine(GetStartConnection(), _comp.m_EndConnection);
            }

            m_MeshFilter            = gameObject.AddComponent <MeshFilter>();
            m_MeshRenderer          = gameObject.AddComponent <MeshRenderer>();
            m_MeshRenderer.material = StreetComponentManager.Instance.DeadEndMat;
            transform.SetParent(_comp.transform);
            MeshGenerator.Extrude(this);
            return(this);
        }
        /// <summary>
        /// Create a finshed Street
        /// </summary>
        /// <param name="_street">The Preview Street</param>
        /// <returns>Return the new finished Street</returns>
        public static Street CreateStreet(Street _street)
        {
            CreateCollisionStreet(_street.m_Spline.StartPos, _street.m_Spline.Tangent1Pos, _street.m_Spline.Tangent2Pos, _street.m_Spline.EndPos, _street.GetStartConnection(), _street.m_EndConnection);
            Destroy(_street.GetCollisionStreet()?.gameObject);
            Street output = CreateStreet(_street.m_Spline.StartPos, _street.m_Spline.Tangent1Pos, _street.m_Spline.Tangent2Pos, _street.m_Spline.EndPos, _street.GetStartConnection(), _street.m_EndConnection);

            allStreets.Add(output);
            return(output);
        }