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

        HighlightEffect.RemoveHighlight(go);
    }
 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;
     }
 }
 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);
     }
 }
    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 #5
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)
                }
            }
        }
    }
Beispiel #6
0
 void OnDisable()
 {
     HighlightEffect.RemoveHighlight(gameObject);
     done = false;
 }