// <summary> /// Performs a slot swap. /// </summary> /// <returns><c>true</c>, if slot swap was performed, <c>false</c> otherwise.</returns> /// <param name="sourceSlot">Source slot.</param> public override bool PerformSlotSwap(Object sourceObject) { // Get the source slot UISlotBase sourceSlot = (sourceObject as UISlotBase); // Get the source item info UIItemInfo sourceItemInfo = null; bool assign1 = false; // Check the type of the source slot if (sourceSlot is UIItemSlot) { sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo(); // Assign the source slot by this one assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo()); } else if (sourceSlot is UIEquipSlot) { sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo(); // Assign the source slot by this one assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo()); } // Assign this slot by the source slot bool assign2 = this.Assign(sourceItemInfo); // Return the status return(assign1 && assign2); }
/// <summary> /// Raises the pointer enter event. /// </summary> /// <param name="eventData">Event data.</param> public void OnPointerEnter(PointerEventData eventData) { if (this.m_HintText == null) { return; } // Check if we are dragging if (eventData.dragging) { // Try getting slot base component from the selected object UISlotBase slotBase = this.ExtractSlot(eventData); // If we have a slot, we should show the hint if (slotBase != null) { // Show the hint if (this.m_Fading) { this.m_HintText.CrossFadeAlpha(1f, this.m_FadeDuration, true); } else { this.m_HintText.canvasRenderer.SetAlpha(1f); } // Set the hint state this.m_HintState = HintState.Shown; } } }
/// <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); }
/// <summary> /// Extracts a base slot based on the event data. /// </summary> /// <returns>The slot.</returns> /// <param name="eventData">Event data.</param> private UISlotBase ExtractSlot(PointerEventData eventData) { if (eventData.pointerPress == null) { return(null); } // Try getting slot base component from the selected object UISlotBase slotBase = eventData.pointerPress.GetComponent <UISlotBase>(); // Check if we failed to get a slot from the pressed game object directly if (slotBase == null) { slotBase = eventData.pointerPress.GetComponentInChildren <UISlotBase>(); } return(slotBase); }
/// <summary> /// Raises the drop event. /// </summary> /// <param name="eventData">Event data.</param> public void OnDrop(PointerEventData eventData) { if (eventData.pointerPress == null) { return; } // Try getting slot base component from the selected object UISlotBase slotBase = this.ExtractSlot(eventData); // Check if we have a slot if (slotBase == null) { return; } // Determine the type of slot we are dropping here if (slotBase is UIItemSlot) { UIItemSlot itemSlot = (slotBase as UIItemSlot); // Make sure the slot we are dropping is valid and assigned if (itemSlot != null && itemSlot.IsAssigned()) { // Try finding a suitable slot to equip UIEquipSlot equipSlot = this.GetSlotByType(itemSlot.GetItemInfo().EquipType); if (equipSlot != null) { // Use the drop event to handle equip equipSlot.OnDrop(eventData); // Hide the hint this.HideHint(); // Break out of the method return; } } } }
/// <summary> /// Assign the specified slot by object. /// </summary> /// <param name="source">Source.</param> public virtual bool Assign(Object source) { if (source is UISlotBase) { UISlotBase sourceSlot = source as UISlotBase; if (sourceSlot != null) { // Assign by sprite or texture if (sourceSlot.GetIconSprite() != null) { return(this.Assign(sourceSlot.GetIconSprite())); } else if (sourceSlot.GetIconTexture() != null) { return(this.Assign(sourceSlot.GetIconTexture())); } } } return(false); }
/// <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() || !source.dragAndDropEnabled) { 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); } }