/// <summary> /// Assign the slot by the passed source slot. /// </summary> /// <param name="source">Source.</param> public override bool Assign(Object source) { if (source is UIItemSlot) { UIItemSlot sourceSlot = source as UIItemSlot; // Check if the equipment type matches the target slot if (!this.CheckEquipType(sourceSlot.GetItemInfo())) { return(false); } return(this.Assign(sourceSlot.GetItemInfo())); } else if (source is UIEquipSlot) { UIEquipSlot sourceSlot = source as UIEquipSlot; // Check if the equipment type matches the target slot if (!this.CheckEquipType(sourceSlot.GetItemInfo())) { return(false); } return(this.Assign(sourceSlot.GetItemInfo())); } // Default return(false); }
void Awake() { if (this.slot == null) { this.slot = this.GetComponent <UIEquipSlot>(); } }
/* * Creator: Yunzheng Zhou * Insert new potion into slot and interact with GUI * Parameter: slot - UIEquipSlot variable, * id - an int variable indicating the item id * testslot - Test_UIEquipSlot_Assign variable */ public void fillinPotionslot(UIEquipSlot slot, int id, Test_UIEquipSlot_Assign testslot) { for (int i = 0; i < 40; i++) { if (Inventory.instance.items[i].itemID == id) { Inventory.instance.setdefault(i); slot.Assign(itemdatabase.GetByID(id)); testslot.assignItem = id; InventoryGUI.instance.items[i] = id; InventoryGUI.instance.gameslot[i].GetComponent <UIItemSlot>().Assign(itemdatabase.GetByID(0)); InventoryGUI.instance.gameslot[i].GetComponent <Test_UIItemSlot_Assign>().assignItem = 0; return; } } testslot.assignItem = 0; slot.Assign(itemdatabase.GetByID(0)); for (int i = 0; i < 5; i++) { if (EquipmentManager.instance.potionSlot[i].GetComponent <Test_UIEquipSlot_Assign>().assignItem == 0) { EquipmentManager.instance.Potions[i] = null; } } }
/// <summary> /// Raises the tooltip event. /// </summary> /// <param name="show">If set to <c>true</c> show.</param> public override void OnTooltip(bool show) { UITooltip.InstantiateIfNecessary(this.gameObject); // Handle unassigned if (!this.IsAssigned()) { // If we are showing the tooltip if (show) { UITooltip.AddTitle(UIEquipSlot.EquipTypeToString(this.m_EquipType)); UITooltip.SetHorizontalFitMode(ContentSizeFitter.FitMode.PreferredSize); UITooltip.AnchorToRect(this.transform as RectTransform); UITooltip.Show(); } else { UITooltip.Hide(); } } else { // Make sure we have spell info, otherwise game might crash if (this.m_ItemInfo == null) { return; } // If we are showing the tooltip if (show) { UIItemSlot.PrepareTooltip(this.m_ItemInfo); UITooltip.AnchorToRect(this.transform as RectTransform); UITooltip.Show(); } else { UITooltip.Hide(); } } }
/// <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 slot by the passed source slot. /// </summary> /// <param name="source">Source.</param> public override bool Assign(Object source) { if (source is UIItemSlot) { UIItemSlot sourceSlot = source as UIItemSlot; if (sourceSlot != null) { return(this.Assign(sourceSlot.GetItemInfo())); } } else if (source is UIEquipSlot) { UIEquipSlot sourceSlot = source as UIEquipSlot; if (sourceSlot != null) { return(this.Assign(sourceSlot.GetItemInfo())); } } // Default 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 * Retrieve and use item from inventary slot. * Parameter: item - RaycastResult variable referencing mouse postion and action */ public void UseItem(RaycastResult item) // right click. Use this! { if (this is UIEquipSlot && (int)(this as UIEquipSlot).equipType != 9) { return; } UIItemSlot inventorySlot = item.gameObject.GetComponent <UIItemSlot>(); UIEquipSlot equipSlot = item.gameObject.GetComponent <UIEquipSlot>(); Test_UIItemSlot_Assign tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); Test_UIEquipSlot_Assign equipItem = item.gameObject.GetComponent <Test_UIEquipSlot_Assign>(); if (equipItem != null) { if (equipItem.assignItem == 0) { return; } } UIItemInfo inven; Item consumable; if (inventorySlot == null) { //equipSlot = item.gameObject.GetComponent<UIEquipSlot>(); //equipItem = item.gameObject.GetComponent<Test_UIEquipSlot_Assign>(); if (equipItem == null) { return; } consumable = backupitemDataBase.GetItem(equipItem.assignItem); inven = equipSlot.GetItemInfo(); } else //consumable { if (inventorySlot.isVendor) { return; } tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); inven = inventorySlot.GetItemInfo(); consumable = backupitemDataBase.GetItem(tmpItem.assignItem); } if (consumable.isconsumable) { playSFX(onConsumeSFX); consumable.Use(); if (inventorySlot == null) { equipSlot.Assign(itemdatabase.GetByID(0)); fillinPotionslot(equipSlot, equipItem.assignItem, equipItem); return; } inventorySlot.Assign(itemdatabase.GetByID(0)); tmpItem.assignItem = 0; } else //equip { int i = (int)(itemdatabase.GetByID(tmpItem.assignItem).EquipType); if (i > 6 || i < 1) { //Debug.Log("find gem"); return; } //this.InternalHideTooltip(); UIEquipSlot EquipedSlot = EquipmentManager.instance.equipmentSlot[i].GetComponent <UIEquipSlot>(); //Debug.Log(EquipedSlot); UIItemInfo currentEquiped = EquipedSlot.GetItemInfo(); if (currentEquiped.EquipType == 0) { //tmpItem.assignItem = 10; playSFX(onEquipSFX); inventorySlot.Assign(EquipedSlot); if ((int)EquipedSlot.equipType == 1) { Player.instance.playerController.WeaponState = 1; } } else { playSFX(onEquipSFX); inventorySlot.Assign(currentEquiped); } int tmpID = currentEquiped.ID; Test_UIEquipSlot_Assign equipedItem = EquipmentManager.instance.equipmentSlot[i].GetComponent <Test_UIEquipSlot_Assign>(); equipedItem.assignItem = tmpItem.assignItem; equipedItem.itemDatabase = itemdatabase; //equipedItem.slot = EquipedSlot; EquipedSlot.Assign(inven); //equipedItem.slot.Assign(inven); //EquipedSlot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); //equipedItem.slot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); tmpItem.assignItem = tmpID; Test_UIItemSlot_Assign inventoryitem = inventorySlot.GetComponent <Test_UIItemSlot_Assign>(); inventoryitem.assignItem = tmpID; //Inventory.instance.UpdateInventory(); for (int k = 4; k < 8; k++) { EquipmentManager.instance.EquipmentUpdate(k); } } }