// -------------------------------------------------------------------------------------------- // Name : UseBackpackItem // Desc : Uses a backpack item. // -------------------------------------------------------------------------------------------- public override bool UseBackpackItem(int mountIndex, bool playAudio = true) { // Is the selected slot valid to be consumed if (mountIndex < 0 || mountIndex >= _backpack.Count) { return(false); } // Get weapon mount and return if no weapon assigned InventoryBackpackMountInfo backpackMountInfo = _backpack[mountIndex]; if (backpackMountInfo.Item == null) { return(false); } // Get the prefab from the app dictionary for this item InventoryItem backpackItem = backpackMountInfo.Item; // Tell the item to consume itself Vector3 position = _playerPosition != null ? _playerPosition.value : Vector3.zero; InventoryItem replacement = backpackItem.Use(position, playAudio); // Assign either null or a replacement item to that inventory slot _backpack[mountIndex].Item = replacement; // Mission Success return(true); }
// -------------------------------------------------------------------------------------------- // Name : OnAfterDeserialize() // Desc : We use this function so at runtime we clone the Mounts into copies that we can // mutate without any affecting our original lists as defined in the inpsector. // Note : This has to be a deep copy as having two seperate lists referencing the same // Mount objects will still mutate the original data. // -------------------------------------------------------------------------------------------- public void OnAfterDeserialize() { // Clear our runtime lists _weapons.Clear(); _ammo.Clear(); _backpack.Clear(); _recordings.Clear(); // Clone inspector lists into runtime lists foreach (InventoryWeaponMountInfo info in _weaponMounts) { InventoryWeaponMountInfo clone = new InventoryWeaponMountInfo(); clone.Condition = info.Condition; clone.InGunRounds = info.InGunRounds; clone.Weapon = info.Weapon; _weapons.Add(clone); // This implementation supports only two weapons so ignore any others specified if (_weapons.Count == 2) { break; } } foreach (InventoryAmmoMountInfo info in _ammoMounts) { InventoryAmmoMountInfo clone = new InventoryAmmoMountInfo(); clone.Ammo = info.Ammo; clone.Rounds = info.Rounds; _ammo.Add(clone); } foreach (InventoryBackpackMountInfo info in _backpackMounts) { InventoryBackpackMountInfo clone = new InventoryBackpackMountInfo(); clone.Item = info.Item; _backpack.Add(clone); } foreach (InventoryItemAudio recording in _audioRecordings) { _recordings.Add(recording); } // Reset the audio recording selection _activeAudioRecordingIndex = -1; }
// -------------------------------------------------------------------------------- // Name : OnPointerClickBackpackSlot // Desc : Called when user clicks on a Backpack Mount's frame // -------------------------------------------------------------------------------- public void OnClickBackpackMount(Image image) { // Get mountfrom name int mount; if (image == null || !int.TryParse(image.name, out mount)) { Debug.Log("OnClickBackpackError : Could not parse image name as INT"); return; } // Is this a valid mount that's been clicked if (mount >= 0 && mount < _backpackMounts.Count) { // Get Inventory Item InventoryBackpackMountInfo itemMount = _inventory.GetBackpack(mount); // No highlight if nothing at this slot if (itemMount == null || itemMount.Item == null) { return; } // We are clicking on the selected item so unselect if (mount == _selectedMount && _selectedPanelType == InventoryPanelType.Backpack) { Invalidate(); image.color = _backpackMountHover; image.fillCenter = false; DisplayGeneralDescription(itemMount.Item); } else { Invalidate(); _selectedPanelType = InventoryPanelType.Backpack; _selectedMount = mount; image.color = _backpackMountColor; image.fillCenter = true; DisplayGeneralDescription(itemMount.Item); } } }
// ------------------------------------------------------------------------------------------- // Name : OnEnterBackpackMount // Desc : Called when mouse enters a Backpack Mount's Frame // ------------------------------------------------------------------------------------------- public void OnEnterBackpackMount(Image image) { Debug.Log("dkjdkjfkldkfj"); int mount; // Get the slot index from the name of the object passed if (image == null || !int.TryParse(image.name, out mount)) { Debug.Log("OnEnterBackpackMount Error! Could not parse image name as INT"); return; } // Valid Index? if (mount >= 0 && mount < _backpackMounts.Count) { // Get Inventory Item InventoryBackpackMountInfo itemMount = _inventory.GetBackpack(mount); // No highlight if nothing at this slot if (itemMount == null || itemMount.Item == null) { return; } // Set the color of the frame of this slot to the hover color if (_selectedPanelType != InventoryPanelType.Backpack || _selectedMount != mount) { image.color = _backpackMountHover; } // If the selected panel is not none then something else is selected at the // moment so don't update the info pane if (_selectedPanelType != InventoryPanelType.None) { return; } // Update Description Window DisplayGeneralDescription(itemMount.Item); } }
// -------------------------------------------------------------------------------------------- // Name : DropBackpackItem // Desc : Drop the item at the specified mount in the Backpack // -------------------------------------------------------------------------------------------- public override void DropBackpackItem(int mountIndex, bool playAudio = true) { if (mountIndex < 0 || mountIndex >= _backpack.Count) { return; } // Chck we have a valid BackPack mount in the inventory InventoryBackpackMountInfo itemMount = _backpack[mountIndex]; if (itemMount == null || itemMount.Item == null) { return; } // Put it in the scene Vector3 position = _playerPosition != null ? _playerPosition.value : Vector3.zero; position += _playerDirection != null ? _playerDirection.value : Vector3.zero; itemMount.Item.Drop(position, playAudio); // Nullify the slot so it is empty _backpack[mountIndex].Item = null; }
// -------------------------------------------------------------------------------------------- // Name : Invalidate // Desc : This function updates the UI so all elements reflect the current state of the // user's inventory. This function also resets the Inventory to an unselected // state. // -------------------------------------------------------------------------------------------- protected virtual void Invalidate() { // Make sure its initialized before its is rendered for the first time if (!_isInitialized) { Initialize(); } // Reset Selections _selectedPanelType = InventoryPanelType.None; _selectedMount = -1; // Deactivate Description Panels if (_generalDescriptionLayout.LayoutContainer != null) { _generalDescriptionLayout.LayoutContainer.SetActive(false); } if (_weaponDescriptionLayout.LayoutContainer != null) { _weaponDescriptionLayout.LayoutContainer.SetActive(false); } // Deactivate the action buttons if (_actionButton1.GameObject != null) { _actionButton1.GameObject.SetActive(false); } if (_actionButton2.GameObject != null) { _actionButton2.GameObject.SetActive(false); } // Clear the Weapon Mounts for (int i = 0; i < _weaponMounts.Count; i++) { if (_weaponMounts[i] != null) { if (_weaponMountImages[i] != null) { _weaponMountImages[i].sprite = null; } if (_weaponMountNames[i] != null) { _weaponMountNames[i].text = ""; } if (_weaponMountSliders[i] != null) { _weaponMountSliders[i].enabled = false; } _weaponMounts[i].SetActive(false); _weaponMounts[i].transform.GetComponent <Image>().fillCenter = false; } } // Iterate over the UI Backpack mounts and set all to empty and unselected for (int i = 0; i < _backpackMounts.Count; i++) { // Clear sprite and deactivate mount if (_backpackMountImages[i] != null) { _backpackMountImages[i].gameObject.SetActive(false); _backpackMountImages[i].sprite = null; } // Enable the text for this slot that says "EMPTY" if (_backpackMountText[i] != null) { _backpackMountText[i].gameObject.SetActive(true); } // Make all mounts look unselected if (_backpackMounts[i] != null) { // Get the image of the mount itself (the frame) Image img = _backpackMounts[i].GetComponent <Image>(); if (img) { img.fillCenter = false; img.color = _backpackMountColor; } } } // Configure the ammo slots for (int i = 0; i < _ammoMounts.Count; i++) { // Clear Sprite and deactivate mount if (_ammoMounts[i] != null) { if (_ammoMountImages[i]) { _ammoMountImages[i].gameObject.SetActive(false); _ammoMountImages[i].sprite = null; } } // Enable the text for this slot that says "EMPTY" if (_ammoMountEmptyText[i] != null) { _ammoMountEmptyText[i].gameObject.SetActive(true); } if (_ammoMountRoundsText[i] != null) { _ammoMountRoundsText[i].gameObject.SetActive(false); } // Give Mount Frame unselected look if (_ammoMounts[i] != null) { Image img = _ammoMounts[i].GetComponent <Image>(); if (img) { img.fillCenter = false; img.color = _ammoMountColor; } } } // Other PDA things if (_pDAReferences._autoplayOnPickup) { if (_audioPlayOnPickup) { _pDAReferences._autoplayOnPickup.isOn = true; } else { _pDAReferences._autoplayOnPickup.isOn = false; } } // Finally update the status panel if (_statusPanelUI.HealthSlider) { _statusPanelUI.HealthSlider.value = _health.value; } if (_statusPanelUI.InfectionSlider) { _statusPanelUI.InfectionSlider.value = _infection.value; } if (_statusPanelUI.StaminaSlider) { _statusPanelUI.StaminaSlider.value = _stamina.value; } if (_statusPanelUI.FlashlightSlider) { _statusPanelUI.FlashlightSlider.value = _flashlight.value; } if (_statusPanelUI.NightVisionSlider) { _statusPanelUI.NightVisionSlider.value = _nightvision.value; } // DO we have a valid Inventory Referenc. If so...let's paint it if (_inventory != null) { // Configure Weapons Panel by iterating through each mount for (int i = 0; i < _weaponMounts.Count; i++) { // Do we have a weapon mount here if (_weaponMounts[i] != null) { // Get the matching mount and weapon data from the inventory InventoryWeaponMountInfo weaponMountInfo = _inventory.GetWeapon(i); InventoryItemWeapon weapon = null; if (weaponMountInfo != null) { weapon = weaponMountInfo.Weapon; } // No weapon info here to skip this mount if (weapon == null) { continue; } // Set sprite and name of weapon if (_weaponMountImages[i] != null) { _weaponMountImages[i].sprite = weapon.inventoryImage; } if (_weaponMountNames[i] != null) { _weaponMountNames[i].text = weapon.inventoryName; } // If its a melee weapon then deactivate the entire AmmoInfo section of the UI // otherwise Enabled it and show the Reload Type and Rounds in Gun if (_weaponMountAmmoInfo[i] != null) { if (weapon.weaponFeedType == InventoryWeaponFeedType.Melee) { _weaponMountAmmoInfo[i].SetActive(false); } else { // Activate Mount _weaponMountAmmoInfo[i].SetActive(true); // Display Reload Type if (_weaponMountReloadType[i] != null) { _weaponMountReloadType[i].text = weapon.reloadType.ToString(); } if (_weaponMountRounds[i] != null) { _weaponMountRounds[i].text = weaponMountInfo.InGunRounds + " / " + weapon.ammoCapacity; } } } // Update the condition slider if (_weaponMountSliders[i] != null) { _weaponMountSliders[i].enabled = true; _weaponMountSliders[i].value = weaponMountInfo.Condition; } _weaponMounts[i].SetActive(true); } } // Configure Ammo Mounts for (int i = 0; i < _ammoMounts.Count; i++) { // Clear Sprite and deactivate mount if (_ammoMounts[i] != null) { // Get the ammo and it's mount info for this mount InventoryAmmoMountInfo ammoMountInfo = _inventory.GetAmmo(i); InventoryItemAmmo ammo = null; if (ammoMountInfo != null) { ammo = ammoMountInfo.Ammo; } // No weapon at this mount so skip if (ammo == null) { continue; } // Set image if (_ammoMountImages[i]) { _ammoMountImages[i].gameObject.SetActive(true); _ammoMountImages[i].sprite = ammoMountInfo.Ammo.inventoryImage; } // Set and Enable Rounds Text if (_ammoMountRoundsText[i] != null) { _ammoMountRoundsText[i].gameObject.SetActive(true); _ammoMountRoundsText[i].text = ammoMountInfo.Rounds.ToString(); } // Disable Empty text if (_ammoMountEmptyText[i] != null) { _ammoMountEmptyText[i].gameObject.SetActive(false); } } } // Iterate over the UI Backpack mounts and set all to empty and unselected for (int i = 0; i < _backpackMounts.Count; i++) { if (_backpackMounts[i] != null) { InventoryBackpackMountInfo backpackMountInfo = _inventory.GetBackpack(i); InventoryItem item = null; if (backpackMountInfo != null) { item = backpackMountInfo.Item; } if (item != null) { // Set sprite and activate mount if (_backpackMountImages[i] != null) { _backpackMountImages[i].gameObject.SetActive(true); _backpackMountImages[i].sprite = item.inventoryImage; } // Disable the text for this slot that says "EMPTY" if (_backpackMountText[i] != null) { _backpackMountText[i].gameObject.SetActive(false); } } } } } }