Beispiel #1
0
    IEnumerator Highlight(GameObject go, Color color, float time)
    {
        HighlightEffect.AddHighlight(go, color);
        yield return(new WaitForSeconds(time));

        HighlightEffect.RemoveHighlight(go);
    }
Beispiel #2
0
 void Update()
 {
     if (!done)
     {
         done = true;
         HighlightEffect.AddHighlight(gameObject, color);
     }
 }
 void OnMouseUpAsButton()
 {
     if (enabled && requirement == "" && !ScoreTracker.instance.isSummaryShowing)
     {
         if (selected != null)
         {
             HighlightEffect.RemoveHighlight(selected.gameObject);
         }
         HighlightEffect.AddHighlight(gameObject, selectionColor, true);
         selected             = this;
         BuildMenu.activeTool = this;
     }
 }
Beispiel #4
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);
    }
    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);
            }
        }
    }
Beispiel #6
0
    public void ClickTile(TileGrid world, int x, int y)
    {
        if (enabled && !ScoreTracker.instance.isSummaryShowing)
        {
            if (BuildMenu.activeTool.type == "peep" && !firstTurnWork)
            {
                BuildingPrice.Cost[] workCosts = GetComponent <BuildingPrice>().workCosts;
                if (working || (ContainsPerson(workCosts) && Resources.instance.TryBuy(workCosts)))
                {
                    working = !working;
                    if (!working)
                    {
                        audio.PlayOneShot(workerRemoveSounds[Random.Range(0, workerRemoveSounds.Length)]);
                        foreach (BuildingPrice.Cost cost in workCosts)
                        {
                            if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                            {
                                ScoreTracker.instance.RemoveExpenses(cost.type, cost.amount);
                            }
                        }
                        Resources.instance.AddResources(workCosts);
                    }
                    else
                    {
                        audio.PlayOneShot(workerPlaceSounds[Random.Range(0, workerPlaceSounds.Length)]);
                        foreach (BuildingPrice.Cost cost in workCosts)
                        {
                            if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                            {
                                ScoreTracker.instance.AddExpenses(cost.type, cost.amount);
                            }
                        }
                    }
                    foreach (SpecialStates child in GetComponentsInChildren <SpecialStates>(true))
                    {
                        if (child.activeOnWork)
                        {
                            child.gameObject.SetActive(working);
                        }
                    }
                    gameObject.BroadcastMessage("WorkingToggle", SendMessageOptions.DontRequireReceiver);
                    Color highlightColor = HighlightEffect.GetColor(gameObject);
                    if (highlightColor != Color.black)
                    {
                        HighlightEffect.RemoveHighlight(gameObject);
                        HighlightEffect.AddHighlight(gameObject, highlightColor);
                    }
                }
            }
            else if (BuildMenu.activeTool.type == "demo")
            {
                if (canDemolish && (firstTurnWork || !working))
                {
                    world.SetTile(x, y, null);
                    Resources.instance.AddResources(demolishRefund);
                    foreach (BuildingPrice.Cost cost in demolishRefund)
                    {
                        if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                        {
                            ScoreTracker.instance.RemoveExpenses(cost.type, cost.amount);
                        }
                    }
                    if (working)
                    {
                        BuildingPrice.Cost[] workCosts = GetComponent <BuildingPrice>().workCosts;
                        foreach (BuildingPrice.Cost cost in workCosts)
                        {
                            if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                            {
                                ScoreTracker.instance.RemoveExpenses(cost.type, cost.amount);
                            }
                        }
                        Resources.instance.AddResources(workCosts);

                        if (firstTurnWork && isFirstTurn)
                        {
                            ++Resources.instance.person;
                        }
                    }
                    SoundEffects.PlaySound(WorldInteraction.instance.buildSound, 0.9f);
                }
                else
                {
                    // TODO (hitch) ERROR (can't demolish)
                }
            }
        }
    }