Ucc_v.2.2.7 Integration Uis_v.1.1.1

Hi,
Errors messages report:

-In "ItemViewSlotsContainerItemActionBindingBase.cs"
At line 204 ("protected virtual void InvokeActionInternal(int itemSlotIndex, int itemActionIndex)")
I'm think if you add:
"if (itemAction == null)
return;"
This would avoid the error when you press an empty hotbar key.

-And when you drop an item assigned at hotbar, I think you are missing delete them in hotbar and there make an error if you press the assigned key.

But you've made a lot of progress, I'll finally be able to use it, if I find other errors or anything else I'll let you know.
Thanks for this nice pair of Ucc and Uis scripts.
?
 
Last edited:
Thank you for reporting this bug, I've actually already fixed it,excatly how you mentioned, it will be part of the v1.1.2 update which should come out either this week or the next.

I'm glad you're enjoying UIS and UCC :)
 
Cool ?

In "ItemHotbar.cs" I've modified this:
/// <summary>
/// Assign an item to a slot.
/// </summary>
/// <param name="itemInfo">The item.</param>
/// <param name="slot">The item slot.</param>
public virtual void AssignItemToSlot(ItemInfo itemInfo, int slot)
{
UnassignItemToSlot(itemInfo);
m_ItemViewSlotsContainer.AddItem(itemInfo, slot);
}

/// <summary>
/// Unassign an item to a slot.
/// </summary>
/// <param name="itemInfo">The item.</param>
public virtual void UnassignItemToSlot(ItemInfo itemInfo)
{
int slot;

while ((slot = m_ItemViewSlotsContainer.GetItemIndex(itemInfo)) != -1)
{
m_ItemViewSlotsContainer.RemoveItem(itemInfo, slot);
}
}

/// <summary>
/// UnAssign an item to a slot.
/// </summary>
/// <param name="itemInfo">The item.</param>
/// <param name="slot">The item slot.</param>
public virtual void UnAssignItemToSlot(ItemInfo itemInfo, int slot)
{
if (slot == m_ItemViewSlotsContainer.GetItemIndex(itemInfo))
{
UnassignItemToSlot(itemInfo);
}
else
{
AssignItemToSlot(itemInfo, slot);
}
}

This allowed me to create :
"UnAssignHotbarItemAction.cs" I've just copying "AssignHotbarItemAction.cs" and changing:
/// <summary>
/// Invoke action after waiting for index slot.
/// </summary>
/// <param name="itemInfo">The item.</param>
/// <param name="itemUser">The item user (can be null).</param>
/// <param name="awaitedValue">The index slot.</param>
protected override void InvokeWithAwaitedValue(ItemInfo itemInfo, ItemUser itemUser, int awaitedValue)
{
m_ItemHotbar.UnAssignItemToSlot(itemInfo, awaitedValue);
}

Finally for fixed error when drop item in hotbar i've modified "CharacterQuantityDropItemAction.cs":
/// <summary>
/// Invoke with the action with the awaited value.
/// </summary>
/// <param name="itemInfo">The itemInfo.</param>
/// <param name="itemUser">The item user.</param>
/// <param name="awaitedValue">The value that was waited for.</param>
protected override void InvokeWithAwaitedValue(ItemInfo itemInfo, ItemUser itemUser, int awaitedValue)
{
if (awaitedValue <= 0) { return; }

itemInfo = (awaitedValue, itemInfo);

foreach (ItemHotbar itemHotbar in Resources.FindObjectsOfTypeAll(typeof(ItemHotbar)))
{
if (itemHotbar.ItemUser == itemUser)
{
itemHotbar.UnassignItemToSlot(itemInfo);
}
}

EventHandler.ExecuteEvent<ItemInfo>(itemInfo.Inventory.gameObject, "OnItemActionDrop", itemInfo);
}

It's not the best solution but that work lol
If it can inspire you ;)

Tomorrow I go to see for Rewired, UMA and/or an Localization Integration.
 
Interesting, those all look like good solutions to me, I might look into something similar.

Just one note I don't think you should be using this:
foreach (ItemHotbar itemHotbar in Resources.FindObjectsOfTypeAll(typeof(ItemHotbar)))

Instead I would find the PanelManager -> Item Hotbar Panel -> Item Hotbar. I believe it will be more efficient. If for some reason you have multiple Item Hotbars in the game then I would cache them all the first time you search such that you do not have to call Resources each time you drop an item.

On my side I will look as to why the hotbar does not update correctly when dropping the item.

I'm actually refactoring the Item Hotbar class due to other problems so I'm glad you found this issue now.
I'll add instructions in the release notes as to how to update the hotbar to make it work correctly.
I think we will release the next update later this week or early next week
 
I like your inventory but I'm still having trouble using it...

Another thing that caught my attention is that as soon as you have a weapon in the inventory it can be placed in the holster, on my integration of InventoryPro and Rucksack I make the weapons appear only when they are equipped and I use ItemAbilities to switch between them.

But the magic system associated with the Hotbar is great!

Finally how can you create an inventory with ItemSlotCollection? Or just limit the number of slots and/or the weight...

Keep it that way, you're doing a great job! ?
 
The way the integration works right now is that it spawns all the items that equippable on the character, then the character actually switches the equipped item by moving & activating/deactivating the equippable items.

We will look into improving this in the future such that users can have more control over the bridge between UCC and UIS.

As for limiting the items that can be added you may use a GroupItemRestrictionObject or if you wish to have more control you may use your own component with the IItemRestriction interface. This allows you to control if items can be added/removed to/from the inventory. You can learn more about it here:

Of course you can create your very own custom Item Collection if you wish to have total control over your items.

