Пример #1
0
    public void Initialise(Map map, int seed)
    {
        this.map = map;

        width  = map.levelWidth;
        height = map.levelHeight;

        noiseMap = NoiseMapGenerator.Create(map, seed);

        wallMap = new int[width, height];

        CreateWallMap();

        ProcessMap();

        MSMeshGenerator MSGen = GetComponent <MSMeshGenerator> ();

        Material[] mats = new Material[map.possibleTerrain.Length];
        for (int i = 0; i < map.possibleTerrain.Length; i++)
        {
            mats [i] = map.possibleTerrain [i].terrainMaterial;
        }

        List <MeshFilter> walkables = MSGen.Generate(wallMap, map.tileSize, map.wallHeight, mats, map.wallMaterial);

        ObjectGenerator objGen = GetComponent <ObjectGenerator> ();

        List <GameObject> objects = objGen.GenerateObjects(map, noiseMap);

        NavMeshGenerator meshGen = GetComponent <NavMeshGenerator> ();

        meshGen.Initialise();

        meshGen.BuildNavMesh(walkables, objects, wallMap.GetLength(0) * map.tileSize, wallMap.GetLength(1) * map.tileSize);

        StaticBatchingUtility.Combine(objects.ToArray(), objects [0].transform.parent.gameObject);

        Light worldLight = (Light)Instantiate(new GameObject(), Vector3.zero, Quaternion.Euler(map.lightOptions.angle), this.transform).AddComponent(typeof(Light));

        worldLight.name = "World Light";

        worldLight.type      = LightType.Directional;
        worldLight.intensity = map.lightOptions.intensity;
        worldLight.color     = map.lightOptions.lightColour;
        worldLight.shadows   = LightShadows.Soft;

        worldLight.shadowStrength = 0.8f;

        if (map.postProcProfile != null)
        {
            Camera.main.GetComponent <PostProcessingBehaviour> ().profile = map.postProcProfile;
        }
        else
        {
            Debug.LogWarning("Map is missing a Post Processing Profile");
        }
    }