/// <summary> /// Performs a slot swap. /// </summary> /// <param name="targetObject">Target slot.</param> public virtual bool PerformSlotSwap(Object targetObject) { // Get the source slot UISlotBase targetSlot = (targetObject as UISlotBase); // Get the target slot icon Object targetIcon = targetSlot.GetIconAsObject(); // Assign the target slot with this one bool assign1 = targetSlot.Assign(this); // Assign this slot by the target slot icon bool assign2 = this.Assign(targetIcon); // Return the status return(assign1 && assign2); }
/* * 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(); }