Max acceptable

in max acceptable we check if item is not equal to null if so we return 0. He says in the video if item is already set we cant allow another to be placed in the slot. But we can still swap items?

When we implement the interface IDragContainer which overrides IDragDestination and IDragSource we get functionality from DragItem. In the different methods in DragItem, IDragDestination and IDragSource is used. what happens here? does it look for an ex IDragDestination when one of the unity events happen like IEndDragHandler, finds the equipmentslot that this events happens on which is an IDragDestination and runs the methods?

In most cases, the item should absolutely be null when we call MaxAcceptable. This is because what we do first is remove the items from both the source and destination containers and hold them in temporary storage:

            var removedSourceNumber = source.GetNumber();
            var removedSourceItem = source.GetItem();
            var removedDestinationNumber = destination.GetNumber();
            var removedDestinationItem = destination.GetItem();

            source.RemoveItems(removedSourceNumber);
            destination.RemoveItems(removedDestinationNumber);

At this point, both the source and destination containers should be empty. Then we check to see what the maximum number of items they will accept and go from there.

That’s exactly what happens. The script checks to make sure that you’ve stopped on an IDragDestination. If it’s an IDragContainer, then it is (due to inheritance) an IDragDestination. In order to fulfill the interface contract in an IDragDestination, it must have the IDragDestination methods available, so it uses those to make the transfer.

great thnx!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms