Exemplo n.º 1
0
    void Update()
    {
        Game.Update(Time.deltaTime);
        foreach (var e in Game.Buildings)
        {
            if (e.GameObject == null)
            {
                AttachGameObject(e);
            }
            var obj    = e.GameObject;
            var h      = Game.Terrain.AverageHeight(e.Cell.i, e.Cell.j, e.type.w, e.type.h);
            var center = e.Cell.ToVector + 0.5f * new Vector3(e.type.w, 0, e.type.h);
            obj.transform.position   = center + new Vector3(0, h, 0);
            obj.transform.localScale = new Vector3(1, (0.2f + 0.8f * e.BuildProgress), 1);
            e.GameObject.GetComponent <Renderer>().material.color = BuildingColor(e);
        }
        PruneDead(Game.Buildings);
        Game.Buildings.RemoveAll(e => e.IsDead);

        foreach (var e in Game.Entities)
        {
            if (Game.NeighbourDist[e.Pos] > Game.VisionRange)
            {
                continue;
            }
            if (e.GameObject == null)
            {
                AttachGameObject(e);
            }
            e.GameObject.transform.position = e.Pos;
            e.GameObject.transform.rotation = Quaternion.LookRotation(e.Dir, Vector3.up);
        }
        PruneDead(Game.Entities);
        Game.Entities.RemoveAll(e => e.IsDead);

        InputFilter.Update();
        if (InputFilter.IsStartOfTap && Input.mousePosition.x > 110)
        {
            Game.SelectCell();
        }
        if (InputFilter.Hold)
        {
            var delta = new Vector3(InputFilter.Swipe.x, 0, InputFilter.Swipe.y);
            Game.Pan += 0.003f * Game.Zoom * delta;
        }
    }