Exemplo n.º 1
0
    public BuildingAttributes instantiateBuilding()
    {
        if (currentlyCraftedBuilding.GetComponentInChildren <MeshCollider>())
        {
            currentlyCraftedBuilding.GetComponentInChildren <MeshCollider>().isTrigger = false;
        }
        else if (!currentlyCraftedBuilding.GetComponentInChildren <MeshCollider>())
        {
            currentlyCraftedBuilding.GetComponentInChildren <BoxCollider>().isTrigger = false;
        }

        BuildingAttributes buildingAttributes = currentlyCraftedBuilding.GetComponent <BuildingAttributes>();

        // STORAGE CAPACITY
        if (buildingAttributes.gameObject.GetComponent <Inventory>())
        {
            buildingAttributes.GetComponent <Inventory>().setInventoryCapacity(buildingAttributes.getStorageCapacity());
            buildingAttributes.gameObject.GetComponent <Inventory>().instatiateInventory();
        }

        // PLAYER OWNED
        buildingAttributes.setIsOwnedByPlayer(true);

        // TOWN BUILDING IS A PART OF
        buildingAttributes.setTownBuildingIsApartOf(gameManager.GetUI().getPlayerOwnedSelectedTown());

        // POSITION
        if (buildingAttributes.gameObject.GetComponent <BoxCollider>())
        {
            buildingAttributes.setPositionX(currentlyCraftedBuilding.transform.GetComponent <BoxCollider>().bounds.center.x);
            buildingAttributes.setPositionY(currentlyCraftedBuilding.transform.GetComponent <BoxCollider>().bounds.center.y);
            buildingAttributes.setPositionZ(currentlyCraftedBuilding.transform.GetComponent <BoxCollider>().bounds.center.z);
        }
        else
        {
            buildingAttributes.setPositionX(buildingAttributes.transform.position.x);
            buildingAttributes.setPositionY(buildingAttributes.transform.position.y);
            buildingAttributes.setPositionZ(buildingAttributes.transform.position.z);
        }

        // TAGS AND LAYERS
        currentlyCraftedBuilding.tag = craftingSavedTag;
        buildingAttributes.setBuildingTag(craftingSavedTag);
        currentlyCraftedBuilding.layer = LayerMask.NameToLayer(craftingSavedLayer);

        // ADD BUILDING TO TOWN, ACTIVATE ONTRIGGER FOR TOWN
        currentlyCraftedBuilding.SetActive(false);
        currentlyCraftedBuilding.SetActive(true);

        foreach (var item in itemsToRemoveFromInventory)
        {
            gameManager.getInventoryCatalog().getMainInventory().removeItemFromInventory(item.Key, item.Value);
        }
        currentlyCraftedBuilding = null;
        foreach (Town town in gameManager.getPlayerBehavior().getTownsOwned())
        {
            town.townIndicator(false);
        }
        //gameManager.GetUI().getPlayerOwnedSelectedTown().townIndicator(false);
        setIsCrafting(false);
        buildingAttributes.transform.gameObject.SetActive(false);
        buildingAttributes.buildingIndicatorOff();
        return(buildingAttributes);
    }