// <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); }
public void OnDrop(PointerEventData eventData) { if (eventData.pointerPress == null) { return; } // Try getting slot base component from the selected object UISlotBase slotBase = eventData.pointerPress.gameObject.GetComponent <UISlotBase>(); // 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 = UIEquipSlot.GetSlotWithType(itemSlot.GetItemInfo().EquipType); if (equipSlot != null) { // Use the drop event to handle equip equipSlot.OnDrop(eventData); return; } } } }
/* * Creator: Yunzheng Zhou * Description: * Performs a item swap from one slot to another slot * The destination slot will varied. if the destination slot is vendor inventory * then it means that the player is trading with vendor. * otherwise swap the items. * Parameter: sourceObject object * Return a bool value indicating if slot swap was performed */ public override bool PerformSlotSwap(Object sourceObject) { // Get the source slot UISlotBase sourceSlot = (sourceObject as UISlotBase); //Debug.Log("Itemslot!"); // Get the source item info UIItemInfo sourceItemInfo = null; bool assign1 = false; bool sourceVendor = false; bool thisVendor = false; // Check the type of the source slot if (sourceSlot is UIItemSlot) { sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo(); if ((sourceSlot as UIItemSlot).isVendor) { sourceVendor = true; } if (this.isVendor) { thisVendor = true; } Text gold = Inventory.instance.gold.GetComponent <Text>(); if (sourceVendor && !thisVendor) { gold.text = Convert.ToString(Convert.ToInt32(gold.text) + this.GetItemInfo().price); } if (!sourceVendor && thisVendor) { if (gold.text == "0") { return(false); } if (this.GetItemInfo().price > Convert.ToInt32(gold.text)) { return(false); } gold.text = Convert.ToString(Convert.ToInt32(gold.text) - this.GetItemInfo().price); } // Assign the source slot by this one assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo()); Test_UIItemSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIItemSlot_Assign>(); Test_UIItemSlot_Assign Toitem = this.GetComponent <Test_UIItemSlot_Assign>(); int id = sourceItem.assignItem; sourceItem.assignItem = Toitem.assignItem; Toitem.assignItem = id; /*if (sourceItem.assignItem == 0) * { * sourceSlot.Unassign(); * } * if (Toitem.assignItem == 0) * { * this.Unassign(); * }*/ } else if (sourceSlot is UIEquipSlot) { sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo(); if (this.GetItemInfo().gemSlot != (sourceSlot as UIEquipSlot).slotindex) { return(false); } if (this.GetItemInfo().EquipType == 0) { return(false); } // Assign the source slot by this one assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo()); if (!assign1) { return(false); } Test_UIEquipSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIEquipSlot_Assign>(); Test_UIItemSlot_Assign Toitem = this.GetComponent <Test_UIItemSlot_Assign>(); int id = sourceItem.assignItem; sourceItem.assignItem = Toitem.assignItem; Toitem.assignItem = id; if ((int)sourceSlot.GetComponent <UIEquipSlot>().equipType == 1) { Player.instance.playerController.WeaponState = 1; } //Debug.Log("source is " + sourceItem.assignItem); //Debug.Log("this is " + this + " id is " + Toitem.assignItem); } //Debug.Log("perform swap"); // Assign this slot by the source slot for (int i = 4; i < 8; i++) { EquipmentManager.instance.EquipmentUpdate(i); } bool assign2 = this.Assign(sourceItemInfo); //Debug.Log("assign1 is " + assign1 + "assign2 is " + assign2); // Return the status //Inventory.instance.UpdateInventory(); return(assign1 && assign2); }
/// <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(); }