How to get the using items in each hand?

wuyan

Member
Hello, How to get the items which is being used in the character's left or right hand aftear integrated?

Sangemdoko provided me with two solutions on discord. So sorry, I'm still confused. So, can you give me a simple example?Thank you so much!?
 
No problem, I took the time to make an example and found something I could improve on for the next update, so great question!

Here is an example component you can try out:
C#:
using Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem;
using Opsive.UltimateCharacterController.Items;
using Opsive.UltimateInventorySystem.Core.InventoryCollections;
using UnityEngine;

public class GetItemInSpecificSlot : MonoBehaviour
{
    [SerializeField] protected Inventory m_UISInventory;
    [SerializeField] protected UltimateInventorySystemBridge m_InventorySystemBridge;

    [ContextMenu("Get Right Hand Item UCC")]
    public void GetItemInSlotUCCway()
    {
        //Get the item at slot 0 (Right Hand)
        var item = m_InventorySystemBridge.GetActiveItem(0);
        
        Debug.Log("UCC: "+item);
        
        Debug.Log("Converted to UIS: "+ConvertUCCItemToUISItem(item));
    }
    
    [ContextMenu("Get Right Hand Item UIS")]
    public void GetItemInSlotUISway()
    {
        //Get the equipment item collection as an ItemSlotCollection
        var itemSlotCollection = m_UISInventory.GetItemCollection("Equipped") as ItemSlotCollection;

        //Check the item slot set to get the index
        for (int i = 0; i < itemSlotCollection.ItemSlotSet.ItemSlots.Count; i++) {
            var itemSlot = itemSlotCollection.ItemSlotSet.ItemSlots[i];

            if (itemSlot.Name == "RightHand") {
                var itemInRightHand = itemSlotCollection.GetItemAtSlot(i);
                Debug.Log("UIS: "+itemInRightHand);
                
                Debug.Log("Converted to UCC: "+ConvertUISItemToUCCItem(itemInRightHand));
            }
        }
        
        //From V1.1 you'll be able to do this,  instead of using the for loop above
        //itemSlotCollection.GetItemInfoAtSlot("RightHand");
    }

    public Item ConvertUISItemToUCCItem(Opsive.UltimateInventorySystem.Core.Item uisItem)
    {
        return m_InventorySystemBridge.GetItem(uisItem, 0);
    }
    
    
    public Opsive.UltimateInventorySystem.Core.Item ConvertUCCItemToUISItem(Item uccItem)
    {
        return uccItem?.ItemIdentifier as Opsive.UltimateInventorySystem.Core.Item;
    }
}

in UCC slot 0 means right hand and slot 1 means left hand by default.

Note that the [ContextMenu("XXX")] are method attributes that Unity provides to let us call functions from the inspector when you right-click on the component. It's very useful to test things quickly.
1603877256067.png

If you have any other issues related to this please let us know and we'll add some functions to make things easier
 
If you have any other issues related to this please let us know and we'll add some functions to make things easier
Hi Sangemdoko,

Thank you so much. It works well.

In addition, if I want the character's attributes to affect the performance of the weapon been using. For example, rifle proficiency affects the recoil of rifle. I modify and restore the related vaule of the weapon's attributes in OnEquipItem and OnUnequipItem event respectively. Is that right? Or is there a better way?
 
That is one way of doing it and it is perfectly fine, especially for complex modification.
But in some cases there is an easier solution where all you want is to replace a property value on your UCC Item by an UIS Item attribute.

To do this you can use the ItemBinding component. You can learn about it in this video:
Or in the documentation
 
Top