Drag to button to delete item.

Niroan

Member
Hello i have and inventory system.

I want be able to drag from Grid Inventory to a button that looks like a trash can, then show a pop to confirm deletion.
After this delete item from inventory.
 
You can learn morea bout drag&drop in this video:
and in the documentation:

To create your Trash Can you can inspire yourself from the "Scene Drop Action Item View Slot" prefab. You will find it in the RPG schema assets. It uses an Item View Slot + Item View Drop Handler + Item View Slot Drop Handler Binding.

You can use a custom Drop Action to open a popup either by spawning a prefab or by enabling a popup in the scene. You should have a reference to the ItemViewDropHandler component inside the custom Drop Action you will make. Then you can remove the item once you press yes, or cancel if you press no.

You can use a "ConfirmationPopUp" prefab if you want or you can create your own script that's up to you.
I hope that helps
 
You can learn morea bout drag&drop in this video:
and in the documentation:

To create your Trash Can you can inspire yourself from the "Scene Drop Action Item View Slot" prefab. You will find it in the RPG schema assets. It uses an Item View Slot + Item View Drop Handler + Item View Slot Drop Handler Binding.

You can use a custom Drop Action to open a popup either by spawning a prefab or by enabling a popup in the scene. You should have a reference to the ItemViewDropHandler component inside the custom Drop Action you will make. Then you can remove the item once you press yes, or cancel if you press no.

You can use a "ConfirmationPopUp" prefab if you want or you can create your own script that's up to you.
I hope that helps
Im not that good at coding your plugin, how would i achieve this easy? I spend last 5 days rebuilding after update. please help me.
I know i can just look at prefab, but i dont understand the way your plugin is build. For me its not logic, there are SOOOO many scripts on each object that my head explodes. It might be easy for you cause you build it...
 
I think you need to break what you are trying to do in little pieces such that you have an easier time implementing it step by step.

By watching the video I linked above you should know how the drag&dop system works, and using the "Scene Drop Action Item View Slot" prefab you have something already setup to detect drop events.

So the only custom thing you need to do is create a custom Drop Action to know when you need to make the confirmation popup appear.
As specified in the documentation all you need to do to create a custom Drop Action is to inherit the "ItemViewDropAction" class.

In the source code have a look at the built-in ItemViewDropActions to know how they are written.

The easiest way to implement this is for you to create a custom component that you place next to your ItemViewDrophandler component (on the prefab I mentioned previously, make sure to duplicate the prefab before obviously or it will be overwritten after an update).
You'll then use the your custom ItemViewDropAction, inside the overriden "Drop" function, to call a function on that custom component. And you can pass in the item that was selected as argument. it's the "itemViewDropHandler.SourceItemInfo".

So something around those lines (Not Tested):
Code:
[Serializable]
    public class MyCustomItemViewDropAction : ItemViewDropAction
    {

        /// <summary>
        /// Drop Action.
        /// </summary>
        /// <param name="itemViewDropHandler">The Item View Drop Handler.</param>
        public override void Drop(ItemViewDropHandler itemViewDropHandler)
        {
            var myCustomComponent = itemViewDropHandler.GetComponent<MyCustomComponent>();
            if (myCustomComponent == null) {
                Debug.LogError("The component was not found.")
                return;
            }

            var itemInfo = itemViewDropHandler.SourceItemInfo;
            myCustomComponent.TryConfirmDropRemove(itemInfo);
        }

        /// <summary>
        /// To string.
        /// </summary>
        /// <returns>The string.</returns>
        public override string ToString()
        {
            return "My Custom Try Confirm Drop";
        }
where MyCustomComponent is the custom component you will be adding next to your ItemViewDropHandler component.

I hope that helps
 
Top