示例#1
0
    public void Regenerate(bool rebuild = false)
    {
        float tStart = Time.realtimeSinceStartup;

        string path = levelDirectory + gameObject.name + ".asset";

        if (!rebuild && Map.IsMap(path))
        {
            map = Map.Read(path);
        }
        else
        {
            map = Map.Generate(new DepthFirstGenerator(width, height));
            if (!Application.isPlaying)
            {
                map.SaveToFile(path);
            }
        }

        MeshFilter filter = GetComponent<MeshFilter>();
        if (filter == null)
            gameObject.AddComponent<MeshFilter>();

        ProceduralMesh pm = new ProceduralMesh();
        pm.Generate(map);
        pm.Compile();

        GetComponent<MeshCollider>().sharedMesh = pm.Mesh;
        filter.sharedMesh = pm.Mesh;

        float tEnd = Time.realtimeSinceStartup;
        float tTotal = tEnd - tStart;
        Debug.Log("Level Regenerate( Maze: " + rebuild + " ). Time: " + tTotal);
    }