Esempio n. 1
0
    void drawslotsBp()
    {
        x  = -81; y = 112;
        x1 = -100; y1 = -95;
        Slots.Clear();
        Blueprints.Clear();
        int slotFreeAmount = 25;        //почему 25? потому что все слоты представлены одним листом и поэтому чтобы создать новые слоты необходимо начать с той позиции в которой заканчивается инвентарь

        Blueprintdb = GameObject.FindGameObjectWithTag("BlueprintDatabase").GetComponent <BlueprintDB>();
        itemdb      = GameObject.FindGameObjectWithTag("ItemDatabase").GetComponent <ItemsDB>();
        for (int i = 1; i < 4; i++)         // создаем 12 слотов под наше чертежи и приписываем к каждому слоты чертеж
        {
            for (int j = 1; j < 5; j++)
            {
                GameObject slot = (GameObject)Instantiate(slots);
                slot.GetComponent <Slot> ().slotNumber        = slotFreeAmount;
                slot.GetComponentInChildren <Text> ().enabled = false;
                slot.GetComponent <Slot> ().slotType          = Slot.SlotType.bp;
                Slots.Add(slot);
                Blueprints.Add(new Blueprint());
                slot.name             = "slotbp " + ((j - 1) + 4 * (i - 1));
                slot.transform.parent = this.gameObject.transform;
                slot.GetComponent <RectTransform> ().localPosition = new Vector3(x, y, 0);
                x += 55;
                if (j == 4)
                {
                    x  = -81;
                    y -= 55;
                }
                slotFreeAmount++;
            }
        }

        for (int j = 1; j < 6; j++)         //а здесь мы создаем 5 слотов под ресурсы - итого 37 слотов
        {
            GameObject slot = (GameObject)Instantiate(slots);
            slot.GetComponent <Slot> ().slotNumber       = slotFreeAmount;
            slot.GetComponentInChildren <Text>().enabled = false;
            slot.GetComponent <Slot> ().slotType         = Slot.SlotType.res;
            Slots.Add(slot);
            Blueprints.Add(new Blueprint());
            slot.name             = "slotres " + ((j - 1));
            slot.transform.parent = this.gameObject.transform;
            slot.GetComponent <RectTransform> ().localPosition = new Vector3(x1, y1, 0);
            x1 += 55;
            slotFreeAmount++;
        }
    }
Esempio n. 2
0
    public int x = -110, y = 112;                                 //позиция отрисовки слотов инвентаря
    // Use this for initialization
    void Start()                                                  //получаем доступ ко всем нужным сущностям
    {
        int slotFreeAmount = 0;

        Blueprints  = GameObject.FindGameObjectWithTag("Craft").GetComponent <Craft>().Blueprints;
        Blueprintdb = GameObject.FindGameObjectWithTag("BlueprintDatabase").GetComponent <BlueprintDB>();
        itemdb      = GameObject.FindGameObjectWithTag("ItemDatabase").GetComponent <ItemsDB>();
        for (int i = 1; i < 6; i++)         //создаем и инициализируем 25 слотов. К каждому слоту присваиваем один предмет
        {
            for (int j = 1; j < 6; j++)
            {
                GameObject slot = (GameObject)Instantiate(slots);
                slot.GetComponent <Slot> ().slotNumber = slotFreeAmount;
                slot.GetComponent <Slot> ().slotType   = Slot.SlotType.item;
                Slots.Add(slot);
                Items.Add(new Item());
                slot.name             = "slot " + ((j - 1) + (i - 1) * 5);
                slot.transform.parent = this.gameObject.transform;
                slot.GetComponent <RectTransform> ().localPosition = new Vector3(x, y, 0);
                x += 55;
                if (j == 5)
                {
                    x  = -110;
                    y -= 55;
                }
                slotFreeAmount++;
            }
        }

        for (int i = 0; i < 20; i++)        // добавялем предметы в инвентарь
        {
            for (int j = 0; j < 13; j++)
            {
                addItem(j);
            }
        }
    }