Example #1
0
    // Create the ground
    private void PopulateGround(List <Vector3> points)
    {
        GameObject ground = new GameObject();

        ground.transform.parent = transform;
        int          groundMaterialIndex = Random.Range(0, _groundMaterials.Length);
        MeshRenderer groundRendered      = ground.AddComponent <MeshRenderer>();

        groundRendered.material = _groundMaterials[groundMaterialIndex];
        ground.transform.name   = "Ground" + groundRendered.material.name;
        ground.tag = "Ground";
        MeshCollider groundCollider   = ground.AddComponent <MeshCollider>();
        MeshFilter   groundMeshFilter = ground.AddComponent <MeshFilter>();
        PlaneRange   range            = new PlaneRange(0, 1f, 0, 0, 0, 1f);

        if (_missingFloor)
        {
            // TODO: Change to only render floor that exists
            groundMeshFilter.mesh = MeshTools.CreateMeshFromVectors(points, range);
        }
        else
        {
            groundMeshFilter.mesh = MeshTools.CreateMeshFromVectors(points, range);
        }
        groundCollider.sharedMesh = groundMeshFilter.mesh;
    }
Example #2
0
    /*
     * Add a ceiling to the room
     */
    public void AddCeiling()
    {
        GameObject ceiling = new GameObject();

        ceiling.transform.parent = transform;
        int          ceilingMaterialIndex = Random.Range(0, _ceilingMaterials.Length);
        MeshRenderer ceilingRendered      = ceiling.AddComponent <MeshRenderer>();

        ceilingRendered.material = _ceilingMaterials[ceilingMaterialIndex];
        ceiling.transform.name   = "Ceiling" + ceilingRendered.material.name;
        MeshCollider   ceilingCollider   = ceiling.AddComponent <MeshCollider>();
        MeshFilter     ceilingMeshFilter = ceiling.AddComponent <MeshFilter>();
        List <Vector3> ceilingPoints     = new List <Vector3>();
        LineRange      groundRangeX      = _ground.GetXRange();
        LineRange      groundRangeZ      = _ground.GetZRange();

        ceilingPoints.Add(new Vector3(groundRangeX.max * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.min * _wall.GetWallShrink()));
        ceilingPoints.Add(new Vector3(groundRangeX.min * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.min * _wall.GetWallShrink()));
        ceilingPoints.Add(new Vector3(groundRangeX.min * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.max * _wall.GetWallShrink()));
        ceilingPoints.Add(new Vector3(groundRangeX.max * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.max * _wall.GetWallShrink()));

        PlaneRange ceilingRange = new PlaneRange(
            0, 1,
            0, 0,
            0, 1
            );

        ceilingMeshFilter.mesh = MeshTools.CreateMeshFromVectors(ceilingPoints, ceilingRange);

        ceilingCollider.sharedMesh = ceilingMeshFilter.mesh;
    }
