Ejemplo n.º 1
0
    /*
     * Add lights to the room.
     * If there are windows, we may choose not to turn the lights on
     */
    private void AddLights()
    {
        if (_window.GetWindowCount() == 0 || Random.Range(0f, _window.GetWindowCount()) < 1)
        {
            GameObject lightSource = new GameObject();
            lightSource.transform.parent = transform;
            Vector3 lightPos = new Vector3(0, _ceiling.GetHeight() - 0.5f, 0);
            Light   light    = lightSource.AddComponent <Light>();
            light.type = LightType.Point;

            lightSource.transform.position = lightPos;
            light.color     = Color.yellow;
            light.range     = 3f;
            light.intensity = 0.85f;
            light.shadows   = LightShadows.Soft;
            light.name      = "LightBulb";
        }
    }
Ejemplo n.º 2
0
    /*
     * Add windows to the outside walls
     */
    public void AddWindows()
    {
        int        wallIndex    = 0;
        int        windowIndex  = Random.Range(0, _windowPrefabs.Length);
        GameObject windowPrefab = _windowPrefabs[windowIndex];
        Bounds     bounds       = windowPrefab.GetComponent <MeshRenderer>().bounds;
        float      windowWidth  = bounds.max.x - bounds.min.x;

        Debug.Log("Window Size: " + windowWidth);
        LineRange groundRangeX = _ground.GetXRange();
        LineRange groundRangeZ = _ground.GetZRange();

        foreach (bool isOutsideWall in _wall.GetIsOutsideWalls())
        {
            if (isOutsideWall && Random.Range(0f, 1f) < _windowChance[wallIndex])
            {
                // Add Window(s)
                List <LineRange> freeWallSections = _wall.GetEmptySections(wallIndex);
                foreach (LineRange freeWallSection in freeWallSections)
                {
                    if (freeWallSection.max - freeWallSection.min > windowWidth)
                    {
                        // Window fits
                        Vector3 windowAt = _wall.AddToWall(wallIndex, freeWallSection, windowWidth, (_ceiling.GetHeight() / 3) * 2);

                        GameObject window = Instantiate <GameObject>(windowPrefab);
                        window.transform.Rotate(_wall.GetWallRotate(wallIndex) * Vector3.up);
                        window.transform.position = windowAt;
                        Debug.Log("Window " + wallIndex + "(" + windowAt.x + "," + windowAt.z + "): " + window.transform.position);
                        window.transform.parent = transform;
                        window.transform.name   = "Window" + wallIndex + windowPrefab.name;
                        window.tag = "Decoration";
                        AddWindowLight(wallIndex, window);

                        _windowCount++;
                        // Only one window per wall
                        break;
                    }
                }
            }
            wallIndex++;
        }
    }
Ejemplo n.º 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);
        }
    }