public void SpawnEnemy(Vector2 firstDestination) { // List<Vector2> enemyRoute = GenerateRoute(); List <Vector2> enemyRoute = new List <Vector2>(); //enemyRoute.Add(GetSpawnPoint()); enemyRoute.Add(firstDestination); enemyRoute.Add(ClosestPoint(firstDestination)); GameObject newEnemy = Instantiate(Globals.ENEMY, GetSpawnPoint(), Quaternion.identity); newEnemy.transform.SetParent(ObjectContainer.instance.enemies.transform); AutoMover autoMover = newEnemy.GetComponent <AutoMover>(); Inventory inventory = newEnemy.GetComponent <Inventory>(); autoMover.route = enemyRoute; autoMover.randomPatrol = true; autoMover.pointMemory = PRNG.Range(0, 3); Inventory.ItemType[] types = (Inventory.ItemType[])System.Enum.GetValues(typeof(Inventory.ItemType)); Inventory.ItemType dropType = types[PRNG.Range(0, types.Length)]; Inventory.InventoryEntry item = new Inventory.InventoryEntry(dropType, 1); inventory.Add(item); StartCoroutine(DelayedCall(autoMover, firstDestination)); //autoMover.SoundToPosition(firstDestination, true, Noise.Source.Gun, Vector2.zero); }
private void SpawnEnemy(Vector2 cell) { List <Vector2> enemyRoute = new List <Vector2>(); enemyRoute.Add(RandomTileFromCell(cell)); foreach (Vector2 neighbor in neighborList[cell]) { enemyRoute.Add(RandomTileFromCell(neighbor)); } GameObject newEnemy = Instantiate(Globals.ENEMY, enemyRoute[0], Quaternion.identity); // newEnemy.name = newEnemy.name + i; newEnemy.transform.SetParent(ObjectContainer.instance.enemies.transform); AutoMover autoMover = newEnemy.GetComponent <AutoMover>(); Inventory inventory = newEnemy.GetComponent <Inventory>(); autoMover.spawnsWounded = true; autoMover.route = enemyRoute; autoMover.randomPatrol = PRNG.Range(0, 2) == 0; autoMover.pointMemory = PRNG.Range(0, 3); Inventory.ItemType[] types = (Inventory.ItemType[])System.Enum.GetValues(typeof(Inventory.ItemType)); Inventory.ItemType dropType = types[PRNG.Range(0, types.Length)]; Inventory.InventoryEntry item = new Inventory.InventoryEntry(dropType, 1); inventory.Add(item); // Position, route, weaponequipped, leashlength, randompatrol, pointmemory, inventory }
public void SwapItemByUI(Inventory.ItemType itemType, int itemindex, Inventory.ItemType toitemType, int toitemindex) { GameObject from = null, to = null; inventory.FindItemByTypeAndIndex(itemType, itemindex, ref from); inventory.FindItemByTypeAndIndex(toitemType, toitemindex, ref to); if (to != null) { if (IsSameType(from, to) || (itemType == Inventory.ItemType.Backpack && toitemType == Inventory.ItemType.Backpack)) { inventory.SwapItem(itemType, itemindex, toitemType, toitemindex); } } else { if (toitemType == Inventory.ItemType.Backpack) { inventory.AddToInventory(from); } else { inventory.EquipeItem(toitemType, toitemindex, from); } } }
public void DropItem(Inventory.ItemType it, int index) { if (photonView.isMine) { photonView.RPC("DropItemByUI", PhotonTargets.All, it, index); } }
public void SwapItem(Inventory.ItemType itemType, int itemindex, Inventory.ItemType toitemType, int toitemindex) { if (photonView.isMine) { photonView.RPC("SwapItemByUI", PhotonTargets.All, itemType, itemindex, toitemType, toitemindex); } }
public void FindItemByTypeAndIndex(Inventory.ItemType type, int index, ref GameObject obj) { switch (type) { case ItemType.Equiped: { switch (index) { case 0: case 1: { obj = Weapon[index]; break; } case 2: { obj = Missile[index - 2]; break; } case 3: case 4: { obj = Remedy[index - 3]; break; } default: { break; } } break; } case ItemType.Skill: { obj = Skills[index]; break; } case ItemType.Backpack: { if (index < ItemList.Count) { obj = ItemList[index]; break; } else { obj = null; break; } } default: { break; } } }
public void DropItemByUI(Inventory.ItemType it, int index) { switch (it) { case Inventory.ItemType.Backpack: { DropItem(inventory.ItemList[index]); inventory.ItemList.RemoveAt(index); break; } case Inventory.ItemType.Equiped: { switch (index) { case 0: case 1: { DropItem(inventory.Weapon[index]); playerManager.GetComponent <Inventory>().RemoveReference(inventory.Weapon[index]); break; } case 2: { DropItem(inventory.Missile[index - 2]); playerManager.GetComponent <Inventory>().RemoveReference(inventory.Missile[index - 2]); break; } case 3: case 4: { DropItem(inventory.Remedy[index - 3]); playerManager.GetComponent <Inventory>().RemoveReference(inventory.Remedy[index - 3]); break; } default: { break; } } break; } case Inventory.ItemType.Skill: { DropItem(inventory.Skills[index]); playerManager.GetComponent <Inventory>().RemoveReference(inventory.Skills[index]); break; } default: break; } }
public void GetItemInfo(Inventory.ItemType itemType, int itemindex, ref GameObject[] a, ref int aIndex) { switch (itemType) { case ItemType.Equiped: { switch (itemindex) { case 0: case 1: { a = Weapon; aIndex = itemindex; break; } case 2: { a = Missile; aIndex = itemindex - 2; break; } case 3: case 4: { a = Remedy; aIndex = itemindex - 3; break; } default: { break; } } break; } case ItemType.Skill: { a = Skills; aIndex = itemindex; break; } case ItemType.Backpack: { a = null; aIndex = itemindex; break; } } }
private void SpawnPlayer() { PlayerMover.instance.transform.position = RandomTileFromCell(new Vector2(2, 2)); Inventory inventory = PlayerMover.instance.GetComponent <Inventory>(); Inventory.ItemType[] types = (Inventory.ItemType[])System.Enum.GetValues(typeof(Inventory.ItemType)); int startingItems = PRNG.Range(0, 5); for (int i = 0; i < startingItems; ++i) { Inventory.ItemType dropType = types[PRNG.Range(0, types.Length)]; Inventory.InventoryEntry item = new Inventory.InventoryEntry(dropType, 1); inventory.Add(item); } }
//ITEMS private void getItemList(Inventory.ItemType itemType) { foreach (ItemData items in inventory.GetItems(itemType)) { itemList = Instantiate(itemBar, equipmentWindow.transform); Image image = itemList.GetComponent <RectTransform>().Find("itemIcon").GetComponent <Image>(); TextMeshProUGUI itemNametext = itemList.GetComponent <RectTransform>().Find("itemName").GetComponent <TextMeshProUGUI>(); Image rarityImage = itemList.GetComponent <RectTransform>().Find("rarity").GetComponent <Image>(); image.sprite = items.GetSprite(); rarityImage.sprite = items.getRaritySprite(); itemNametext.text = items.data.itemName; equipmentSlot = itemList.GetComponent <UI_CharacterEquipmentSlot>(); //PASSING OF VALUE IN UI_EQUIPMENTCHARACTERSLOT SCRIP equipmentSlot.Item = items; } }
public void SwapItem(Inventory.ItemType itemType, int itemindex, Inventory.ItemType toitemType, int toitemindex) { GameObject[] a = null; int aIndex = -1; GameObject[] b = null; int bIndex = -1; GetItemInfo(itemType, itemindex, ref a, ref aIndex); GetItemInfo(toitemType, toitemindex, ref b, ref bIndex); GameObject temp; if (a != null && b != null) { temp = a[aIndex]; a[aIndex] = b[bIndex]; b[bIndex] = temp; } else if (a == null && b != null) { temp = ItemList[aIndex]; ItemList[aIndex] = b[bIndex]; b[bIndex] = temp; } else if (a != null && b == null) { temp = a[aIndex]; a[aIndex] = ItemList[bIndex]; ItemList[bIndex] = temp; } else { temp = ItemList[aIndex]; ItemList[aIndex] = ItemList[bIndex]; ItemList[bIndex] = temp; } }
private void RefreshActionButton(Inventory inv, Inventory.ItemType itemType, Button button) { button.GetComponentInChildren <Text>().text = inv.GetQuantity(itemType).ToString(); button.interactable = inv.GetQuantity(itemType) > 0; }
//结束拖动时 public void OnEndDrag(PointerEventData eventData) { if (transform.GetComponent <Image>().sprite == null && transform.tag == "UIDropable") { return; } GameObject dropObj = eventData.pointerEnter; Debug.Log(this.name); string[] itemtypeindex = this.name.Split('('); string itemtype = itemtypeindex[0]; int itemindex = int.Parse(itemtypeindex[1].Split(')')[0]); Debug.Log(itemtype + " " + itemindex); Inventory.ItemType itemType = StringToItemtype(itemtype); if (dropObj == null) { Debug.Log(itemType + " " + itemindex); rpcManager.DropItem(itemType, itemindex); DestroyItem(eventData); } else { if (dropObj.tag == "UIDropable") { string[] toitemtypeindex = dropObj.name.Split('('); string toitemtype = toitemtypeindex[0]; int toitemindex = int.Parse(toitemtypeindex[1].Split(')')[0]); Inventory.ItemType toitemType = StringToItemtype(toitemtype); rpcManager.SwapItem(itemType, itemindex, toitemType, toitemindex); } GetComponent <Image>().sprite = m_DraggingIcons[eventData.pointerId].GetComponent <Image>().sprite; DestroyItem(eventData); } transform.tag = "UIDropable"; //Sprite dropSprite = dropObj.GetComponent<Image>().sprite; //if (dropSprite != null) //{ // GetComponent<Image>().sprite = dropSprite; //} //dropObj.transform.parent.GetComponent<Image>().color = normalColor; //dropObj.GetComponent<Image>().sprite = m_DraggingIcons[eventData.pointerId].GetComponent<Image>().sprite; //if (dropObj.GetComponent<Image>().sprite != nullItem) //{ // dropObj.GetComponent<DragItem>().enabled = true; //} //DestroyItem(eventData); //if (image.sprite == nullItem) //{ // GetComponent<DragItem>().enabled = false; //} }
private void SwapItemByUI(Inventory.ItemType itemType, int itemindex, Inventory.ItemType toitemType, int toitemindex) { pickupManager.SwapItemByUI(itemType, itemindex, toitemType, toitemindex); }
private void DropItemByUI(Inventory.ItemType it, int index) { pickupManager.DropItemByUI(it, index); }