Esempio n. 1
0
    IEnumerator Start()
    {
        height = (buildSettings.maxBuildHeight + buildSettings.minBuildHeight) / 2;
        width  = (buildSettings.maxBuildWidth + buildSettings.minBuildWidth) / 2;

        InitializeWorld();

        inv    = GetComponent <Inventory>();
        cam    = FindObjectOfType <Camera>();
        canvas = FindObjectOfType <MapBuilderCanvas>();
        timer  = FindObjectOfType <Timer>();

        timer.Initialize(buildSettings.buildTime);
        timer.StartCountdown();

        FindObjectOfType <GridGenerator>().GenerateLines(buildSettings.maxBuildWidth, buildSettings.maxBuildHeight);

        spriteSelection = FindObjectOfType <SpriteSelection>();
        spriteSelection.gameObject.SetActive(false);

        hoverBlock                    = Instantiate(BlockData.Instance.prefabs[BlockType.empty], transform);
        hoverSprite                   = hoverBlock.GetComponent <SpriteRenderer>();
        hoverSprite.color             = emptyPlace;
        hoverBlock.transform.position = new Vector3(hoverBlock.transform.position.x, hoverBlock.transform.position.y, hoverOffset);

        UpdateSelectKeys();
        InputManager.Instance.ControlsChanged += UpdateSelectKeys;

        buildData.SetDimensions(height, width);
        buildData.SetMapState(blockData, blockView);
        buildData.SetObjectData(this, worldHolder, hoverBlock, hoverSprite, spriteSelection, selected, inv, cam);
        buildData.Start();

        yield return(new WaitForEndOfFrame());

        onDimensionsChanged?.Invoke(width, height);
    }