Пример #1
0
    public void CreateGrid(float _slot_size)
    {
        slot_size = _slot_size;

        for (int i = 0; i < transform.childCount; ++i)
        {
            GameObject      go = transform.GetChild(i).gameObject;
            GridSlotManager gs = go.GetComponent <GridSlotManager>();

            GridCreator.GridCreatorSlot slot = new GridCreator.GridCreatorSlot(go, gs);

            grid.Add(slot);
        }

        CalculateGridChilds();
    }
Пример #2
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);
        }
    }
Пример #3
0
        private void GenerateRuntimeGrid(List <GridCreator.GridCreatorSlot> grid)
        {
            grid_slots.Clear();
            interactable_slots.Clear();
            non_interactable_slots.Clear();

            for (int i = 0; i < grid.Count; ++i)
            {
                GameObject curr_go = grid[i].go;

                SpriteRenderer srend = curr_go.AddComponent <SpriteRenderer>();
                srend.sprite  = grid_slot_sprite;
                srend.enabled = false;

                BoxCollider bcoll = curr_go.AddComponent <BoxCollider>();
                bcoll.isTrigger = true;

                GridSlotManager smanager = curr_go.GetComponent <GridSlotManager>();
                smanager.SetGridManager(this);

                GridSlot slot = new GridSlot(curr_go, smanager.GetSlotType(), srend, bcoll);

                grid_slots.Add(slot);

                if (smanager != null)
                {
                    switch (smanager.GetSlotType())
                    {
                    case GridSlotManager.GridSlotType.GST_INTERACTABLE:
                    {
                        interactable_slots.Add(slot);
                        break;
                    }

                    case GridSlotManager.GridSlotType.GST_NO_INTERACTABLE:
                    {
                        non_interactable_slots.Add(slot);
                        break;
                    }
                    }
                }
            }
        }
Пример #4
0
 public GridCreatorSlot(GameObject _go, GridSlotManager _slot_manager)
 {
     go           = _go;
     slot_manager = _slot_manager;
 }