(There is currently a bug that happens when switching the ItemCollection of the character when bound to the UCC/UIS bridge component, you may ingore it, it will be fixed in the next update)
 
I will return to my Mirror and Rucksack integrations for Ucc.
Currently I've copied and translated PUN to Mirror,
But if I redo everything on a client-server architecture, I could sell it?
Sorry I know this is not the appropriate topic but I will create the appropriate topic when I'm ready, if you permit me to do that...
:unsure:
 
You can sell it if it's an independent asset which does not contain any of our source code (Similar to our PUN add-on of UCC)
Just give us a heads up to know about your progress and any hurdles you come up with :)
 
I know this is an old thread but when I was searching for a weight restriction this is the thread I found. I decided to implement one into our game, and thought I'd share what I'm using. It probably needs some optimizations, but basically I added a float attribute to all items in our game for the weight of the item. I then added this restriction to our players:
C#:
/// ---------------------------------------------
/// Ultimate Inventory System
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------

namespace Opsive.UltimateInventorySystem.Core.InventoryCollections
{
    using Opsive.Shared.Utility;
    using Opsive.UltimateInventorySystem.Core.DataStructures;
    using System;
    using UnityEngine;

    [Serializable]
    public class ItemCollectionWeightRestriction : IItemRestriction
    {
        [Tooltip("The itemCollections affected by this restriction.")]
        [SerializeField] protected string[] m_ItemCollectionNames;

        [SerializeField] int m_MaxWeightLimit = 100;

        [System.NonSerialized] protected IInventory m_Inventory;
        [System.NonSerialized] protected ResizableArray<ItemCollection> m_ItemCollections;
        [System.NonSerialized] protected bool m_Initialized;

        /// <summary>
        /// Initialize with the Inventory.
        /// </summary>
        /// <param name="inventory">The inventory.</param>
        /// <param name="force">Force Initialization.</param>
        public void Initialize(IInventory inventory, bool force)
        {
            if (m_Initialized && !force && inventory == m_Inventory) { return; }

            if (m_Inventory != inventory)
            {
                m_Inventory = inventory;
                if (m_ItemCollections == null) { m_ItemCollections = new ResizableArray<ItemCollection>(); }
                m_ItemCollections.Clear();
                for (int i = 0; i < m_ItemCollectionNames.Length; i++)
                {
                    var match = m_Inventory.GetItemCollection(m_ItemCollectionNames[i]);
                    if (match == null) { continue; }
                    m_ItemCollections.Add(match);
                }
            }

            m_Initialized = true;
        }

        /// <summary>
        /// Can the Item be added to the item collection?
        /// </summary>
        /// <param name="itemInfo">The item to add.</param>
        /// <param name="receivingCollection">The item collection the item is added to.</param>
        /// <returns>The item that can be added.</returns>
        public ItemInfo? CanAddItem(ItemInfo itemInfo, ItemCollection receivingCollection)
        {
            if (m_ItemCollections.Contains(receivingCollection) == false) { return itemInfo; }

            var item = itemInfo.Item;

            float currentCollectionWeight = CurrentWeight(receivingCollection);
            Debug.Log("Collection weight for " + receivingCollection.Name + " is " + currentCollectionWeight);
            float itemWeight = 1;
            item.TryGetAttributeValue("Weight", out itemWeight);
            if (itemWeight < 1)
            {
                itemWeight = 1;
                Debug.Log("UH OH Weight of " + item.name + " was 0 and changed back to 1");
            }

            float availableWeight = m_MaxWeightLimit - currentCollectionWeight;
        
            int maxAmountThatCanBeAdded = Mathf.RoundToInt(availableWeight / itemWeight);

            int itemAmountThatFits = Mathf.Min(itemInfo.Amount, maxAmountThatCanBeAdded);

            Debug.Log("Current weight is " + currentCollectionWeight + " and can only fit " + itemAmountThatFits + " of " + item.name);
            if (itemAmountThatFits == 0)
            {
                return null;
            }
            return (itemAmountThatFits, itemInfo);
        }

        float CurrentWeight(ItemCollection itemCollection)
        {
            float weight = 0;
            var stacks = itemCollection.GetAllItemStacks();
            Debug.Log("Stack count is "+  stacks.Count);
            for (int i = 0; i < stacks.Count; i++)
            {
                if (stacks[i].Item.TryGetAttributeValue("Weight", out float itemWeight))
                {
                    Debug.Log("Weight of " + stacks[i].Item + " is " + itemWeight);
                    weight += (itemWeight * stacks[i].Amount);
                }
                else
                {
                    //Couldnt find a weight for the item, adding a default value of 1 per amount.
                    weight += stacks[i].Amount;
                }

            }
            return weight;
        }

        /// <summary>
        /// Can the Item be removed.
        /// </summary>
        /// <param name="itemInfo">The item info.</param>
        /// <returns>The item Info.</returns>
        public ItemInfo? CanRemoveItem(ItemInfo itemInfo)
        {
            return itemInfo;
        }
        /// <summary>
        /// Easy to read string.
        /// </summary>
        /// <returns>String representation.</returns>
        public override string ToString()
        {
            var weightLimit = $" Max Weight Limit {m_MaxWeightLimit}";

            if (m_ItemCollectionNames == null || m_ItemCollectionNames.Length == 0)
            {
                return "EMPTY" + weightLimit;
            }

            var collectionNames = m_ItemCollectionNames[0];
            for (int i = 1; i < m_ItemCollectionNames.Length; i++)
            {
                collectionNames = ", " + m_ItemCollectionNames[i];
            }

            return collectionNames + " " + weightLimit;
        }
    }
}
 
Back
Top