コード例 #1
0
    public void SwapPrimaryWeapon(Weapon weapon)
    {
        var droppedItem = (GameObject)Instantiate(GetPrimaryWeapon().DropItem.gameObject, equippedGunMesh.transform.position, equippedGunMesh.transform.rotation);
        inventory.Ammunition[GetPrimaryWeapon().AmmunitionType] += GetPrimaryWeapon().GetClipRemaining();
        droppedItem.GetComponent<Weapon>().AmmoAmount = 0;
        droppedItem.GetComponent<Weapon>().Init();
        var equippedRigidbody = droppedItem.GetComponent<Rigidbody>();

        //Debug.Log("PICKING UP: " + weapon.Item.Name);
        //Debug.Log("INVENTORY");
        for (var i = 0; i < inventory.Weapons.Count; i++)
        {
            //Debug.LogFormat("{0} - {1}", i, inventory.Weapons[i].Name);
            if (inventory.Weapons[i].Name == GetPrimaryWeapon().Name)
            {
                //Debug.Log("REMOVE AT: " + i);
                inventory.Weapons.RemoveAt(i);
            }
        }

        weapon.Give(inventory);
        /*
        Debug.Log("UPDATED INVENTORY");
        for (var i = 0; i < inventory.Weapons.Count; i++)
        {
            Debug.LogFormat("{0} - {1}", i, inventory.Weapons[i]);
        }
        */
        equippedRigidbody.isKinematic = false;
        droppedItem.transform.parent = World.CollectiblesContainer;
        StartCoroutine(DelayedDroppedEnable(droppedItem, 0.5f));
        Destroy(equippedGunMesh);

        weaponInstances[selectedWeaponIndex] = InitializeWeapon(weapon.Item);
        SelectWeapon(selectedWeaponIndex);
    }