Esempio n. 1
0
 public BlockContent(Entity entity, VoxelData.VoxelType voxelType, int index)
 {
     this.entity     = entity;
     this.voxelType  = voxelType;
     this.voxelIndex = index;
 }
Esempio n. 2
0
    public void ChangeHotbarContent(VoxelData.VoxelType voxelType)
    {
        // Atualiza cor dos ícones das abas
        foreach (GameObject tab in tabs)
        {
            VoxelData.VoxelType tabContent = tab.GetComponent <Tab>().tabContent;
            Text tabIcon = tab.GetComponentInChildren <Text>();
            tabIcon.color = (tabContent != voxelType) ? new Color(1, 1, 1) : selectedColor;
        }

        // Limpa instancias anteriores
        foreach (GameObject item in hotbar)
        {
            DestroyImmediate(item);
        }

        hotbar.Clear();
        hotbarSize   = 0;
        curVoxelType = (byte)voxelType;

        // Recebe o tamanho da lista para instanciar os slots da toolbar
        if (voxelType == VoxelData.VoxelType.Block)
        {
            hotbarSize = blockList.Count;
        }
        else if (voxelType == VoxelData.VoxelType.Fluid)
        {
            hotbarSize = fluidList.Count;
        }
        else if (voxelType == VoxelData.VoxelType.Prop)
        {
            hotbarSize = PropData.singleton.propList.Count;
        }

        // Inicializa toolbar de edição dos blocos
        for (int i = 0; i < hotbarSize; i++)
        {
            int pos = i;
            // Instancia slot
            hotbar.Add(Instantiate(slotPrefab));
            hotbar[i].transform.SetParent(slotList);
            hotbar[i].transform.localPosition = new Vector3(0f, 0f, 0f);
            hotbar[i].name = "Slot " + i;
            // Armazena índice do slot e ID do bloco
            hotbar[i].GetComponent <MapMakerSlot>().index   = pos;
            hotbar[i].GetComponent <MapMakerSlot>().blockID = pos;
            // Armazena valores novamente, desta vez para facilitar uso
            int slotIndex = hotbar[i].GetComponent <MapMakerSlot>().index;
            int blockID   = hotbar[i].GetComponent <MapMakerSlot>().blockID;
            // Define sprite dos slots como não selecionado
            hotbar[pos].GetComponentsInChildren <Image>()[0].enabled = true;
            hotbar[pos].GetComponentsInChildren <Image>()[0].sprite  = notSelected;
            if (voxelType == VoxelData.VoxelType.Block)
            {
                hotbar[pos].GetComponentsInChildren <Image>()[1].sprite = blockList[blockID].icon;
            }
            else if (voxelType == VoxelData.VoxelType.Fluid)
            {
                hotbar[pos].GetComponentsInChildren <Image>()[1].sprite = fluidList[blockID].icon;
            }
            // Adiciona listener para modificar índice ativo
            hotbar[pos].GetComponent <Button>().onClick.AddListener(() => UpdateIndex(slotIndex));
        }

        // Recebe conteúdo da posição inicial da hotbar
        curSlotIndex = 0;
        curVoxelID   = (byte)hotbar[0].GetComponent <MapMakerSlot>().blockID;

        // Altera sprite da posição inicial da hotbar
        hotbar[0].GetComponent <Image>().sprite = selected;

        // Ajusta posição da lista
        slotList.transform.localPosition = new Vector3(50f, 0f, 0f);
    }