Ejemplo n.º 1
0
    void PositionTrafficSystemPiece( TrafficSystemPiece a_currentPiece, TrafficSystemPiece a_attachToPiece, bool a_incIndex = true, bool a_useEditOffset = false, bool a_useAnchorOffset = false )
    {
        if(!a_currentPiece)
            return;

        if(!a_attachToPiece)
            return;

        if(a_incIndex)
            m_roadAttachmentPointIndex++;

        if(m_roadAttachmentPointIndex == RoadAttachmentPoint.MAX)
            m_roadAttachmentPointIndex = RoadAttachmentPoint.NORTH;

        EditTrafficSystemPiece.transform.position = a_attachToPiece.transform.position;

        if(TrafficSystem.Instance.m_quickSpawn)
            EditTrafficSystemPiece.transform.rotation = a_attachToPiece.transform.rotation;

        Vector3 pos = a_attachToPiece.transform.position;

        if(a_currentPiece.m_renderer && a_attachToPiece.m_renderer)
        {
            EditTrafficSystemPiece.transform.position = a_attachToPiece.m_renderer.transform.position;
        //			EditTrafficSystemPiece.transform.rotation = a_attachToPiece.m_renderer.transform.rotation;
            pos = a_attachToPiece.m_renderer.transform.position;
        }

        float   roadPieceSize = m_roadPieceSize;

        switch(m_roadAttachmentPointIndex)
        {
        case RoadAttachmentPoint.EAST:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.z;

                float currentSize = a_currentPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.z;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.x = a_attachToPiece.m_renderer.transform.position.x + roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.SOUTH:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.x;

                float currentSize = a_currentPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.x;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.z = a_attachToPiece.m_renderer.transform.position.z - roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.WEST:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.z;

                float currentSize = a_currentPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.z;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.x = a_attachToPiece.m_renderer.transform.position.x - roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.NORTH:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.x;

                float currentSize = a_currentPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.x;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.z  = a_attachToPiece.m_renderer.transform.position.z + roadPieceSize;
        }
            break;
        }

        Vector3 posOffset = a_currentPiece.m_posOffset;
        if(a_useAnchorOffset)
            posOffset = a_attachToPiece.m_posOffset;

        Vector3 dir = a_attachToPiece.transform.position - pos;

        if(a_attachToPiece.m_renderer)
            dir = a_attachToPiece.m_renderer.transform.position - pos;

        dir = dir.normalized;

        if(a_useEditOffset || a_useAnchorOffset)
        {
        //			if(TrafficSystem.Instance.m_swapOffsetDir)
        //			{
        //				if(TrafficSystem.Instance.m_swapOffsetSize)
        //				{
        //					posOffset.x = posOffset.z * dir.z;
        //					posOffset.y = posOffset.y * dir.y;
        //					posOffset.z = posOffset.x * dir.x;
        //				}
        //				else
        //				{
        //					posOffset.x = posOffset.x * dir.z;
        //					posOffset.y = posOffset.y * dir.y;
        //					posOffset.z = posOffset.z * dir.x;
        //				}
        //			}
        //			else
        //			{
                if(TrafficSystem.Instance.m_swapOffsetSize)
                {
                    float x = posOffset.x;
                    posOffset.x = posOffset.z;
                    posOffset.y = posOffset.y;
                    posOffset.z = x;
                }
                else
                {
                    posOffset.x = posOffset.x;
                    posOffset.y = posOffset.y;
                    posOffset.z = posOffset.z;
                }
        //			}

            if(TrafficSystem.Instance.m_negateOffsetSize)
            {
                posOffset.x = -posOffset.x;
                posOffset.y = -posOffset.y;
                posOffset.z = -posOffset.z;
            }

            a_currentPiece.transform.position = pos + posOffset;
        }
        else
            a_currentPiece.transform.position = pos;

        UpdateEditTrafficSystemPiecePos();
    }