Exemple #1
0
 private void DisplayCost()
 {
     cost          = defenderCost.GetCost();
     costDisplay   = GetComponent <CostDisplay>();
     textCost      = costDisplay.GetComponentInChildren <Text>();
     textCost.text = cost.ToString();
 }
Exemple #2
0
    private void RevealImage()
    {
        SpriteRenderer renderer = GetComponent <SpriteRenderer>();

        renderer.color = Color.white;
        CostDisplay costDisplay = FindObjectOfType <CostDisplay>();

        costDisplay.SetCost(defenderPrefab.GetCost());
        costDisplay.RevealPrice();
    }
 public void BuildingComplete(string type)
 {
     if (type == requirement)
     {
         requirement = "";
         CostDisplay cost = GetComponentInChildren <CostDisplay>(true);
         if (cost != null)
         {
             cost.gameObject.SetActive(true);
         }
         foreach (Renderer render in GetComponentsInChildren <Renderer>())
         {
             render.enabled = true;
         }
         HighlightEffect.RemoveHighlight(gameObject);
     }
 }
Exemple #4
0
    void OnEnable()
    {
        audio       = GetComponent <AudioSource>();
        isFirstTurn = true;
        if (firstTurnWork && TileGrid.instance.worldGenerated)
        {
            audio.PlayOneShot(workerPlaceSounds[Random.Range(0, workerPlaceSounds.Length)]);
            working = true;
            foreach (SpecialStates child in GetComponentsInChildren <SpecialStates>(true))
            {
                if (child.activeOnWork)
                {
                    child.gameObject.SetActive(true);
                }
            }
        }

        BuildingPrice price   = GetComponent <BuildingPrice>();
        CostDisplay   display = Instantiate(Resources.instance.workCostDisplay).GetComponent <CostDisplay>();

        display.transform.SetParent(transform);
        display.transform.localPosition = price.heightOffset * -Vector3.up;

        int q = 0;

        foreach (BuildingPrice.Cost cost in price.workCosts)
        {
            display.costs[q].sprite.gameObject.SetActive(true);
            display.costs[q].sprite.sprite = Resources.instance.GetIcon(cost.type);
            display.costs[q].text.text     = cost.amount.ToString();
            ++q;
        }

        if (!price.alwaysShowCost)
        {
            display.gameObject.SetActive(false);
        }

        foreach (BuildingPrice.Cost max in maxIncreses)
        {
            Resources.instance.SetValue(max.type, Resources.instance.GetValue(max.type, true) + max.amount, true);
        }
    }
Exemple #5
0
    private int AddToMenu(int i, MenuEntry go)
    {
        Transform menuItem = Instantiate(go.prefab).transform;

        menuItem.gameObject.GetComponent <BuildingPrice>().enabled = true;
        menuItem.parent        = transform;
        menuItem.localPosition = i * (1.57f + ((i % 2 == 1) ? 0.1f : 0)) * Vector3.down + ((i % 2 == 1) ? 1.5f : 0) * Vector3.right + go.yOffset * Vector3.up;
        menuItem.rotation      = itemRotation;
        menuItem.localScale    = Vector3.one;
        foreach (Transform trans in menuItem.gameObject.GetComponentsInChildren <Transform>(true))
        {
            trans.gameObject.layer = gameObject.layer;
        }
        foreach (SpecialStates states in menuItem.GetComponentsInChildren <SpecialStates>())
        {
            if (states.hideInMenu)
            {
                Destroy(states.gameObject);
            }
        }

        BuildingPrice price = menuItem.GetComponent <BuildingPrice>();

        if (price != null)
        {
            price.prefab = go.prefab;
            BuildingPrice.Cost[] costs    = price.buildCosts;
            Transform            costItem = null;
            if (costs.Length > 0)
            {
                costItem                  = Instantiate(costTip).transform;
                costItem.parent           = menuItem;
                costItem.localPosition    = Vector3.zero;
                costItem.localRotation    = Quaternion.identity;
                costItem.localScale       = Vector3.one;
                costItem.gameObject.layer = gameObject.layer;
                CostDisplay display = costItem.GetComponent <CostDisplay>();
                int         q       = 0;
                foreach (BuildingPrice.Cost cost in costs)
                {
                    display.costs[q].sprite.gameObject.SetActive(true);
                    display.costs[q].sprite.sprite = resourcePool.GetIcon(cost.type);
                    display.costs[q].text.text     = cost.amount.ToString();
                    ++q;
                }
            }
            if (price.requirement != "")
            {
                if (costItem != null)
                {
                    costItem.gameObject.SetActive(false);
                }
                foreach (Renderer render in menuItem.GetComponentsInChildren <Renderer>())
                {
                    render.enabled = false;
                }
                HighlightEffect.AddHighlight(menuItem.gameObject, new Color(1, 1, 1), true);
            }
        }

        return(i + 1);
    }
