コード例 #1
0
    /**********************************************************************************/
    // функция зарядки оружия
    //
    /**********************************************************************************/
    void ChargeWeapon(WEAPON_SLOT slot, WEAPON weaponID, int ammo)
    {
        List <WEAPON>           weaponIds  = null;
        List <ClassicWeaponCtr> weaponCtrs = null;

        switch (slot)
        {
        case WEAPON_SLOT.MAIN:
            weaponIds  = m_mainWeaponIds;
            weaponCtrs = m_mainWeaponCollection;
            break;

        case WEAPON_SLOT.CAPTURE:
            weaponIds  = m_captureWeaponIds;
            weaponCtrs = m_captureWeaponCollection;
            break;

        case WEAPON_SLOT.EXLOSION:
            weaponIds  = m_explosionWeaponIds;
            weaponCtrs = m_explosionWeaponCollection;
            break;

        case WEAPON_SLOT.SPECIAL:
            weaponIds  = m_specialWeaponIds;
            weaponCtrs = m_specialWeaponCollection;
            break;
        }

        // пробуем найти нужное оружие и устанавливаем его индекс
        int  index   = 0;
        bool wasFind = false;

        for (; index < weaponIds.Count; index++)
        {
            WEAPON id = weaponIds[index];
            if (id == weaponID)
            {
                wasFind = true;
                break;
            }
        }

        if (!wasFind)
        {
            Debug.LogError("We cant charge weapon: " + weaponID + " in slot: " + slot);
            return;
        }

        // заряжаем оружие и обновляем UI
        ClassicWeaponCtr wCtr = weaponCtrs[index];

        wCtr.ChargeAmmo(ammo);
        UpdateWeaponSlot(slot);
    }
コード例 #2
0
    /**********************************************************************************/
    // обновляем оружейную систему
    //
    /**********************************************************************************/
    protected void UpdateWeaponSlot(WEAPON_SLOT slot)
    {
        // перебираем коллекцию вооружения с конца к началу
        // первое (наиболее технологичное) оружие с боезапасом устанавливается в слот

        // определяемся со списком оружейных слотов на обновление
        List <WEAPON_SLOT> slotsToUpdate;

        if (slot == WEAPON_SLOT.ALL)
        {
            slotsToUpdate = new List <WEAPON_SLOT> {
                WEAPON_SLOT.MAIN, WEAPON_SLOT.CAPTURE, WEAPON_SLOT.EXLOSION, WEAPON_SLOT.SPECIAL
            };
        }
        else
        {
            slotsToUpdate = new List <WEAPON_SLOT> {
                slot
            };
        }

        // производим обновление
        foreach (var updatedSlot in slotsToUpdate)
        {
            // выбираем элементы, с которыми нам предстоит работать
            List <ClassicWeaponCtr> weaponCollerction;
            List <WEAPON>           weaponIdsCollection;
            PlayerInputCtr.CTR_KEY  KeyToBlock;

            switch (updatedSlot)
            {
            case WEAPON_SLOT.MAIN:
                weaponCollerction   = m_mainWeaponCollection;
                weaponIdsCollection = m_mainWeaponIds;
                KeyToBlock          = PlayerInputCtr.CTR_KEY.FIRE_1;
                break;

            case WEAPON_SLOT.CAPTURE:
                weaponCollerction   = m_captureWeaponCollection;
                weaponIdsCollection = m_captureWeaponIds;
                KeyToBlock          = PlayerInputCtr.CTR_KEY.FIRE_2;
                break;

            case WEAPON_SLOT.EXLOSION:
                weaponCollerction   = m_explosionWeaponCollection;
                weaponIdsCollection = m_explosionWeaponIds;
                KeyToBlock          = PlayerInputCtr.CTR_KEY.FIRE_3;
                break;

            case WEAPON_SLOT.SPECIAL:
                weaponCollerction   = m_specialWeaponCollection;
                weaponIdsCollection = m_specialWeaponIds;
                KeyToBlock          = PlayerInputCtr.CTR_KEY.FIRE_4;
                break;

            default:
                Debug.LogError("Unexpected weapon slot: " + updatedSlot);
                return;
            }

            // итерируем по всеми списку вооружения в поисках подходящего элемента
            for (int i = weaponCollerction.Count - 1; i >= 0; i--)
            {
                ClassicWeaponCtr ctr = weaponCollerction[i];
                if (ctr.State != WeaponController.WEAPON_STATE.EMPTY)
                {
                    switch (updatedSlot)
                    {
                    case WEAPON_SLOT.MAIN:
                        m_mainWeaponCtr = ctr;
                        break;

                    case WEAPON_SLOT.CAPTURE:
                        m_captureWeaponCtr = ctr;
                        break;

                    case WEAPON_SLOT.EXLOSION:
                        m_explosionWeaponCtr = ctr;
                        break;

                    case WEAPON_SLOT.SPECIAL:
                        m_specialWeaponCtr = ctr;
                        break;
                    }

                    UIController.GetInstance().SetWeaponInSlot((int)playerId, updatedSlot, weaponIdsCollection[i]);
                    m_inputCtr.BlockButton(KeyToBlock);
                    break;
                }
            }
        }
    }