Esempio n. 1
0
        /// <summary>
        /// Raises the drop event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public virtual void OnDrop(PointerEventData eventData)
        {
            // Get the source slot
            UISlotBase source = (eventData.pointerPress != null) ? eventData.pointerPress.GetComponent <UISlotBase>() : null;

            // Make sure we have the source slot
            if (source == null || !source.IsAssigned())
            {
                return;
            }

            // Notify the source that a drop was performed so it does not unassign
            source.dropPreformed = true;

            // Check if this slot is enabled and it's drag and drop feature is enabled
            if (!this.enabled || !this.m_DragAndDropEnabled)
            {
                return;
            }

            // Prepare a variable indicating whether the assign process was successful
            bool assignSuccess = false;

            // Normal empty slot assignment
            if (!this.IsAssigned())
            {
                // Assign the target slot with the info from the source
                assignSuccess = this.Assign(source);

                // Unassign the source on successful assignment and the source is not static
                if (assignSuccess && !source.isStatic)
                {
                    source.Unassign();
                }
            }
            // The target slot is assigned
            else
            {
                // If the target slot is not static
                // and we have a source slot that is not static
                if (!this.isStatic && !source.isStatic)
                {
                    // Check if we can swap
                    if (this.CanSwapWith(source) && source.CanSwapWith(this))
                    {
                        // Swap the slots
                        assignSuccess = source.PerformSlotSwap(this);
                    }
                }
                // If the target slot is not static
                // and the source slot is a static one
                else if (!this.isStatic && source.isStatic)
                {
                    assignSuccess = this.Assign(source);
                }
            }

            // If this slot failed to be assigned
            if (!assignSuccess)
            {
                this.OnAssignBySlotFailed(source);
            }
        }
        /*
         * Creator: Yunzheng Zhou
         * Raises the drop event.
         * Parameter: Event data as a PointerEventData variable
         */
        public virtual void OnDrop(PointerEventData eventData)
        {
            playSFX(onUnclickSFX);
            // Get the source slot
            UISlotBase source = (eventData.pointerPress != null) ? eventData.pointerPress.GetComponent <UISlotBase>() : null;

            // Make sure we have the source slot
            if (source == null || !source.IsAssigned())
            {
                return;
            }

            // Notify the source that a drop was performed so it does not unassign
            source.dropPreformed = true;

            // Check if this slot is enabled and it's drag and drop feature is enabled
            if (!this.enabled || !this.m_DragAndDropEnabled)
            {
                return;
            }

            // Prepare a variable indicating whether the assign process was successful
            bool assignSuccess = false;

            // Normal empty slot assignment
            if (!this.IsAssigned())
            {
                // Assign the target slot with the info from the source
                //UISlotBase tmpslot = this;
                source.Assign(this);
                assignSuccess = this.Assign(source);
                //source.Assign(tmpslot);
                // Unassign the source on successful assignment and the source is not static
                //Debug.Log("disappear" + assignSuccess);
                if (assignSuccess && !source.isStatic)
                {
                    int tmp = 0;
                    if (source is UIEquipSlot)
                    {
                        tmp = (source as UIEquipSlot).GetComponent <Test_UIEquipSlot_Assign>().assignItem;
                        (source as UIEquipSlot).GetComponent <Test_UIEquipSlot_Assign>().assignItem = 0;
                        (source as UIEquipSlot).Assign((source as UIEquipSlot).GetComponent <Test_UIEquipSlot_Assign>().itemDatabase.GetByID(0));
                    }
                    if (this is UIItemSlot)
                    {
                        (this as UIItemSlot).GetComponent <Test_UIItemSlot_Assign>().assignItem = tmp;
                        (this as UIItemSlot).Assign((this as UIItemSlot).GetComponent <Test_UIItemSlot_Assign>().itemDatabase.GetByID(0));
                    }

                    //source.Unassign();
                }
            }
            // The target slot is assigned
            else
            {
                //Debug.Log("isAssigned!");
                // If the target slot is not static
                // and we have a source slot that is not static
                if (!this.isStatic && !source.isStatic)
                {
                    // Check if we can swap
                    if (this.CanSwapWith(source) && source.CanSwapWith(this))
                    {
                        // Swap the slots
                        //Debug.Log("swapperform" + this.CanSwapWith(source) + "swaop" + source.CanSwapWith(this));
                        assignSuccess = source.PerformSlotSwap(this);
                    }
                }
                // If the target slot is not static
                // and the source slot is a static one
                else if (!this.isStatic && source.isStatic)
                {
                    assignSuccess = this.Assign(source);
                }
            }

            // If this slot failed to be assigned
            if (!assignSuccess)
            {
                this.OnAssignBySlotFailed(source);
            }

            // Use the event
            eventData.Use();
            //Inventory.instance.UpdateInventory();
        }