Exemple #6
0
 // Start is called before the first frame update
 void Start()
 {
     gameManager      = FindObjectOfType <GameManager>();
     indicatorManager = FindObjectOfType <IndicatorManager>();
     costDisplay      = FindObjectOfType <CostDisplay>();
 }
    void Update()
    {
        GameObject hovering = null;
        RaycastHit hit;
        bool       buildStage = (RoundManager.instance.stage == RoundManager.RoundStage.DAWN || RoundManager.instance.stage == RoundManager.RoundStage.DUSK);

        if (!ScoreTracker.instance.isSummaryShowing && buildStage && menuCamera.ScreenToWorldPoint(Input.mousePosition).x < menuLimiter.position.x && Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, terrainLayer))
        {
            hovering = hit.collider.gameObject;
        }

        if (currentHover != hovering)
        {
            // Remove old:
            if (currentHover != null)
            {
                if (currentTile != null)
                {
                    HighlightEffect.RemoveHighlight(currentTile);

                    BuildingPrice price   = currentTile.GetComponent <BuildingPrice>();
                    CostDisplay   display = currentTile.GetComponentInChildren <CostDisplay>(true);
                    if (price != null && display != null && !price.alwaysShowCost)
                    {
                        display.gameObject.SetActive(false);
                    }
                }
                else
                {
                    HighlightEffect.RemoveHighlight(currentHover);
                }
            }

            // Add new:
            currentPoint = null;
            currentHover = null;
            currentTile  = null;
            if (hovering != null)
            {
                currentPoint = world.GetTerrainPos(hovering);
                if (currentPoint != null)
                {
                    GameObject tile = world.GetTile(currentPoint.x, currentPoint.y);
                    if (tile != null)
                    {
                        HighlightEffect.AddHighlight(tile, blockHoverColor);
                        currentTile = tile;

                        BuildingPrice price   = currentTile.GetComponent <BuildingPrice>();
                        CostDisplay   display = currentTile.GetComponentInChildren <CostDisplay>(true);
                        if (price != null && display != null && !price.alwaysShowCost)
                        {
                            display.gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        HighlightEffect.AddHighlight(hovering, blockHoverColor);
                    }
                    currentHover = hovering;
                }
            }
        }

        if (!ScoreTracker.instance.isSummaryShowing && buildStage && Input.GetButtonDown("Click") && currentPoint != null)
        {
            if (currentTile == null)
            {
                if (BuildMenu.activeTool != null && BuildMenu.activeTool.isPlaceable && Resources.instance.TryBuy(BuildMenu.activeTool.buildCosts))
                {
                    if (BuildMenu.activeTool.construction != null)
                    {
                        world.SetTile(currentPoint.x, currentPoint.y, BuildMenu.activeTool.construction);
                    }
                    else
                    {
                        world.SetTile(currentPoint.x, currentPoint.y, BuildingPrice.selected.prefab);
                    }
                    HighlightEffect.RemoveHighlight(currentHover);
                    currentHover = null;
                    world.GetTile(currentPoint.x, currentPoint.y).GetComponent <GameTile>().audio.PlayOneShot(buildSound);
                    SoundEffects.PlaySound(buildSound);
                    foreach (BuildingPrice.Cost cost in BuildMenu.activeTool.buildCosts)
                    {
                        if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                        {
                            ScoreTracker.instance.AddExpenses(cost.type, cost.amount);
                        }
                    }
                }
            }
            else
            {
                currentTile.GetComponent <GameTile>().ClickTile(world, currentPoint.x, currentPoint.y);
            }
        }
    }