Beispiel #1
0
    public bool CanMove(GameObject currentTile, Enums.direction dir)
    {
        GameObject   currentGrid  = currentTile.transform.parent.gameObject;
        GridInstance gridInstance = currentGrid.GetComponent <GridInstance>();
        TileInstance tileInstance = currentTile.GetComponent <TileInstance>();

        GameObject[,] tileArray = gridInstance._tileArray;
        GameObject tileNext = null;

        switch (dir)
        {
        case Enums.direction.left:
            tileNext = tileArray[tileInstance.x - 1, tileInstance.y];
            break;

        case Enums.direction.right:
            tileNext = tileArray[tileInstance.x + 1, tileInstance.y];
            break;

        case Enums.direction.up:
            tileNext = tileArray[tileInstance.x, tileInstance.y + 1];
            break;

        case Enums.direction.down:
            tileNext = tileArray[tileInstance.x, tileInstance.y - 1];
            break;
        }

        if (tileNext != null && tileNext.tag != "Obstacle" && tileNext.GetComponent <TileInstance>().connectedObject.tag != "Obstacle")
        {
            return(true);
        }

        return(false);
    }
Beispiel #2
0
    public bool HasAliveObjectsAbove(GridInstance gridInstance)
    {
        var pickComponent = GetComponent <Picker>();
        var objectAbove   = gridInstance.GetGridObject((int)(pickComponent.index.x), (int)Mathf.Max(0, pickComponent.index.y - 1), (int)(pickComponent.index.z));

        if (objectAbove && objectAbove != transform && objectAbove.renderer.enabled)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #3
0
    public void GetAliveObjectsAbove(GridInstance gridInstance, Transform pick, List <Transform> aliveObjects)
    {
        var pickComponent = pick.GetComponent <Picker>();
        //var objectAbove = gridInstance.grid[(int)(pickComponent.index.x), (int)Mathf.Min(gridInstance.ySize - 1, pickComponent.index.y + 1), (int)(pickComponent.index.z)];
        //var objectAbove = gridInstance.GetGridObject((int)(pickComponent.index.x), (int)Mathf.Min(gridInstance.ySize - 1, pickComponent.index.y + 1), (int)(pickComponent.index.z));
        //Vector3 debug = new Vector3((int)(pickComponent.index.x), (int)Mathf.Max(0, pickComponent.index.y - 1), (int)(pickComponent.index.z));
        //Debug.Log("Above: " + pick.GetInstanceID() + " " + debug);
        var objectAbove = gridInstance.GetGridObject((int)(pickComponent.index.x), (int)Mathf.Max(0, pickComponent.index.y - 1), (int)(pickComponent.index.z));

        if (objectAbove && objectAbove != pick && objectAbove.renderer.enabled)
        {
            aliveObjects.Add(objectAbove);
            GetAliveObjectsAbove(gridInstance, objectAbove, aliveObjects);
        }
    }
Beispiel #4
0
    public void CreateGrid()
    {
        List <GridCreatorSlot> grid = new List <GridCreatorSlot>();

        ClearGrid();

        GameObject   grid_parent   = null;
        GridInstance grid_instance = null;

        if (grid_size.x > 0 && grid_size.y > 0)
        {
            grid_parent      = new GameObject();
            grid_parent.name = "Grid";
            grid_parent.tag  = "Grid";

            grid_instance = grid_parent.AddComponent <GridInstance>();
        }

        for (int i = 0; i < grid_size.x; ++i)
        {
            for (int y = 0; y < grid_size.y; ++y)
            {
                Vector2 slot_pos = new Vector2((i * slot_size) + starting_pos.x, (y * slot_size) + starting_pos.y);

                GameObject go = new GameObject();
                go.transform.position   = new Vector3(slot_pos.x, 0, slot_pos.y);
                go.transform.rotation   = Quaternion.Euler(90, 0, 0);
                go.transform.localScale = new Vector3(slot_size, slot_size, 1);
                go.name = "Grid [" + i + "] " + "[" + y + "]";

                go.transform.parent = grid_parent.transform;

                GridSlotManager gs = go.AddComponent <GridSlotManager>();

                GridCreatorSlot slot = new GridCreatorSlot(go, gs);

                grid.Add(slot);
            }
        }

        if (grid_instance != null)
        {
            grid_instance.CreateGrid(slot_size);
        }
    }
    public void GenerateTileset(int width, int height)
    {
        RemoveTileset();

        _gridInstance = GetComponent <GridInstance>();

        _gridInstance.NewTileset(width, height);

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                GameObject   tile         = Instantiate(_tile, gameObject.transform);
                TileInstance tileInstance = tile.GetComponent <TileInstance>();
                tileInstance.x          = i;
                tileInstance.y          = j;
                tile.name               = "Tile [" + i + "," + j + "]";
                tile.transform.position = new Vector3(gameObject.transform.position.x + i, 0, gameObject.transform.position.z + j);
                _gridInstance.AddTile(i, j, tile);
            }
        }
    }