Пример #1
0
 public void Initialize(BuildingMetaData metaData, Vector2Int coord)
 {
     this.metaData            = metaData;
     coordinate               = coord;
     resourceCalculationOrder = metaData.resourceRecalculationOrder;
     InitializeResourceNeeds();
 }
Пример #2
0
 public void HoverDetailsExit(BuildingMetaData shopItem)
 {
     if (currentShopItemData == shopItem)
     {
         detailsContainer.SetActive(false);
         currentShopItemData = null;
     }
 }
Пример #3
0
    public void Build(BuildingMetaData building, Vector2Int coord)
    {
        isIdle = false;
        //charge costs
        Player.GetInstance().TransactCosts(building.costs);

        //add to queue
        tasks.Add(new Task(building, coord));
        Builder.GetInstance().MoveTo(coord);
    }
Пример #4
0
    public bool CanBuild(BuildingMetaData buildingMetaData, Vector2Int coord)
    {
        GameObject tileGameObject = HexMapManager.GetInstance().TileAtCoordinate(coord);
        HexTile    tile           = tileGameObject.GetComponent <HexTile>();

        if (tile == null || buildingMetaData == null || !tile.inBase)
        {
            return(false);
        }

        return(buildingMetaData.CanBuildOn(tile.id));
    }
Пример #5
0
 public GameObject Build(BuildingMetaData shopItemScriptable, Vector2Int coordinate)
 {
     if (shopItemScriptable.type == ShopItemType.BUILDING)
     {
         return(BuildBuilding(shopItemScriptable, coordinate));
     }
     else
     {
         Debug.LogError("tried to build platform");
         return(null);
     }
 }
Пример #6
0
    public void HoverDetailsEnter(BuildingMetaData shopItem, Vector3 targetPos)
    {
        detailsContainer.SetActive(true);
        currentShopItemData = shopItem;
        detailsContainer.GetComponent <ShopItemDetail>().LoadData(shopItem);

        // Vector2 movePos;

        // RectTransformUtility.ScreenPointToLocalPointInRectangle(GetCanvas().transform as RectTransform, Input.mousePosition, UICamera, out movePos);
        // detailsContainer.transform.position = GetCanvas().transform.TransformPoint(movePos);
        detailsContainer.transform.position = targetPos + new Vector3(-0.3f, -0.3f, -2);
    }
Пример #7
0
    private void EndDragAndDrop()
    {
        _selectedShopItem = null;
        GameObject.Destroy(_dragDropObject);

        if (Shop.GetInstance().isOpen)
        {
            //close shop
            Shop.GetInstance().shopItemsDisplay.SetActive(true);
        }

        if (lastHovered)
        {
            lastHovered.SetValidation(false, false);
        }
    }
Пример #8
0
    public void LoadData(BuildingMetaData item)
    {
        this._item = item;

        // titleText.text = item.title;
        // descriptionText.text = item.description;
        // priceText.text = $"{item.price}";

        _displayObject = GameObject.Instantiate(item.displayPrefab, itemDisplaySlot, false);
        _displayObject.transform.localPosition = Vector3.zero;
        _displayObject.layer = itemDisplaySlot.gameObject.layer;
        foreach (Transform child in _displayObject.transform)
        {
            child.gameObject.layer = itemDisplaySlot.gameObject.layer;
        }
    }
Пример #9
0
    public void BeginDragAndDrop(BuildingMetaData shopItem)
    {
        if (!_dragDropObject)
        {
            _selectedShopItem = shopItem;
            _dragDropObject   = GameObject.Instantiate(shopItem.displayPrefab, Camera.main.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity);
            // LayerMask layer = LayerMask.NameToLayer("UI");
            _dragDropObject.layer = 0;
            foreach (Transform child in _dragDropObject.GetComponentsInChildren <Transform>(true))
            {
                child.gameObject.layer = 0;
            }

            Shop.GetInstance().shopItemsDisplay.SetActive(false);
            //close details
            UIManager.GetInstance().HoverDetailsExit(UIManager.GetInstance().currentShopItemData);
        }
    }
Пример #10
0
    public void Purchase(BuildingMetaData item, Vector2Int coord)
    {
        if (HexMapManager.GetInstance().TileAtCoordinate(coord) == null)
        {
            Debug.LogError("Tried to purchase but no target platform");
            return;
        }

        if (!Player.GetInstance().CanAfford(item.costs))
        {
            return;
        }

        // GameObject platform = BuildingsManager.GetInstance().Build(item, coord);
        Builder.GetInstance().Build(item, coord);

        // if(platform != null) {
        //     Player.GetInstance().TransactCosts(item.costs);
        // }
    }
Пример #11
0
    private GameObject BuildBuilding(BuildingMetaData metaData, Vector2Int coordinate)
    {
        GameObject tile = HexMapManager.GetInstance().TileAtCoordinate(coordinate);

        bool isUpgrade = false;

        Building oldBuilding = BuildingAtCoordinate(coordinate);

        if (oldBuilding != null)
        {
            //check upgrade
            if (oldBuilding.metaData.id == metaData.id)
            {
                //is upgrade
                isUpgrade = true;
            }
            else
            {
                Debug.LogError("Cannot build: already have building here");
                return(null);
            }
        }

        GameObject buildingObject    = GameObject.Instantiate(metaData.prefab, tile.transform.position, tile.transform.rotation);
        Building   buildingComponent = buildingObject.GetComponent <Building>();

        buildingComponent.Initialize(metaData, coordinate);

        if (isUpgrade)
        {
            buildingComponent.UpgradeHandoverFrom(oldBuilding);
            buildings.Remove(coordinate);
            GameObject.Destroy(oldBuilding.gameObject);
        }

        buildings.Add(coordinate, buildingComponent);
        RecalculateResources();

        InfoDetail.GetInstance().LoadData(buildingComponent);
        return(buildingObject);
    }
Пример #12
0
 public Task(BuildingMetaData data, Vector2Int coord)
 {
     this.data       = data;
     this.coordinate = coord;
 }