public void AddToSlot(BagSlot s) { MySlot = s; if (MySlot.Backpack == null) { // This is an inventory slot -- check for type match? // Was already done in an earlier step MySlot.MyLoot = this; if (lootStats.itemType == ItemTypes.Potion) { SoundsManager.PlayRandomClip(PotionDrinkSounds); } // We need to apply the item stats to our character this.GetComponent <LootStats>().ApplyStats(); return; } // Add to all slots BagSlot[] slots = MySlot.Backpack.GetSlotsAt(MySlot.PosX, MySlot.PosY, GridWidth, GridHeight); foreach (BagSlot bs in slots) { bs.MyLoot = this; } }
public void StartDrag(bool isSwap = false) { //Debug.Log("OnBeginDrag: " + gameObject.name); if (CombatPlayer.isDead) { return; } DraggedLoot = this; if (MySlot != null) { RemoveFromSlot(); } if (isSwap == false) { SoundsManager.PlayRandomClip(PickupSounds); } //GetComponent<CanvasGroup>().interactable = false; //GetComponent<CanvasGroup>().blocksRaycasts = false; this.transform.SetParent(GetComponentInParent <Canvas>().transform); this.transform.SetAsLastSibling(); }
void StopDrag() { if (DraggedLoot != this) { return; } //Debug.Log("StopDrag " + gameObject.name); DraggedLoot = null; SoundsManager.PlayRandomClip(DropSounds); //GetComponent<CanvasGroup>().interactable = true; //GetComponent<CanvasGroup>().blocksRaycasts = true; // Do a raycast to see what's under the mouse and find stuff that // implements OnDrop PointerEventData pointerData = new PointerEventData(EventSystem.current) { pointerId = -1, }; pointerData.position = Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); foreach (RaycastResult rr in results) { BagSlot bs = rr.gameObject.GetComponent <BagSlot>(); if (bs != null) { bs = bs.CanDropHere(this); // bs might be changed or could be null now if (bs != null) { bs.DroppedLoot(this); } else { ResetToLootArea(); } return; } } // If we get here, we didn't hit a slot ResetToLootArea(); }
public void Die() { // TODO: Death animation LootArea lootArea = GameObject.FindObjectOfType <LootArea>(); lootArea.SpawnLoot(this.transform.position, Level + (Bossiness * 2) - 1, 100 * (Bossiness * 2 - 1)); this.transform.SetParent(GetComponentInParent <Canvas>().transform); //Destroy(gameObject); SoundsManager.PlayRandomClip(DeathSounds); }