Example #1
0
 public void DropAt(Dropzone dropzone)
 {
     if (_currentItem != null)
     {
         _currentItem.OnDrop();
         dropzone.DropItem(_currentItem);
         RaiseEvent(new CarryableItemDroppedEvent(_currentItem));
         _currentItem = null;
     }
 }
Example #2
0
 public void Pickup(CarryableItem carryableItem)
 {
     if (_currentItem == null && carryableItem.CanBePickedUp)
     {
         RaiseEvent(new CarryableItemPickedUpEvent(carryableItem));
         carryableItem.transform.SetParent(transform);
         carryableItem.transform.localPosition = Vector3.zero;
         _currentItem = carryableItem;
         _currentItem.OnPickup();
     }
 }
Example #3
0
    public bool CarryItem(CarryableItem item)
    {
        //Disable item physics
        if (item.collider != null)
        {
            item.collider.enabled = false;
        }

        if (item.rigidbody != null)
        {
            item.rigidbody.isKinematic = true;
        }

        //Add item to inventory
        _inventory.Add(item);
        var index = _inventory.Count;

        Debug.Log("Carried " + item.name);

        //Set item parent to be the inventory screen
        item.transform.parent = InventoryScreen.transform;

        //Move item to inventory screen layer
        ConvertToLayer(item.gameObject, InventoryScreen.layer);

        //Set position, rotation, scale of newly-added item in the inventory screen
        var uiScale = 130;
        var x       = ((index % 6) - 3) * uiScale;
        var y       = (1 - (index / 6)) * uiScale;

        item.transform.localScale    = Vector3.one * 50;
        item.transform.localRotation = Quaternion.identity;
        item.InventoryPosition       = new Vector2(x, y);

        return(true);
    }
Example #4
0
 public CarryableItemSpawnedEvent(CarryableItem item)
 {
     Item = item;
 }
 public CarryableItemPickedUpEvent(CarryableItem item)
 {
     Item = item;
 }
Example #6
0
 public void DropItem(CarryableItem item)
 {
     item.transform.SetParent(transform);
     item.transform.localPosition = _spawnOffset;
     item.GetComponent <Rigidbody2D>().AddForce(Vector2.up * _force);
 }
Example #7
0
 public CarryableItemDroppedEvent(CarryableItem item)
 {
     Item = item;
 }