private void CreateItem(string id, GameObject Slot) { iss = Slot.GetComponent <ItemSlotScript>(); switch (id[0]) { case 'h': //Healingitem foreach (HealingItemObject healing in Assets.assets.healingTemp) { if (healing.name == id) { ItemO = Instantiate(Item); ItemO.transform.SetParent(Slot.transform, false); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(healing.icon, healing.itemName, healing.description, healing.name, healing.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(healing.itemName, healing.description, DescParent); break; } } break; case 'c': foreach (CombatItemObject combat in Assets.assets.combatTemp) { if (combat.name == id) { ItemO = Instantiate(Item); ItemO.transform.SetParent(Slot.transform, false); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(combat.icon, combat.itemName, combat.description, combat.name, combat.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(combat.itemName, combat.description, DescParent); break; } } break; case 'w': foreach (WeaponObject weapon in Assets.assets.weaponTemp) { if (weapon.name == id) { ItemO = Instantiate(Item); ItemO.transform.SetParent(Slot.transform, false); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(weapon.icon, weapon.weaponName, weapon.description, weapon.name, weapon.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(weapon.weaponName, weapon.description, DescParent); break; } } break; } }
void Awake() { // Grab the weapon once when the enemy spawns mainhand = GetComponentInChildren<ItemSlotScript>(); abilitySlots = GetComponentsInChildren<AbilitySlotScript>(); // Tell each abilityslot which # it is for UI formatting for(int i = 0; i < abilitySlots.Length; i++) { AbilityUIScript uiScript = abilitySlots[i].GetComponent<AbilityUIScript>(); uiScript.abilityIndex = i; } if(mainhand != null) { // If character has a slot for weapons) weapons = mainhand.GetComponentsInChildren<WeaponScript>(); } }
// ending the drag and checking for item swap void OnMouseUp() { HeroBase currentlySelectedHero = (HeroBase)heroMenu.currentlySlecetedShadow().GetComponent <ShadowScript>().shadowedScript; RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100, ignoreHeroLayer)) { this.gameObject.layer = 0; if (hit.collider.tag == "ItemSlot") { ItemSlotScript otherSlot = hit.collider.GetComponent <ItemSlotScript>(); if (this.isSlotEmpty()) { } else if (otherSlot.isSlotEmpty() && (itemInTheSlot.GetComponent <ItemBase>().currentItemType == otherSlot.currentItemType || otherSlot.currentItemType == itemType.Any)) { if (otherSlot.currentItemType == itemType.Any) { otherSlot.receiveItem(itemInTheSlot); clearItemSlot(); } else if (otherSlot.currentItemType != itemType.Any && compareItemToHeroClass(currentlySelectedHero, itemInTheSlot)) { otherSlot.receiveItem(itemInTheSlot); clearItemSlot(); } } else if (!otherSlot.isSlotEmpty() && (itemInTheSlot.GetComponent <ItemBase>().currentItemType == otherSlot.currentItemType || otherSlot.currentItemType == itemType.Any) && (currentItemType == otherSlot.itemInTheSlot.GetComponent <ItemBase>().currentItemType || currentItemType == itemType.Any)) { print(heroMenu.currentlySlecetedShadow().GetComponent <ShadowScript>().shadowedScript.myClass); if (otherSlot.currentItemType == itemType.Any && otherSlot.itemInTheSlot.GetComponent <ItemBase>().primaryItemClass == heroMenu.currentlySlecetedShadow().GetComponent <ShadowScript>().shadowedScript.myClass) { GameObject otherSlotItem; otherSlotItem = otherSlot.itemInTheSlot; otherSlot.receiveItem(itemInTheSlot); this.receiveItem(otherSlotItem); } else if (otherSlot.currentItemType != itemType.Any && compareItemToHeroClass(currentlySelectedHero, itemInTheSlot)) { GameObject otherSlotItem; otherSlotItem = otherSlot.itemInTheSlot; otherSlot.receiveItem(itemInTheSlot); this.receiveItem(otherSlotItem); } } if (saveCurrentEquip != null) { // save the current hero equipment saveCurrentEquip(); } } } dragging = false; transform.SetParent(myParent.transform); transform.position = originalPosition; }
public void FillSlots(string[] inventory, GameObject[] itemSlots, GameObject DescParent) { for (int i = 0; i < inventory.Length; i++) { iss = itemSlots[i].GetComponent <ItemSlotScript>(); if (!(inventory[i] == "")) { switch (inventory[i][0]) { case 'h': //Healingitem foreach (HealingItemObject healing in Assets.assets.healingTemp) { if (healing.name == inventory[i]) { ItemO = Instantiate(Item); ItemO.transform.SetParent(itemSlots[i].transform, false); ItemO.transform.localScale = new Vector3(50, 50, 1); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(healing.icon, healing.itemName, healing.description, healing.name, healing.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(healing.itemName, healing.description, DescParent); break; } } break; case 'c': bool isCombat = false; foreach (CombatItemObject combat in Assets.assets.combatTemp) { if (combat.name == inventory[i]) { ItemO = Instantiate(Item); ItemO.transform.SetParent(itemSlots[i].transform, false); ItemO.transform.localScale = new Vector3(50, 50, 1); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(combat.icon, combat.itemName, combat.description, combat.name, combat.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(combat.itemName, combat.description, DescParent); isCombat = true; break; } } if (!isCombat) { foreach (ClothItemObject cloth in Assets.assets.clothTemp) { if (cloth.name == inventory[i]) { ItemO = Instantiate(Item); ItemO.transform.SetParent(itemSlots[i].transform, false); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(cloth.icon, cloth.itemName, cloth.description, cloth.name, cloth.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(cloth.itemName, cloth.description, DescParent); break; } } } break; case 'w': foreach (WeaponObject weapon in Assets.assets.weaponTemp) { if (weapon.name == inventory[i]) { ItemO = Instantiate(Item); ItemO.transform.SetParent(itemSlots[i].transform, false); itemInfo = ItemO.GetComponent <ItemInfo>(); itemInfo.GetData(weapon.icon, weapon.weaponName, weapon.description, weapon.name, weapon.cost, txtDescName, txtDescDesc); iss.GetComponent <ItemSlotScript>().GetItem(weapon.weaponName, weapon.description, DescParent); break; } } break; default: Debug.Log("Can't find Item! inventory[" + i + "]: " + inventory[i]); break; } } } }
// Use this for initialization void Start() { mainHandSlot = transform.parent.GetComponent<ItemSlotScript>(); // Grab the parent mainhand to get any slot-related info }