Example #3
0
    /*
     * Create the walls
     * Walls are slightly smaller than a bounding box of the chaparone area
     * We will in the area outside the chaparone area, but inside walls
     * with debris, furniture, ect
     */
    public void AddWalls()
    {
        GameObject[]     walls        = new GameObject[4];
        List <Vector3>[] wallPoints   = new List <Vector3> [4];
        PlaneRange[]     wallRanges   = new PlaneRange[4];
        LineRange        groundRangeX = _ground.GetXRange();
        LineRange        groundRangeZ = _ground.GetZRange();

        _wallEmpty[0] = new List <LineRange>();
        _wallEmpty[0].Add(new LineRange(_adjustment + groundRangeX.min * _shrinkWall, _adjustment + groundRangeX.max * _shrinkWall));
        wallPoints[0] = new List <Vector3>();
        wallPoints[0].Add(new Vector3(groundRangeX.min * _shrinkWall, 0, groundRangeZ.min * _shrinkWall));
        wallPoints[0].Add(new Vector3(groundRangeX.min * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.min * _shrinkWall));
        wallPoints[0].Add(new Vector3(groundRangeX.max * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.min * _shrinkWall));
        wallPoints[0].Add(new Vector3(groundRangeX.max * _shrinkWall, 0, groundRangeZ.min * _shrinkWall));
        wallRanges[0] = new PlaneRange(
            0, 1,
            0, 1,
            0, 0
            );

        _wallEmpty[1] = new List <LineRange>();
        _wallEmpty[1].Add(new LineRange(_adjustment + groundRangeZ.min * _shrinkWall, _adjustment + groundRangeZ.max * _shrinkWall));
        _wallEmpty[1] = new List <LineRange>();
        _wallEmpty[1].Add(new LineRange(_adjustment + groundRangeZ.min * _shrinkWall, _adjustment + groundRangeZ.max * _shrinkWall));
        wallPoints[1] = new List <Vector3>();
        wallPoints[1].Add(new Vector3(groundRangeX.max * _shrinkWall, 0, groundRangeZ.min * _shrinkWall));
        wallPoints[1].Add(new Vector3(groundRangeX.max * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.min * _shrinkWall));
        wallPoints[1].Add(new Vector3(groundRangeX.max * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.max * _shrinkWall));
        wallPoints[1].Add(new Vector3(groundRangeX.max * _shrinkWall, 0, groundRangeZ.max * _shrinkWall));
        wallRanges[1] = new PlaneRange(
            0, 0,
            0, 1,
            0, 1
            );
        _wallEmpty[2] = new List <LineRange>();
        _wallEmpty[2].Add(new LineRange(_adjustment + groundRangeX.min * _shrinkWall, _adjustment + groundRangeX.max * _shrinkWall));
        wallPoints[2] = new List <Vector3>();
        wallPoints[2].Add(new Vector3(groundRangeX.max * _shrinkWall, 0, groundRangeZ.max * _shrinkWall));
        wallPoints[2].Add(new Vector3(groundRangeX.max * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.max * _shrinkWall));
        wallPoints[2].Add(new Vector3(groundRangeX.min * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.max * _shrinkWall));
        wallPoints[2].Add(new Vector3(groundRangeX.min * _shrinkWall, 0, groundRangeZ.max * _shrinkWall));
        wallRanges[2] = new PlaneRange(
            0, 1,
            0, 1,
            0, 0
            );
        _wallEmpty[3] = new List <LineRange>();
        _wallEmpty[3].Add(new LineRange(_adjustment + groundRangeZ.min * _shrinkWall, _adjustment + groundRangeZ.max * _shrinkWall));
        wallPoints[3] = new List <Vector3>();
        wallPoints[3].Add(new Vector3(groundRangeX.min * _shrinkWall, 0, groundRangeZ.max * _shrinkWall));
        wallPoints[3].Add(new Vector3(groundRangeX.min * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.max * _shrinkWall));
        wallPoints[3].Add(new Vector3(groundRangeX.min * _shrinkWall, _ceiling.GetHeight(), groundRangeZ.min * _shrinkWall));
        wallPoints[3].Add(new Vector3(groundRangeX.min * _shrinkWall, 0, groundRangeZ.min * _shrinkWall));
        int wallMaterialIndex = Random.Range(0, _wallMaterials.Length);

        wallRanges[3] = new PlaneRange(
            0, 0,
            0, 1,
            0, 1
            );
        for (int wallIndex = 0; wallIndex < 4; wallIndex++)
        {
            GameObject wall = new GameObject();
            wall.transform.parent = transform;
            MeshRenderer wallRendered = wall.AddComponent <MeshRenderer>();
            wallRendered.material = _wallMaterials[wallMaterialIndex];
            wall.transform.name   = "Wall" + wallIndex + wallRendered.material.name;
            wall.tag = "Wall";
            MeshCollider wallCollider   = wall.AddComponent <MeshCollider>();
            MeshFilter   wallMeshFilter = wall.AddComponent <MeshFilter>();
            wallMeshFilter.mesh     = MeshTools.CreateMeshFromVectors(wallPoints[wallIndex], wallRanges[wallIndex]);
            wallCollider.sharedMesh = wallMeshFilter.mesh;
            _walls.Add(wall);
            CalculateAccessibleWall(wallIndex);
        }
    }