コード例 #1
0
    // Only to be called by user in editor
    // As not much though has been placed in here
    private void RegenerateMap()
    {
        oldParameters = GetParameters();
        MapGenerator generator = new MapGenerator(oldParameters);

        MapGenerationProgress.InstantiateNew(generator);
        generationTask = Task.Run(() =>
        {
            GridMap.Instance.GenerateMap(generator);
            RegenerateMeshes();
        });
    }
コード例 #2
0
    void Update()
    {
        switch (state)
        {
        case State.Created:
            state = State.GeneratingMap;
            logger.Log("generating new map");

            GenerationParameters parameters = GetParameters();
            MapGenerator         generator  = new MapGenerator(parameters);
            MapGenerationProgress.InstantiateNew(generator);
            oldParameters  = parameters;
            generationTask = Task.Run(() => GridMap.Instance.GenerateMap(generator));
            break;

        case State.GeneratingMap:
        case State.LoadingMap:
            if (GridMap.Instance.IsGenerationDone())
            {
                logger.Log("Map finished generation");
                state = State.MapGenerated;
            }
            break;

        case State.MapGenerated:
            logger.Log("Creating meshGenerators");
            BlockMeshes.LoadMeshes();
            createMeshCreators();
            UpdateMaxVerticalLevel();
            RegenerateMeshes();
            state          = State.MeshGeneratorsCreated;
            cameraObserver = new SimpleObserver <CameraController>(mainCam, (cam) =>
            {
                UpdateMaxVerticalLevel();
                RegenerateMeshes();
            });

            break;

        case State.MeshGeneratorsCreated:
            break;
        }
        if (!oldParameters.Equals(GetParameters()) && generationTask != null && !generationTask.Status.Equals(TaskStatus.Running))
        {
            regenerateMap = false;
            RegenerateMap();
        }
    }
コード例 #3
0
    public static MapGenerationProgress InstantiateNew(IMapGenerator newGenerator)
    {
        GameObject prefabObj = PrefabLoader.GetPrefab <GameObject>(prefabName);
        GameObject obj       = Instantiate(prefabObj) as GameObject;

        if (!obj)
        {
            throw new System.Exception("Could not instantiate prefab " + prefabName);
        }
        MapGenerationProgress disp = obj.GetComponent <MapGenerationProgress>();

        if (!disp)
        {
            throw new System.Exception("No MapGenerationProgress Component on " + prefabName);
        }
        disp.generator = newGenerator;
        return(disp);
    }