コード例 #1
0
    private void SetupIntersection(GameObject _trafficLight)
    {
        // Set locations of colliders to stop Vehicles
        foreach (RoadSection junction in roadSection.GetNeighbours())
        {
            // Check if connection is above or below this junction
            if (junction.Row() > roadSection.Row())
            {
                Vector3    pos = new Vector3(transform.position.x + 0.45f, 0.07f, transform.position.z + 0.55f);
                Quaternion rot = Quaternion.Euler(-90.0f, 0.0f, 180.0f);

                GenerateTrafficLight(pos, rot, _trafficLight);
            }

            if (junction.Row() < roadSection.Row())
            {
                Vector3    pos = new Vector3(transform.position.x - 0.45f, 0.07f, transform.position.z - 0.55f);
                Quaternion rot = Quaternion.Euler(-90.0f, 0.0f, 0.0f);

                GenerateTrafficLight(pos, rot, _trafficLight);
            }

            // Check if connection is to the left or right of this junction
            if (junction.Col() > roadSection.Col())
            {
                Vector3    pos = new Vector3(transform.position.x + 0.55f, 0.07f, transform.position.z - 0.45f);
                Quaternion rot = Quaternion.Euler(-90.0f, 0.0f, -90.0f);

                GenerateTrafficLight(pos, rot, _trafficLight);
            }

            if (junction.Col() < roadSection.Col())
            {
                Vector3    pos = new Vector3(transform.position.x - 0.55f, 0.07f, transform.position.z + 0.45f);
                Quaternion rot = Quaternion.Euler(-90.0f, 0.0f, 90.0f);

                GenerateTrafficLight(pos, rot, _trafficLight);
            }
        }
    }
コード例 #2
0
    private void AssignType(RoadSection _section)
    {
        List <RoadSection> neighbours = new List <RoadSection>();

        Vector3 roadPos = _section.transform.position;
        int     index   = 0;

        bool up    = false;
        bool down  = false;
        bool left  = false;
        bool right = false;



        if (roadPos.z + roadSize <= cityLength)
        {
            //Check Up
            if (roadMap[(int)roadPos.z + roadSize, (int)roadPos.x] != null)
            {
                neighbours.Add(roadMap[(int)roadPos.z + roadSize, (int)roadPos.x]);
                up     = true;
                index += 1;
            }
        }

        if (roadPos.z - roadSize >= 0)
        {
            //Check Down
            if (roadMap[(int)roadPos.z - roadSize, (int)roadPos.x] != null)
            {
                neighbours.Add(roadMap[(int)roadPos.z - roadSize, (int)roadPos.x]);
                down   = true;
                index += 8;
            }
        }

        if (roadPos.x - roadSize >= 0)
        {
            //Check Left
            if (roadMap[(int)roadPos.z, (int)roadPos.x - roadSize] != null)
            {
                neighbours.Add(roadMap[(int)roadPos.z, (int)roadPos.x - roadSize]);
                left   = true;
                index += 2;
            }
        }


        if (roadPos.x + roadSize <= cityWidth)
        {
            //Check Right
            if (roadMap[(int)roadPos.z, (int)roadPos.x + roadSize] != null)
            {
                neighbours.Add(roadMap[(int)roadPos.z, (int)roadPos.x + roadSize]);
                right  = true;
                index += 4;
            }
        }

        _section.SetIndex(index);

        _section.GetComponent <MeshFilter>().mesh = roadMeshPrefabs[GetLookupValue(index)];

        Material[] _sectionMats = new Material[2];

        // 3DS Max flips the Mats after Index_7? so a quick fix
        if (index <= 7)
        {
            _sectionMats[0] = roadMaterials[0];
            _sectionMats[1] = roadMaterials[1];
        }

        else
        {
            _sectionMats[0] = roadMaterials[1];
            _sectionMats[1] = roadMaterials[0];
        }

        _section.GetComponent <Renderer>().sharedMaterials = _sectionMats;

        _section.gameObject.AddComponent <MeshCollider>();

        // Compensate for 3Ds Max's Rotations
        _section.transform.rotation = Quaternion.Euler(-90.0f, 180.0f, 0.0f);

        _section.transform.parent = roadContainer.transform;

        _section.SetNeighbours(neighbours);


        if (_section.Index() == 6 || _section.Index() == 9)
        {
            _section.GetComponent <RoadSection>().SetWaypoints();
        }

        else if (_section.GetNeighbours().Count > 2)
        {
            _section.gameObject.AddComponent <Intersection>();
            _section.GetComponent <Intersection>().Initialise(TrafficLightPrefab);
        }
    }